Skip to content

Commit

Permalink
refactor: rewire() now does 10 times the number of edges trials by de…
Browse files Browse the repository at this point in the history
…fault
  • Loading branch information
szhorvat committed Jul 3, 2024
1 parent 9be1c22 commit 67b44e4
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/_igraph/graphobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6432,14 +6432,19 @@ PyObject *igraphmodule_Graph_rewire(igraphmodule_GraphObject * self,
PyObject * args, PyObject * kwds)
{
static char *kwlist[] = { "n", "mode", NULL };
Py_ssize_t n = 1000;
PyObject *mode_o = Py_None;
PyObject *n_o = Py_None, *mode_o = Py_None;
igraph_integer_t n = 10 * igraph_ecount(&self->g); /* TODO overflow check */
igraph_rewiring_t mode = IGRAPH_REWIRING_SIMPLE;

if (!PyArg_ParseTupleAndKeywords(args, kwds, "|nO", kwlist, &n, &mode_o))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &n_o, &mode_o)) {
return NULL;
}

CHECK_SSIZE_T_RANGE(n, "number of rewiring attempts");
if (n_o != Py_None) {
if (igraphmodule_PyObject_to_integer_t(n_o, &n)) {
return NULL;
}
}

if (igraphmodule_PyObject_to_rewiring_t(mode_o, &mode)) {
return NULL;
Expand Down Expand Up @@ -15810,12 +15815,13 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
/* interface to igraph_rewire */
{"rewire", (PyCFunction) igraphmodule_Graph_rewire,
METH_VARARGS | METH_KEYWORDS,
"rewire(n=1000, mode=\"simple\")\n--\n\n"
"rewire(n=None, mode=\"simple\")\n--\n\n"
"Randomly rewires the graph while preserving the degree distribution.\n\n"
"Please note that the rewiring is done \"in-place\", so the original\n"
"graph will be modified. If you want to preserve the original graph,\n"
"use the L{copy} method before.\n\n"
"@param n: the number of rewiring trials.\n"
"The rewiring is done \"in-place\", so the original graph will be modified.\n"
"If you want to preserve the original graph, use the L{copy} method before\n"
"rewiring.\n\n"
"@param n: the number of rewiring trials. The default is 10 times the number\n"
" of edges.\n"
"@param mode: the rewiring algorithm to use. It can either be C{\"simple\"} or\n"
" C{\"loops\"}; the former does not create or destroy loop edges while the\n"
" latter does.\n"},
Expand Down

0 comments on commit 67b44e4

Please sign in to comment.