Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rewire() now does 10 times the number of edges trials by default #787

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading