Skip to content

Commit c185ea6

Browse files
committed
fix: update rewire() for C API changes
1 parent 2788bbb commit c185ea6

File tree

6 files changed

+10
-29
lines changed

6 files changed

+10
-29
lines changed

src/_igraph/convert.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -766,19 +766,6 @@ int igraphmodule_PyObject_to_reciprocity_t(PyObject *o, igraph_reciprocity_t *re
766766
TRANSLATE_ENUM_WITH(reciprocity_tt);
767767
}
768768

769-
/**
770-
* \brief Converts a Python object to an igraph \c igraph_rewiring_t
771-
*/
772-
int igraphmodule_PyObject_to_rewiring_t(PyObject *o, igraph_rewiring_t *result) {
773-
static igraphmodule_enum_translation_table_entry_t rewiring_tt[] = {
774-
{"simple", IGRAPH_REWIRING_SIMPLE},
775-
{"simple_loops", IGRAPH_REWIRING_SIMPLE_LOOPS},
776-
{"loops", IGRAPH_REWIRING_SIMPLE_LOOPS},
777-
{0,0}
778-
};
779-
TRANSLATE_ENUM_WITH(rewiring_tt);
780-
}
781-
782769
/**
783770
* \brief Converts a Python object to an igraph \c igraphmodule_shortest_path_algorithm_t
784771
*/

src/_igraph/convert.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ int igraphmodule_PyObject_to_realize_degseq_t(PyObject *o, igraph_realize_degseq
8686
int igraphmodule_PyObject_to_random_tree_t(PyObject *o, igraph_random_tree_t *result);
8787
int igraphmodule_PyObject_to_random_walk_stuck_t(PyObject *o, igraph_random_walk_stuck_t *result);
8888
int igraphmodule_PyObject_to_reciprocity_t(PyObject *o, igraph_reciprocity_t *result);
89-
int igraphmodule_PyObject_to_rewiring_t(PyObject *o, igraph_rewiring_t *result);
9089
int igraphmodule_PyObject_to_shortest_path_algorithm_t(PyObject *o, igraphmodule_shortest_path_algorithm_t *result);
9190
int igraphmodule_PyObject_to_spinglass_implementation_t(PyObject *o, igraph_spinglass_implementation_t *result);
9291
int igraphmodule_PyObject_to_spincomm_update_t(PyObject *o, igraph_spincomm_update_t *result);

src/_igraph/graphobject.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6512,12 +6512,12 @@ PyObject *igraphmodule_Graph_permute_vertices(igraphmodule_GraphObject *self,
65126512
PyObject *igraphmodule_Graph_rewire(igraphmodule_GraphObject * self,
65136513
PyObject * args, PyObject * kwds)
65146514
{
6515-
static char *kwlist[] = { "n", "mode", NULL };
6516-
PyObject *n_o = Py_None, *mode_o = Py_None;
6515+
static char *kwlist[] = { "n", "allowed_edge_types", NULL };
6516+
PyObject *n_o = Py_None, *allowed_edge_types_o = Py_None;
65176517
igraph_integer_t n = 10 * igraph_ecount(&self->g); /* TODO overflow check */
6518-
igraph_rewiring_t mode = IGRAPH_REWIRING_SIMPLE;
6518+
igraph_edge_type_sw_t allowed_edge_types = IGRAPH_SIMPLE_SW;
65196519

6520-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &n_o, &mode_o)) {
6520+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &n_o, &allowed_edge_types_o)) {
65216521
return NULL;
65226522
}
65236523

@@ -6527,11 +6527,11 @@ PyObject *igraphmodule_Graph_rewire(igraphmodule_GraphObject * self,
65276527
}
65286528
}
65296529

6530-
if (igraphmodule_PyObject_to_rewiring_t(mode_o, &mode)) {
6530+
if (igraphmodule_PyObject_to_edge_type_sw_t(allowed_edge_types_o, &allowed_edge_types)) {
65316531
return NULL;
65326532
}
65336533

6534-
if (igraph_rewire(&self->g, n, mode)) {
6534+
if (igraph_rewire(&self->g, n, allowed_edge_types)) {
65356535
igraphmodule_handle_igraph_error();
65366536
return NULL;
65376537
}
@@ -16281,7 +16281,7 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
1628116281
/* interface to igraph_rewire */
1628216282
{"rewire", (PyCFunction) igraphmodule_Graph_rewire,
1628316283
METH_VARARGS | METH_KEYWORDS,
16284-
"rewire(n=None, mode=\"simple\")\n--\n\n"
16284+
"rewire(n=None, allowed_edge_types=\"simple\")\n--\n\n"
1628516285
"Randomly rewires the graph while preserving the degree distribution.\n\n"
1628616286
"The rewiring is done \"in-place\", so the original graph will be modified.\n"
1628716287
"If you want to preserve the original graph, use the L{copy} method before\n"

src/_igraph/igraphmodule.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,9 +1158,6 @@ PyObject* PyInit__igraph(void)
11581158
PyModule_AddIntConstant(m, "GET_ADJACENCY_LOWER", IGRAPH_GET_ADJACENCY_LOWER);
11591159
PyModule_AddIntConstant(m, "GET_ADJACENCY_BOTH", IGRAPH_GET_ADJACENCY_BOTH);
11601160

1161-
PyModule_AddIntConstant(m, "REWIRING_SIMPLE", IGRAPH_REWIRING_SIMPLE);
1162-
PyModule_AddIntConstant(m, "REWIRING_SIMPLE_LOOPS", IGRAPH_REWIRING_SIMPLE_LOOPS);
1163-
11641161
PyModule_AddIntConstant(m, "ADJ_DIRECTED", IGRAPH_ADJ_DIRECTED);
11651162
PyModule_AddIntConstant(m, "ADJ_UNDIRECTED", IGRAPH_ADJ_UNDIRECTED);
11661163
PyModule_AddIntConstant(m, "ADJ_MAX", IGRAPH_ADJ_MAX);

src/igraph/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
IN,
4848
InternalError,
4949
OUT,
50-
REWIRING_SIMPLE,
51-
REWIRING_SIMPLE_LOOPS,
5250
STAR_IN,
5351
STAR_MUTUAL,
5452
STAR_OUT,

tests/test_games.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ def testRewire(self):
163163
self.assertTrue(g.is_simple())
164164

165165
# Rewiring with loops (1)
166-
g.rewire(10000, mode="loops")
166+
g.rewire(10000, allowed_edge_types="loops")
167167
self.assertEqual(degrees, g.degree())
168168
self.assertFalse(any(g.is_multiple()))
169169

170170
# Rewiring with loops (2)
171171
g = Graph.Full(4)
172172
g[1, 3] = 0
173173
degrees = g.degree()
174-
g.rewire(100, mode="loops")
174+
g.rewire(100, allowed_edge_types="loops")
175175
self.assertEqual(degrees, g.degree())
176176
self.assertFalse(any(g.is_multiple()))
177177

@@ -185,7 +185,7 @@ def testRewire(self):
185185
self.assertTrue(g.is_simple())
186186

187187
# Directed graph with loops
188-
g.rewire(10000, mode="loops")
188+
g.rewire(10000, allowed_edge_types="loops")
189189
self.assertEqual(indeg, g.indegree())
190190
self.assertEqual(outdeg, g.outdegree())
191191
self.assertFalse(any(g.is_multiple()))

0 commit comments

Comments
 (0)