@@ -4784,7 +4784,7 @@ PyObject *igraphmodule_Graph_personalized_pagerank(igraphmodule_GraphObject *sel
47844784{
47854785 static char *kwlist[] =
47864786 { "vertices", "directed", "damping", "reset", "reset_vertices", "weights",
4787- "arpack_options", NULL };
4787+ "arpack_options", "implementation", "niter", "eps", NULL };
47884788 PyObject *directed = Py_True;
47894789 PyObject *vobj = Py_None, *wobj = Py_None, *robj = Py_None, *rvsobj = Py_None;
47904790 PyObject *list;
@@ -4796,12 +4796,21 @@ PyObject *igraphmodule_Graph_personalized_pagerank(igraphmodule_GraphObject *sel
47964796 igraph_vector_t weights;
47974797 igraph_bool_t return_single = 0;
47984798 igraph_vs_t vs, reset_vs;
4799+ igraph_pagerank_algo_t algo=IGRAPH_PAGERANK_ALGO_PRPACK;
4800+ PyObject *algo_o = Py_None;
4801+ long niter=1000;
4802+ float eps=0.001f;
4803+ igraph_pagerank_power_options_t popts;
4804+ void *opts;
47994805 int retval;
48004806
4801- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOdOOOO!", kwlist, &vobj,
4802- &directed, &damping, &robj, &rvsobj, &wobj,
4807+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOdOOOO!Oid", kwlist, &vobj,
4808+ &directed, &damping, &robj,
4809+ &rvsobj, &wobj,
48034810 &igraphmodule_ARPACKOptionsType,
4804- &arpack_options_o))
4811+ &arpack_options_o, &algo_o, &niter, &eps))
4812+
4813+
48054814 return NULL;
48064815
48074816 if (robj != Py_None && rvsobj != Py_None) {
@@ -4814,6 +4823,7 @@ PyObject *igraphmodule_Graph_personalized_pagerank(igraphmodule_GraphObject *sel
48144823 return NULL;
48154824 }
48164825
4826+ arpack_options = (igraphmodule_ARPACKOptionsObject*)arpack_options_o;
48174827 if (robj != Py_None) {
48184828 if (igraphmodule_attrib_to_vector_t(robj, self, &reset, ATTRIBUTE_TYPE_VERTEX)) {
48194829 igraph_vs_destroy(&vs);
@@ -4845,13 +4855,25 @@ PyObject *igraphmodule_Graph_personalized_pagerank(igraphmodule_GraphObject *sel
48454855 return igraphmodule_handle_igraph_error();
48464856 }
48474857
4848- arpack_options = (igraphmodule_ARPACKOptionsObject*)arpack_options_o;
4858+ if (igraphmodule_PyObject_to_pagerank_algo_t(algo_o, &algo))
4859+ return NULL;
4860+
4861+ popts.niter = (igraph_integer_t) niter; popts.eps = eps;
4862+
4863+ if (algo == IGRAPH_PAGERANK_ALGO_POWER) {
4864+ opts = &popts;
4865+ } else if (algo == IGRAPH_PAGERANK_ALGO_ARPACK) {
4866+ opts = igraphmodule_ARPACKOptions_get(arpack_options);
4867+ } else {
4868+ opts = 0;
4869+ }
4870+
48494871 if (rvsobj != Py_None)
4850- retval = igraph_personalized_pagerank_vs(&self->g, &res, 0, vs, PyObject_IsTrue(directed) ,
4851- damping, reset_vs, &weights, igraphmodule_ARPACKOptions_get(arpack_options) );
4872+ retval = igraph_personalized_pagerank_vs(&self->g, algo, &res, 0, vs,
4873+ PyObject_IsTrue(directed), damping, reset_vs, &weights, opts );
48524874 else
4853- retval = igraph_personalized_pagerank(&self->g, &res, 0, vs, PyObject_IsTrue(directed) ,
4854- damping, reset, &weights, igraphmodule_ARPACKOptions_get(arpack_options) );
4875+ retval = igraph_personalized_pagerank(&self->g, algo, &res, 0, vs,
4876+ PyObject_IsTrue(directed), damping, reset, &weights, opts );
48554877
48564878 if (retval) {
48574879 igraphmodule_handle_igraph_error();
@@ -12892,8 +12914,10 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
1289212914 /* interface to igraph_personalized_pagerank */
1289312915 {"personalized_pagerank", (PyCFunction) igraphmodule_Graph_personalized_pagerank,
1289412916 METH_VARARGS | METH_KEYWORDS,
12895- "personalized_pagerank(vertices=None, directed=True, damping=0.85, "
12896- "reset=None, reset_vertices=None, weights=None, arpack_options=None)\n\n"
12917+ "personalized_pagerank(vertices=None, directed=True, damping=0.85,\n"
12918+ " reset=None, reset_vertices=None, weights=None, \n"
12919+ " arpack_options=None, implementation=\"prpack\", niter=1000,\n"
12920+ " eps=0.001)\n\n"
1289712921 "Calculates the personalized PageRank values of a graph.\n\n"
1289812922 "The personalized PageRank calculation is similar to the PageRank\n"
1289912923 "calculation, but the random walk is reset to a non-uniform distribution\n"
@@ -12919,7 +12943,23 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
1291912943 " even an edge attribute name.\n"
1292012944 "@param arpack_options: an L{ARPACKOptions} object used to fine-tune\n"
1292112945 " the ARPACK eigenvector calculation. If omitted, the module-level\n"
12922- " variable called C{arpack_options} is used.\n"
12946+ " variable called C{arpack_options} is used. This argument is\n"
12947+ " ignored if not the ARPACK implementation is used, see the \n"
12948+ " I{implementation} argument.\n"
12949+ "@param implementation: which implementation to use to solve the \n"
12950+ " PageRank eigenproblem. Possible values are:\n\n"
12951+ " - C{\"prpack\"}: use the PRPACK library. This is a new \n"
12952+ " implementation in igraph 0.7\n\n"
12953+ " - C{\"arpack\"}: use the ARPACK library. This implementation\n"
12954+ " was used from version 0.5, until version 0.7.\n\n"
12955+ " - C{\"power\"}: use a simple power method. This is the\n"
12956+ " implementation that was used before igraph version 0.5.\n\n"
12957+ "@param niter: The number of iterations to use in the power method\n"
12958+ " implementation. It is ignored in the other implementations.\n"
12959+ "@param eps: The power method implementation will consider the\n"
12960+ " calculation as complete if the difference of PageRank values between\n"
12961+ " iterations change less than this value for every node. It is \n"
12962+ " ignored by the other implementations.\n"
1292312963 "@return: a list with the personalized PageRank values of the specified\n"
1292412964 " vertices.\n"},
1292512965
0 commit comments