igraph / python-igraph

Python interface for igraph
GNU General Public License v2.0
1.31k stars 249 forks source link

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

Closed szhorvat closed 4 months ago

szhorvat commented 4 months ago

Closes #775

@ntamas, can you help with this? What should I specify as the default for n? I'm pretty sure that the way I wrote n=None is not correct.

ntamas commented 4 months ago

PyArg_ParseTupleAndKeywords(args, kwds, "|nO", kwlist, &n, &mode_o) -- this function parses n as a Python integer int and saves it in a Py_ssize_t, that's why you cannot simply pass None for n right now (see here for more details). If you wanted to support None, you would need to change the format string to |OO, parse n into a PyObject* first, check whether it's None (with == Py_None) and if not, try to cast it into a Py_ssize_t with PyNumber_AsSsize_t (see here ).

szhorvat commented 4 months ago

What I want is that the effective default be 1000*ecount. What is the best way to do this? Should the formal default be None, which is then interpreted this way? If yes, I now understand how to do that and can update this PR. Let me know.

ntamas commented 4 months ago

Yes, that's the way to go, that's how I would do it in pure Python as well.

szhorvat commented 4 months ago

@ntamas Have another look, I used igraphmodule_PyObject_to_integer_t() instead of PyNumber_AsSsize_t. Is this okay?