4
Copyright (C) 2007 Gabor Csardi <csardi@rmki.kfki.hu>
5
MTA RMKI, Konkoly-Thege Miklos st. 29-33, Budapest 1121, Hungary
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24
#include "arpackobject.h"
25
#include "graphobject.h"
28
PyObject* igraphmodule_arpack_options_default;
31
* \ingroup python_interface_arpack
32
* \brief Checks if the object is an ARPACK parameter object
34
int igraphmodule_ARPACKOptions_Check(PyObject *ob) {
35
if (ob) return PyType_IsSubtype(ob->ob_type, &igraphmodule_ARPACKOptionsType);
40
* \ingroup python_interface_arpack
41
* \brief Allocates a new ARPACK parameters object
43
PyObject* igraphmodule_ARPACKOptions_new() {
44
igraphmodule_ARPACKOptionsObject* self;
45
self=PyObject_New(igraphmodule_ARPACKOptionsObject,
46
&igraphmodule_ARPACKOptionsType);
48
igraph_arpack_options_init(&self->params);
49
igraph_arpack_options_init(&self->params_out);
51
return (PyObject*)self;
55
* \ingroup python_interface_arpack
56
* \brief Deallocates a Python representation of a given ARPACK parameters object
58
void igraphmodule_ARPACKOptions_dealloc(
59
igraphmodule_ARPACKOptionsObject* self) {
60
/*igraph_arpack_options_destroy(&self->params);*/
61
PyObject_Del((PyObject*)self);
64
/** \ingroup python_interface_arpack
65
* \brief Returns one of the attributes of a given ARPACK parameters object
67
PyObject* igraphmodule_ARPACKOptions_getattr(
68
igraphmodule_ARPACKOptionsObject* self, char* attrname) {
69
PyObject *result = NULL;
71
if (strcmp(attrname, "bmat") == 0) {
72
char buf[2] = { self->params_out.bmat[0], 0 };
73
result=PyString_FromString(buf);
74
} else if (strcmp(attrname, "n") == 0) {
75
result=PyInt_FromLong(self->params_out.n);
76
} else if (strcmp(attrname, "which") == 0) {
77
char buf[3] = { self->params.which[0], self->params.which[1], 0 };
78
result=PyString_FromString(buf);
79
} else if (strcmp(attrname, "nev") == 0) {
80
result=PyInt_FromLong(self->params.nev);
81
} else if (strcmp(attrname, "tol") == 0) {
82
result=PyFloat_FromDouble((double)self->params.tol);
83
} else if (strcmp(attrname, "ncv") == 0) {
84
result=PyInt_FromLong(self->params.ncv);
85
} else if (strcmp(attrname, "ldv") == 0) {
86
result=PyInt_FromLong(self->params.ldv);
87
} else if (strcmp(attrname, "ishift") == 0) {
88
result=PyInt_FromLong(self->params.ishift);
89
} else if (strcmp(attrname, "maxiter") == 0 ||
90
strcmp(attrname, "mxiter") == 0) {
91
result=PyInt_FromLong(self->params.mxiter);
92
} else if (strcmp(attrname, "nb") == 0) {
93
result=PyInt_FromLong(self->params.nb);
94
} else if (strcmp(attrname, "mode") == 0) {
95
result=PyInt_FromLong(self->params.mode);
96
} else if (strcmp(attrname, "start") == 0) {
97
result=PyInt_FromLong(self->params.start);
98
} else if (strcmp(attrname, "sigma") == 0) {
99
result=PyFloat_FromDouble((double)self->params.sigma);
100
} else if (strcmp(attrname, "info") == 0) {
101
result=PyInt_FromLong(self->params_out.info);
102
} else if (strcmp(attrname, "iter") == 0) {
103
result=PyInt_FromLong(self->params_out.iparam[2]);
104
} else if (strcmp(attrname, "nconv") == 0) {
105
result=PyInt_FromLong(self->params_out.iparam[4]);
106
} else if (strcmp(attrname, "numop") == 0) {
107
result=PyInt_FromLong(self->params_out.iparam[8]);
108
} else if (strcmp(attrname, "numopb") == 0) {
109
result=PyInt_FromLong(self->params_out.iparam[9]);
110
} else if (strcmp(attrname, "numreo") == 0) {
111
result=PyInt_FromLong(self->params_out.iparam[10]);
113
PyErr_SetString(PyExc_AttributeError, attrname);
118
/** \ingroup python_interface_arpack
119
* \brief Sets one of the attributes of a given ARPACK parameters object
121
int igraphmodule_ARPACKOptions_setattr(
122
igraphmodule_ARPACKOptionsObject* self, char* attrname,
125
PyErr_SetString(PyExc_TypeError, "attribute can not be deleted");
128
if (strcmp(attrname, "maxiter") == 0 ||
129
strcmp(attrname, "mxiter") == 0) {
130
if (PyInt_Check(value)) {
131
long int n=PyInt_AsLong(value);
132
if (n>0) self->params.mxiter=n;
134
PyErr_SetString(PyExc_ValueError, "maxiter must be positive");
138
PyErr_SetString(PyExc_ValueError, "integer expected");
141
} else if (strcmp(attrname, "tol") == 0) {
142
if (PyInt_Check(value)) {
143
self->params.tol = (igraph_real_t) PyInt_AsLong(value);
144
} else if (PyFloat_Check(value)) {
145
self->params.tol = (igraph_real_t) PyFloat_AsDouble(value);
147
PyErr_SetString(PyExc_ValueError, "integer or float expected");
151
PyErr_SetString(PyExc_AttributeError, attrname);
158
/** \ingroup python_interface_arpack */
159
igraph_arpack_options_t *igraphmodule_ARPACKOptions_get(
160
igraphmodule_ARPACKOptionsObject *self) {
161
self->params_out = self->params;
162
self->params_out.iparam[0] = self->params.ishift;
163
self->params_out.iparam[2] = self->params.mxiter;
164
self->params_out.iparam[3] = self->params.nb;
165
self->params_out.iparam[6] = self->params.mode;
166
self->params_out.lworkl = 0;
167
self->params_out.info = self->params.start;
169
return &self->params_out;
172
/** \ingroup python_interface_arpack
173
* \brief Formats an \c igraph.ARPACKOptions object in a
174
* human-consumable format.
176
* \return the formatted textual representation as a \c PyObject
178
PyObject* igraphmodule_ARPACKOptions_str(
179
igraphmodule_ARPACKOptionsObject *self) {
182
s=PyString_FromFormat("ARPACK parameters");
187
* \ingroup python_interface_arpack
188
* Method table for the \c igraph.ARPACKOptions object
190
PyMethodDef igraphmodule_ARPACKOptions_methods[] = {
191
/*{"attributes", (PyCFunction)igraphmodule_Edge_attributes,
193
"attributes() -> list\n\n"
194
"Returns the attribute list of the graph's edges\n"
200
* \ingroup python_interface_edge
201
* Getter/setter table for the \c igraph.ARPACKOptions object
203
PyGetSetDef igraphmodule_ARPACKOptions_getseters[] = {
204
/*{"tuple", (getter)igraphmodule_Edge_get_tuple, NULL,
205
"Source and target node index of this edge as a tuple", NULL
210
/** \ingroup python_interface_edge
211
* Python type object referencing the methods Python calls when it performs
212
* various operations on an ARPACK parameters object
214
PyTypeObject igraphmodule_ARPACKOptionsType = {
215
PyObject_HEAD_INIT(NULL) /* */
217
"igraph.ARPACKOptions", /* tp_name */
218
sizeof(igraphmodule_ARPACKOptionsObject), /* tp_basicsize */
220
(destructor)igraphmodule_ARPACKOptions_dealloc, /* tp_dealloc */
222
(getattrfunc)igraphmodule_ARPACKOptions_getattr, /* tp_getattr */
223
(setattrfunc)igraphmodule_ARPACKOptions_setattr, /* tp_setattr */
226
0, /* tp_as_number */
227
0, /* tp_as_sequence */
228
0, /* tp_as_mapping */
231
(reprfunc)igraphmodule_ARPACKOptions_str, /* tp_str */
234
0, /* tp_as_buffer */
235
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
236
"Class representing the parameters of the ARPACK module.\n\n"
237
"ARPACK is a Fortran implementation of the implicitly restarted\n"
238
"Arnoldi method, an algorithm for calculating some of the\n"
239
"eigenvalues and eigenvectors of a given matrix. igraph uses this\n"
240
"package occasionally, and this class can be used to fine-tune the\n"
241
"behaviour of ARPACK in such cases.\n\n"
242
"The class has several attributes which are not documented here,\n"
243
"since they are usually of marginal use to the ordinary user.\n"
244
"See the source code of the original ARPACK Fortran package\n"
245
"(especially the file C{dsaupd.f}) for a detailed explanation of the\n"
246
"parameters. Only the most basic attributes are explained here. Most\n"
247
"of them are read only unless stated otherwise.\n\n"
248
" - C{bmat}: type of the eigenproblem solved. C{'I'} means standard\n"
249
" eigenproblem (A*x = lambda*x), C{'G'} means generalized\n"
250
" eigenproblem (A*x = lambda*B*x).\n\n"
251
" - C{n}: dimension of the eigenproblem\n\n"
252
" - C{tol}: precision. If less than or equal to zero, the standard\n"
253
" machine precision is used as computed by the LAPACK utility\n"
254
" called C{dlamch}. This can be modified.\n\n"
255
" - C{mxiter}: maximum number of update iterations to take. This\n"
256
" can be modified. You can also use C{maxiter}.\n\n"
257
" - C{iter}: actual number of update iterations taken\n\n"
258
" - C{numop}: total number of OP*x operations\n\n"
259
" - C{numopb}: total number of B*x operations if C{bmat} is C{'G'}\n\n"
260
" - C{numreo}: total number of steps of re-orthogonalization\n\n"
264
0, /* tp_richcompare */
265
0, /* tp_weaklistoffset */
268
igraphmodule_ARPACKOptions_methods, /* tp_methods */
270
igraphmodule_ARPACKOptions_getseters, /* tp_getset */
273
0, /* tp_descr_get */
274
0, /* tp_descr_set */
275
0, /* tp_dictoffset */
278
(newfunc)igraphmodule_ARPACKOptions_new, /* tp_new */