Skip to content

Commit 47c2213

Browse files
committed
refactor!: adapt Graph.SBM() interface to changes in C core
1 parent 0fce500 commit 47c2213

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/_igraph/graphobject.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,24 +3563,22 @@ PyObject *igraphmodule_Graph_SBM(PyTypeObject * type,
35633563
{
35643564
igraphmodule_GraphObject *self;
35653565
igraph_t g;
3566-
Py_ssize_t n;
35673566
PyObject *block_sizes_o, *pref_matrix_o;
35683567
PyObject *directed_o = Py_False;
35693568
PyObject *loops_o = Py_False;
3569+
PyObject *multiple_o = Py_False;
35703570
igraph_matrix_t pref_matrix;
35713571
igraph_vector_int_t block_sizes;
35723572

3573-
static char *kwlist[] = { "n", "pref_matrix", "block_sizes", "directed",
3574-
"loops", NULL };
3573+
static char *kwlist[] = { "pref_matrix", "block_sizes", "directed",
3574+
"loops", "multiple", NULL };
35753575

3576-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "nOO|OO", kwlist,
3577-
&n, &pref_matrix_o,
3576+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOO", kwlist,
3577+
&pref_matrix_o,
35783578
&block_sizes_o,
3579-
&directed_o, &loops_o))
3579+
&directed_o, &loops_o, &multiple_o))
35803580
return NULL;
35813581

3582-
CHECK_SSIZE_T_RANGE(n, "vertex count");
3583-
35843582
if (igraphmodule_PyObject_to_matrix_t(pref_matrix_o, &pref_matrix, "pref_matrix")) {
35853583
return NULL;
35863584
}
@@ -3590,7 +3588,7 @@ PyObject *igraphmodule_Graph_SBM(PyTypeObject * type,
35903588
return NULL;
35913589
}
35923590

3593-
if (igraph_sbm_game(&g, n, &pref_matrix, &block_sizes, PyObject_IsTrue(directed_o), PyObject_IsTrue(loops_o))) {
3591+
if (igraph_sbm_game(&g, &pref_matrix, &block_sizes, PyObject_IsTrue(directed_o), PyObject_IsTrue(loops_o), PyObject_IsTrue(multiple_o))) {
35943592
igraphmodule_handle_igraph_error();
35953593
igraph_matrix_destroy(&pref_matrix);
35963594
igraph_vector_int_destroy(&block_sizes);
@@ -14754,19 +14752,19 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
1475414752
METH_VARARGS | METH_CLASS | METH_KEYWORDS,
1475514753
"SBM(n, pref_matrix, block_sizes, directed=False, loops=False)\n--\n\n"
1475614754
"Generates a graph based on a stochastic block model.\n\n"
14757-
"A given number of vertices are generated. Every vertex is assigned to a\n"
14758-
"vertex type according to the given block sizes. Vertices of the same\n"
14755+
"Every vertex is assigned to a vertex type according to the given block\n"
14756+
"sizes, which also determine the total vertex count. Vertices of the same\n"
1475914757
"type will be assigned consecutive vertex IDs. Finally, every\n"
1476014758
"vertex pair is evaluated and an edge is created between them with a\n"
1476114759
"probability depending on the types of the vertices involved. The\n"
1476214760
"probabilities are taken from the preference matrix.\n\n"
14763-
"@param n: the number of vertices in the graph\n"
14764-
"@param pref_matrix: matrix giving the connection probabilities for\n"
14765-
" different vertex types.\n"
14761+
"@param pref_matrix: matrix giving the connection probabilities (or expected\n"
14762+
" edge multiplicities for multigraphs) between different vertex types.\n"
1476614763
"@param block_sizes: list giving the number of vertices in each block; must\n"
1476714764
" sum up to I{n}.\n"
1476814765
"@param directed: whether to generate a directed graph.\n"
14769-
"@param loops: whether loop edges are allowed.\n"},
14766+
"@param loops: whether loop edges are allowed.\n"
14767+
"@param multiple: whether multi-edges are allowed.\n"},
1477014768

1477114769
// interface to igraph_star
1477214770
{"Star", (PyCFunction) igraphmodule_Graph_Star,

0 commit comments

Comments
 (0)