@@ -4784,7 +4784,7 @@ PyObject *igraphmodule_Graph_personalized_pagerank(igraphmodule_GraphObject *sel
4784
4784
{
4785
4785
static char *kwlist[] =
4786
4786
{ "vertices", "directed", "damping", "reset", "reset_vertices", "weights",
4787
- "arpack_options", NULL };
4787
+ "arpack_options", "implementation", "niter", "eps", NULL };
4788
4788
PyObject *directed = Py_True;
4789
4789
PyObject *vobj = Py_None, *wobj = Py_None, *robj = Py_None, *rvsobj = Py_None;
4790
4790
PyObject *list;
@@ -4796,12 +4796,21 @@ PyObject *igraphmodule_Graph_personalized_pagerank(igraphmodule_GraphObject *sel
4796
4796
igraph_vector_t weights;
4797
4797
igraph_bool_t return_single = 0;
4798
4798
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;
4799
4805
int retval;
4800
4806
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,
4803
4810
&igraphmodule_ARPACKOptionsType,
4804
- &arpack_options_o))
4811
+ &arpack_options_o, &algo_o, &niter, &eps))
4812
+
4813
+
4805
4814
return NULL;
4806
4815
4807
4816
if (robj != Py_None && rvsobj != Py_None) {
@@ -4814,6 +4823,7 @@ PyObject *igraphmodule_Graph_personalized_pagerank(igraphmodule_GraphObject *sel
4814
4823
return NULL;
4815
4824
}
4816
4825
4826
+ arpack_options = (igraphmodule_ARPACKOptionsObject*)arpack_options_o;
4817
4827
if (robj != Py_None) {
4818
4828
if (igraphmodule_attrib_to_vector_t(robj, self, &reset, ATTRIBUTE_TYPE_VERTEX)) {
4819
4829
igraph_vs_destroy(&vs);
@@ -4845,13 +4855,25 @@ PyObject *igraphmodule_Graph_personalized_pagerank(igraphmodule_GraphObject *sel
4845
4855
return igraphmodule_handle_igraph_error();
4846
4856
}
4847
4857
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
+
4849
4871
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 );
4852
4874
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 );
4855
4877
4856
4878
if (retval) {
4857
4879
igraphmodule_handle_igraph_error();
@@ -12892,8 +12914,10 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
12892
12914
/* interface to igraph_personalized_pagerank */
12893
12915
{"personalized_pagerank", (PyCFunction) igraphmodule_Graph_personalized_pagerank,
12894
12916
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"
12897
12921
"Calculates the personalized PageRank values of a graph.\n\n"
12898
12922
"The personalized PageRank calculation is similar to the PageRank\n"
12899
12923
"calculation, but the random walk is reset to a non-uniform distribution\n"
@@ -12919,7 +12943,23 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
12919
12943
" even an edge attribute name.\n"
12920
12944
"@param arpack_options: an L{ARPACKOptions} object used to fine-tune\n"
12921
12945
" 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"
12923
12963
"@return: a list with the personalized PageRank values of the specified\n"
12924
12964
" vertices.\n"},
12925
12965
0 commit comments