@@ -13611,11 +13611,12 @@ PyObject *igraphmodule_Graph_community_walktrap(igraphmodule_GraphObject * self,
1361113611PyObject *igraphmodule_Graph_community_leiden(igraphmodule_GraphObject *self,
1361213612 PyObject *args, PyObject *kwds) {
1361313613
13614- static char *kwlist[] = {"edge_weights", "node_weights", "resolution",
13614+ static char *kwlist[] = {"edge_weights", "node_weights", "node_in_weights", " resolution",
1361513615 "normalize_resolution", "beta", "initial_membership", "n_iterations", NULL};
1361613616
1361713617 PyObject *edge_weights_o = Py_None;
1361813618 PyObject *node_weights_o = Py_None;
13619+ PyObject *node_in_weights_o = Py_None;
1361913620 PyObject *initial_membership_o = Py_None;
1362013621 PyObject *normalize_resolution = Py_False;
1362113622 PyObject *res = Py_None;
@@ -13624,14 +13625,14 @@ PyObject *igraphmodule_Graph_community_leiden(igraphmodule_GraphObject *self,
1362413625 Py_ssize_t n_iterations = 2;
1362513626 double resolution = 1.0;
1362613627 double beta = 0.01;
13627- igraph_vector_t *edge_weights = NULL, *node_weights = NULL;
13628+ igraph_vector_t *edge_weights = NULL, *node_weights = NULL, *node_in_weights = NULL ;
1362813629 igraph_vector_int_t *membership = NULL;
1362913630 igraph_bool_t start = true;
1363013631 igraph_integer_t nb_clusters = 0;
1363113632 igraph_real_t quality = 0.0;
1363213633
13633- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOdOdOn ", kwlist,
13634- &edge_weights_o, &node_weights_o, &resolution, &normalize_resolution, &beta, &initial_membership_o, &n_iterations))
13634+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOdOdOn ", kwlist,
13635+ &edge_weights_o, &node_weights_o, &node_in_weights_o, & resolution, &normalize_resolution, &beta, &initial_membership_o, &n_iterations))
1363513636 return NULL;
1363613637
1363713638 if (n_iterations >= 0) {
@@ -13654,6 +13655,13 @@ PyObject *igraphmodule_Graph_community_leiden(igraphmodule_GraphObject *self,
1365413655 error = -1;
1365513656 }
1365613657
13658+ /* Get node in-weights (directed case) */
13659+ if (!error && igraphmodule_attrib_to_vector_t(node_in_weights_o, self, &node_in_weights,
13660+ ATTRIBUTE_TYPE_VERTEX)) {
13661+ igraphmodule_handle_igraph_error();
13662+ error = -1;
13663+ }
13664+
1365713665 /* Get initial membership */
1365813666 if (!error && igraphmodule_attrib_to_vector_int_t(initial_membership_o, self, &membership,
1365913667 ATTRIBUTE_TYPE_VERTEX)) {
@@ -13696,7 +13704,7 @@ PyObject *igraphmodule_Graph_community_leiden(igraphmodule_GraphObject *self,
1369613704 /* Run actual Leiden algorithm for several iterations. */
1369713705 if (!error) {
1369813706 error = igraph_community_leiden(&self->g,
13699- edge_weights, node_weights,
13707+ edge_weights, node_weights, node_in_weights,
1370013708 resolution, beta,
1370113709 start, n_iterations, membership,
1370213710 &nb_clusters, &quality);
@@ -13710,6 +13718,10 @@ PyObject *igraphmodule_Graph_community_leiden(igraphmodule_GraphObject *self,
1371013718 igraph_vector_destroy(node_weights);
1371113719 free(node_weights);
1371213720 }
13721+ if (node_in_weights != 0) {
13722+ igraph_vector_destroy(node_in_weights);
13723+ free(node_in_weights);
13724+ }
1371313725
1371413726 if (!error && membership != 0) {
1371513727 res = igraphmodule_vector_int_t_to_PyList(membership);
0 commit comments