OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
PySquarePolynomialMap.cpp
Go to the documentation of this file.
1/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
2 *
3 * MAUS is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * MAUS is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with MAUS. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17#include <Python.h>
18#include <structmember.h>
19
20#include <vector>
21#include <string>
22
26#include "Fields/Interpolation/LeastSquaresSolveFactory.h"
27
28#include "PyOpal/Globals.h"
31
33
35
37std::string("Return the coefficients of the matrix. Takes no arguments\n\n")+
38std::string("Return value is a list of lists, with polynomial coefficients\n")+
39std::string("for y_i = sum_j a_{ij}*prod_n(x_n^j_n) forming the i, j term\n")+
40std::string("in the matrix.\n");
41
42PyObject* get_coefficients_as_matrix(PyObject *self, PyObject *args, PyObject *kwds) {
43 PyPolynomialMap* py_map = reinterpret_cast<PyPolynomialMap*>(self);
44 // failed to cast or self was not initialised - something horrible happened
45 if (py_map == NULL) {
46 PyErr_SetString(PyExc_TypeError,
47 "Failed to resolve self as PolynomialMap");
48 return NULL;
49 }
50 if (py_map->map == NULL) {
51 PyErr_SetString(PyExc_TypeError,
52 "PolynomialMap not properly initialised");
53 return NULL;
54 }
56 PyObject* py_coefficients = PyList_New(coefficients.num_row());
57 // not safe from out of memory errors (etc)
58 for (size_t i = 0; i < coefficients.num_row(); ++i) {
59 PyObject* py_row = PyList_New(coefficients.num_col());
60 for (size_t j = 0; j < coefficients.num_col(); ++j) {
61 PyObject* py_value = PyFloat_FromDouble(coefficients(i+1, j+1));
62 Py_INCREF(py_value);
63 PyList_SetItem(py_row, j, py_value);
64 }
65 PyList_SetItem(py_coefficients, i, py_row);
66 Py_INCREF(py_row);
67 }
68 Py_INCREF(py_coefficients);
69 return py_coefficients;
70}
71
73std::string("Maps from the matrix index to the polynomial term.\n\n")+
74std::string(" - col: index of the matrix column.\n")+
75std::string(" - dim: dimension of the problem.\n")+
76std::string("Return value is a list of ints of length dim. Terms in the\n")+
77std::string("transfer matrix in the column given by col correspond to the\n")+
78std::string("coefficient of the x_j1^k1 ... x_jn^kn term where kn are the\n")+
79std::string("integers returned by this method.\n")+
80std::string("For example, PolynomialMap.index_by_power(5, 2) returns\n")+
81std::string("[2, 1] meaning the 7th column in a two-dimensional problem\n")+
82std::string("represents the coefficients of x_0^2 x_1^1\n");
83
84
85PyObject* index_by_power(PyObject *py_class, PyObject *args, PyObject *kwds) {
86 PyTypeObject* py_map_type = reinterpret_cast<PyTypeObject*>(py_class);
87 // failed to cast or self was not initialised - something horrible happened
88 if (py_map_type == NULL) {
89 PyErr_SetString(PyExc_TypeError,
90 "Failed to resolve self as PolynomialMapType");
91 return NULL;
92 }
93
94 int col = 0;
95 int dim = 0;
96 static char *kwlist[] = {
97 const_cast<char*>("col"),
98 const_cast<char*>("dim"),
99 NULL
100 };
101 if (!PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwlist, &col, &dim)) {
102 return NULL;
103 }
104 if (col < 0) {
105 PyErr_SetString(PyExc_ValueError, "col should be >= 0");
106 return NULL;
107 }
108 if (dim <= 0) {
109 PyErr_SetString(PyExc_ValueError, "dim should be > 0");
110 return NULL;
111 }
112 std::vector<int> powers =
114 PyObject* py_powers = PyList_New(powers.size());
115 Py_INCREF(py_powers);
116 for (size_t i = 0; i < powers.size(); ++i) {
117 PyObject* py_one_power = PyLong_FromSize_t(powers[i]);
118 Py_INCREF(py_one_power);
119 PyList_SetItem(py_powers, i, py_one_power);
120 }
121 return py_powers;
122}
123
125std::string("Apply the mapping to a point.\n\n")+
126std::string(" - point: list of floats with length equal to the point\n")+
127std::string(" dimension of the mapping, corresponding to the abscissa.\n")+
128std::string("Return value is a list of floats, with length equal to the\n")+
129std::string("value dimension of the mapping; corresponding to the ordinates\n");
130
131PyObject* evaluate(PyObject *self, PyObject *args, PyObject *kwds) {
132 PyPolynomialMap* py_map = reinterpret_cast<PyPolynomialMap*>(self);
133 // failed to cast or self was not initialised - something horrible happened
134 if (py_map == NULL) {
135 PyErr_SetString(PyExc_TypeError,
136 "Failed to resolve self as PolynomialMap");
137 return NULL;
138 }
139 if (py_map->map == NULL) {
140 PyErr_SetString(PyExc_TypeError,
141 "PolynomialMap not properly initialised");
142 return NULL;
143 }
144 PyObject* py_point;
145 static char *kwlist[] = {const_cast<char*>("point"), NULL};
146 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &py_point)) {
147 return NULL;
148 }
149
150 if (!PyList_Check(py_point)) {
151 PyErr_SetString(PyExc_TypeError, "point was not a list");
152 return NULL;
153 }
154 if (PyList_Size(py_point) != py_map->map->PointDimension()) {
155 PyErr_SetString(PyExc_TypeError, "point had wrong size");
156 return NULL;
157 }
158 std::vector<double> point(py_map->map->PointDimension());
159 for (size_t i = 0; i < point.size(); ++i) {
160 PyObject* point_i = PyList_GetItem(py_point, i);
161 point[i] = PyFloat_AsDouble(point_i);
162 }
163 if (PyErr_Occurred()) // probably not a double in the list
164 return NULL;
165 std::vector<double> value(py_map->map->ValueDimension());
166 py_map->map->F(&point[0], &value[0]);
167 PyObject* py_value = PyList_New(value.size());
168 for (size_t i = 0; i < value.size(); ++i) {
169 PyObject* value_i = PyFloat_FromDouble(value[i]);
170 PyList_SetItem(py_value, i, value_i);
171 Py_INCREF(value_i);
172 }
173 Py_INCREF(py_value);
174 return py_value;
175}
176
178std::string("Find a mapping by solving for the matrix.\n\n")+
179std::string(" - points: list, each entry containing a list of floats\n")+
180std::string(" corresponding to abscissa, each with length PointDimension.\n")+
181std::string(" The list should be as long as the number of coefficients in\n")+
182std::string(" the polynomial.\n")+
183std::string(" - values: list, each entry containing a list of floats\n")+
184std::string(" corresponding to ordinates, each with length ValueDimension.\n")+
185std::string(" The list should be as long as points.\n")+
186std::string(" - polynomial_order: integer, >= 0, corresponding to the\n")+
187std::string(" order of the fitted polynomial; 0 is constant, 1 is linear...\n")+
188std::string("Returns a polynomial map.\n");
189
190std::vector<std::vector<double> > get_vectors(PyObject* py_floats) {
191 // convert from list of list of floats to std::vector< std::vector<double> >
192 // first check validity of coefficients
193 std::vector< std::vector<double> > data;
194 if (!PyList_Check(py_floats)) {
195 return std::vector<std::vector<double> >();
196 }
197 size_t num_rows = PyList_Size(py_floats);
198 if (num_rows == 0) {
199 return std::vector<std::vector<double> >();
200 }
201 size_t num_cols = 0;
202 // now loop over the rows
203 for (size_t i = 0; i < num_rows; ++i) {
204 PyObject* row = PyList_GetItem(py_floats, i);
205 if (!PyList_Check(row)) {
206 return std::vector<std::vector<double> >();
207 }
208 // do some initialisation in the first row
209 if (i == 0) {
210 num_cols = PyList_Size(row);
211 if (num_cols == 0) {
212 return std::vector<std::vector<double> >();
213 }
214 data = std::vector< std::vector<double> >(num_rows, std::vector<double>(num_cols));
215 }
216 // now loop over columns
217 if (PyList_Size(row) != static_cast<int>(num_cols)) {
218 return std::vector<std::vector<double> >();
219 }
220 for (size_t j = 0; j < num_cols; ++j) {
221 PyObject* py_value = PyList_GetItem(row, j);
222 data.at(i).at(j) = PyFloat_AsDouble(py_value);
223 if (PyErr_Occurred() != NULL) // not a float
224 return std::vector<std::vector<double> >();
225 }
226 }
227 return data;
228}
229
230PyObject* exact_solve(PyObject *py_class, PyObject *args, PyObject *kwds) {
231 PyTypeObject* py_map_type = reinterpret_cast<PyTypeObject*>(py_class);
232 // failed to cast or self was not initialised - something horrible happened
233 if (py_map_type == NULL) {
234 PyErr_SetString(PyExc_TypeError,
235 "Failed to resolve self as PolynomialMapType");
236 return NULL;
237 }
238
239 PyObject* py_points = NULL;
240 PyObject* py_values = NULL;
241 int polynomial_order = 0;
242 PyObject* py_error_matrix = Py_None; // borrowed reference
243 static char *kwlist[] = {
244 const_cast<char*>("points"),
245 const_cast<char*>("values"),
246 const_cast<char*>("polynomial_order"),
247 const_cast<char*>("error_matrix"),
248 NULL
249 };
250 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOi|O", kwlist, &py_points,
251 &py_values, &polynomial_order, &py_error_matrix)) {
252 return NULL;
253 }
254 if (polynomial_order < 0) {
255 PyErr_SetString(PyExc_ValueError, "polynomial_order should be >= 0");
256 return NULL;
257 }
258 std::vector<std::vector<double> > points = get_vectors(py_points);
259 if (points.size() == 0) {
260 PyErr_SetString(PyExc_ValueError, "Failed to evaluate points");
261 return NULL;
262 }
263 std::vector<std::vector<double> > values = get_vectors(py_values);
264 if (values.size() == 0) {
265 PyErr_SetString(PyExc_ValueError, "Failed to evaluate values");
266 return NULL;
267 }
268 if (points.size() != values.size()) {
269 PyErr_SetString(PyExc_ValueError, "points misaligned with values");
270 return NULL;
271 }
273 try {
274 std::vector<std::vector<double> > no_derivs;
275 std::vector<std::vector<int> > no_indices;
276 size_t dim = points[0].size();
277 interpolation::SolveFactory solve(polynomial_order, polynomial_order,
278 dim, dim, points, no_derivs, no_indices);
279 test_map = solve.PolynomialSolve(values, no_derivs);
280 } catch (GeneralClassicException& exc) {
281 PyErr_SetString(PyExc_ValueError, exc.what().c_str());
282 return NULL;
283 }
284 PyObject* py_map_obj = _alloc(py_map_type, 0);
285 PyPolynomialMap* py_map = reinterpret_cast<PyPolynomialMap*>(py_map_obj);
286 py_map->map = test_map;
287 return py_map_obj;
288}
289
291std::string("Find a mapping by solving for the matrix.\n\n")+
292std::string(" - points: list, each entry containing a list of floats\n")+
293std::string(" corresponding to abscissa, each with length PointDimension.\n")+
294std::string(" The list should be at least as long as the number of \n")+
295std::string(" coefficients in the polynomial.\n")+
296std::string(" - values: list, each entry containing a list of floats\n")+
297std::string(" corresponding to ordinates, each with length ValueDimension.\n")+
298std::string(" The list should be as long as points.\n")+
299std::string(" - polynomial_order: integer, >= 0, corresponding to the\n")+
300std::string(" order of the fitted polynomial; 0 is constant, 1 is linear...\n")+
301std::string(" - coefficients: list of PolynomialCoefficients. Fix these\n")+
302std::string(" coefficients to some \n")+
303std::string(" - weights: list, of length = 0, corresponding to\n")+
304std::string("Returns a polynomial map.\n");
305
306
307PyObject* least_squares(PyObject *py_class, PyObject *args, PyObject *kwds) {
308 PyTypeObject* py_map_type = reinterpret_cast<PyTypeObject*>(py_class);
309 // failed to cast or self was not initialised - something horrible happened
310 if (py_map_type == NULL) {
311 PyErr_SetString(PyExc_TypeError,
312 "Failed to resolve self as PolynomialMapType");
313 return NULL;
314 }
315
316 PyObject* py_points = NULL;
317 PyObject* py_values = NULL;
318 int polynomial_order = 0;
319 PyObject* py_coefficients = NULL;
320 PyObject* py_weights = NULL;
321 static char *kwlist[] = {
322 const_cast<char*>("points"),
323 const_cast<char*>("values"),
324 const_cast<char*>("polynomial_order"),
325 const_cast<char*>("polynomial_coefficients"),
326 const_cast<char*>("weights"),
327 NULL
328 };
329 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOi|OO", kwlist, &py_points,
330 &py_values, &polynomial_order, &py_coefficients, &py_weights)) {
331 return NULL;
332 }
333 if (polynomial_order < 0) {
334 PyErr_SetString(PyExc_ValueError, "polynomial_order should be >= 0");
335 return NULL;
336 }
337 std::vector<std::vector<double> > points = get_vectors(py_points);
338 std::vector<std::vector<double> > values = get_vectors(py_values);
339 std::vector<interpolation::PolynomialCoefficient> coeff;
340 std::vector<double> weights;
341 // weights
342 if (py_weights != NULL) {
343 if (!PyList_Check(py_weights)) {
344 PyErr_SetString(PyExc_TypeError,
345 "Failed to resolve weights as a list");
346 return NULL;
347 }
348 size_t list_size = PyList_Size(py_weights); // nb: size 0 is legal
349 weights = std::vector<double>(list_size);
350 for (size_t i = 0; i < list_size; ++i) {
351 PyObject* py_value = PyList_GetItem(py_weights, i);
352 weights[i] = int(PyFloat_AsDouble(py_value));
353 if (PyErr_Occurred() != NULL) { // not an int
354 return NULL;
355 }
356 }
357 }
358 // coefficients
359 if (py_coefficients != NULL) {
360 if (!PyList_Check(py_coefficients)) {
361 PyErr_SetString(PyExc_TypeError,
362 "Failed to resolve coefficients as a list");
363 return NULL;
364 }
365 size_t list_size = PyList_Size(py_coefficients); // nb: size 0 is legal
366 for (size_t i = 0; i < list_size; ++i) {
367 PyObject* py_value = PyList_GetItem(py_coefficients, i);
368 PyCoefficient* py_coeff = reinterpret_cast<PyCoefficient*>(py_value);
369 if (py_coeff == NULL) {
370 PyErr_SetString(PyExc_TypeError,
371 "Failed to resolve list item as a PolynomialCoefficient.");
372 return NULL;
373 }
374 coeff.push_back(*(py_coeff->coeff));
375 }
376
377 }
379 try {
380 interpolation::LeastSquaresSolveFactory solver(polynomial_order, points);
381 solver.setWeights(weights);
382 solver.setCoefficients(coeff);
383 test_map = new interpolation::SquarePolynomialVector(solver.solve(values));
384 } catch (GeneralClassicException& exc) {
385 PyErr_SetString(PyExc_ValueError, exc.what().c_str());
386 return NULL;
387 }
388 PyObject* py_map_obj = _alloc(py_map_type, 0);
389 PyPolynomialMap* py_map = reinterpret_cast<PyPolynomialMap*>(py_map_obj);
390 py_map->map = test_map;
391 return py_map_obj;
392}
393
394
395
396int _init(PyObject* self, PyObject *args, PyObject *kwds) {
397 PyPolynomialMap* py_map = reinterpret_cast<PyPolynomialMap*>(self);
398 // failed to cast or self was not initialised - something horrible happened
399 if (py_map == NULL) {
400 PyErr_SetString(PyExc_TypeError,
401 "Failed to resolve self as PolynomialMap in __init__");
402 return -1;
403 }
404 // legal python to call initialised_object.__init__() to reinitialise, so
405 // handle this case
406 if (py_map->map != NULL) {
407 delete py_map->map;
408 py_map->map = NULL;
409 }
410 // read in arguments
411 int point_dim;
412 PyObject* py_coefficients;
413 static char *kwlist[] = {const_cast<char*>("point_dimension"),
414 const_cast<char*>("coefficients"), NULL};
415 if (!PyArg_ParseTupleAndKeywords(args, kwds, "iO", kwlist,
416 &point_dim, &py_coefficients)) {
417 return -1;
418 }
419
420 // convert from list of list of floats to Matrix<double>
421 // first check validity of coefficients
422 if (!PyList_Check(py_coefficients)) {
423 PyErr_SetString(PyExc_TypeError,
424 "Failed to resolve coefficients as a list");
425 return -1;
426 }
427 size_t num_rows = PyList_Size(py_coefficients);
428 if (num_rows == 0) {
429 PyErr_SetString(PyExc_ValueError, "coefficients was empty");
430 return -1;
431 }
432 size_t num_cols = 0;
434 // now loop over the rows
435 for (size_t i = 0; i < num_rows; ++i) {
436 PyObject* row = PyList_GetItem(py_coefficients, i);
437 if (!PyList_Check(py_coefficients)) {
438 PyErr_SetString(PyExc_TypeError,
439 "Failed to resolve coefficients row as a list");
440 return -1;
441 }
442 // do some initialisation in the first row
443 if (i == 0) {
444 num_cols = PyList_Size(row);
445 if (num_cols == 0) {
446 PyErr_SetString(PyExc_ValueError, "coefficients row was empty");
447 return -1;
448 }
449 coefficients = interpolation::MMatrix<double>(num_rows, num_cols);
450 }
451 // now loop over columns
452 if (PyList_Size(row) != static_cast<int>(num_cols)) {
453 PyErr_SetString(PyExc_ValueError,
454 "coefficients row had wrong number of elements");
455 }
456 for (size_t j = 0; j < num_cols; ++j) {
457 PyObject* py_value = PyList_GetItem(row, j);
458 coefficients(i+1, j+1) = PyFloat_AsDouble(py_value);
459 if (PyErr_Occurred() != NULL) // not a float
460 return -1;
461 }
462 }
463
464 // now initialise the internal map
465 try {
466 py_map->map = new interpolation::SquarePolynomialVector(point_dim, coefficients);
467 } catch (std::exception& exc) {
468 PyErr_SetString(PyExc_RuntimeError, (&exc)->what());
469 return -1;
470 }
471 return 0;
472}
473
474PyObject *_alloc(PyTypeObject *type, Py_ssize_t nitems) {
475 void* void_map = malloc(sizeof(PyPolynomialMap));
476 PyPolynomialMap* map = reinterpret_cast<PyPolynomialMap*>(void_map);
477 map->map = NULL;
478 Py_REFCNT(map) = 1;
479 Py_TYPE(map) = type;
480 return reinterpret_cast<PyObject*>(map);
481}
482
483PyObject *_new(PyTypeObject *type, Py_ssize_t nitems) {
484 return _alloc(type, nitems);
485}
486
488 _free(self);
489}
490
491void _free(PyPolynomialMap * self) {
492 if (self != NULL) {
493 if (self->map != NULL)
494 delete self->map;
495 free(self);
496 }
497}
498
499static PyMemberDef _members[] = {
500{NULL}
501};
502
503static PyMethodDef _methods[] = {
504{"get_coefficients_as_matrix", (PyCFunction)get_coefficients_as_matrix,
505 METH_VARARGS|METH_KEYWORDS, get_coefficients_as_matrix_docstring.c_str()},
506{"evaluate", (PyCFunction)evaluate,
507 METH_VARARGS|METH_KEYWORDS, evaluate_docstring.c_str()},
508{"exact_solve", (PyCFunction)exact_solve,
509 METH_CLASS|METH_VARARGS|METH_KEYWORDS, exact_solve_docstring.c_str()},
510{"least_squares", (PyCFunction)least_squares,
511 METH_CLASS|METH_VARARGS|METH_KEYWORDS, least_squares_docstring.c_str()},
512{"index_by_power", (PyCFunction)index_by_power,
513 METH_CLASS|METH_VARARGS|METH_KEYWORDS, index_by_power_docstring.c_str()},
514{NULL}
515};
516
517std::string class_docstring =
518std::string("PolynomialMap provides routines to calculate multivariate \n")+
519std::string("polynomials.\n\n")+
520std::string("__init__()\n")+
521std::string(" Takes two arguments.\n")+
522std::string(" - point_dim: integer which defines the dimension of the\n")+
523std::string(" points (abscissa)\n")+
524std::string(" - coefficients: list of lists of floats which define the\n")+
525std::string(" polynomial\n")+
526std::string("The value dimension of the PolynomialMap is the number of rows\n")+
527std::string("coefficients matrix\n");
528
529static PyTypeObject PyPolynomialMapType = {
530 PyObject_HEAD_INIT(NULL)
531 "polynomial_map.PolynomialMap", /*tp_name*/
532 sizeof(PyPolynomialMap), /*tp_basicsize*/
533 0, /*tp_itemsize*/
534 (destructor)_dealloc, /*tp_dealloc*/
535 0, /*tp_print*/
536 0, /*tp_getattr*/
537 0, /*tp_setattr*/
538 0, /*tp_compare*/
539 0, /*tp_repr*/
540 0, /*tp_as_number*/
541 0, /*tp_as_sequence*/
542 0, /*tp_as_mapping*/
543 0, /*tp_hash */
544 0, /*tp_call*/
545 0, /*tp_str*/
546 0, /*tp_getattro*/
547 0, /*tp_setattro*/
548 0, /*tp_as_buffer*/
549 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
550 class_docstring.c_str(), /* tp_doc */
551 0, /* tp_traverse */
552 0, /* tp_clear */
553 0, /* tp_richcompare */
554 0, /* tp_weaklistoffset */
555 0, /* tp_iter */
556 0, /* tp_iternext */
557 _methods, /* tp_methods */
558 _members, /* tp_members */
559 0, /* tp_getset */
560 0, /* tp_base */
561 0, /* tp_dict */
562 0, /* tp_descr_get */
563 0, /* tp_descr_set */
564 0, /* tp_dictoffset */
565 (initproc)_init, /* tp_init */
566 (allocfunc)_alloc, /* tp_alloc, called by new */
567 0, // (newfunc)_new, /* tp_new */
568 (freefunc)_free, /* tp_free, called by dealloc */
569};
570
571} // namespace PyPolynomialMap
572
573const char* module_docstring =
574 "polynomial_map module contains the PolynomialMap class";
575
576static struct PyModuleDef polynomial_map_def = {
577 PyModuleDef_HEAD_INIT,
578 "polynomial_map", /* m_name */
579 module_docstring, /* m_doc */
580 -1, /* m_size */
581 NULL, /* m_methods */
582 NULL, /* m_reload */
583 NULL, /* m_traverse */
584 NULL, /* m_clear */
585 NULL, /* m_free */
586};
587
588PyMODINIT_FUNC PyInit_polynomial_map(void) {
590 PySquarePolynomialMap::PyPolynomialMapType.tp_new = PyType_GenericNew;
591 if (PyType_Ready(&PySquarePolynomialMap::PyPolynomialMapType) < 0)
592 return NULL;
593
594 PyObject* module = PyModule_Create(&polynomial_map_def);
595 if (module == NULL)
596 return NULL;
597
598 PyTypeObject* polynomial_map_type = &PySquarePolynomialMap::PyPolynomialMapType;
599 Py_INCREF(polynomial_map_type);
600 PyModule_AddObject(module, "PolynomialMap",
601 reinterpret_cast<PyObject*>(polynomial_map_type));
602
603 return module;
604}
605
606
void Initialise()
Definition: Globals.cpp:78
std::string get_coefficients_as_matrix_docstring
PyObject * least_squares(PyObject *py_class, PyObject *args, PyObject *kwds)
PyObject * index_by_power(PyObject *py_class, PyObject *args, PyObject *kwds)
PyObject * exact_solve(PyObject *py_class, PyObject *args, PyObject *kwds)
std::vector< std::vector< double > > get_vectors(PyObject *py_floats)
PyObject * _alloc(PyTypeObject *type, Py_ssize_t nitems)
void _dealloc(PyPolynomialMap *self)
void _free(PyPolynomialMap *self)
int _init(PyObject *self, PyObject *args, PyObject *kwds)
PyObject * _new(PyTypeObject *type, Py_ssize_t nitems)
PyObject * get_coefficients_as_matrix(PyObject *self, PyObject *args, PyObject *kwds)
PyObject * evaluate(PyObject *self, PyObject *args, PyObject *kwds)
void solve(double *Matrix, double *Solution, double *rightHandSide, const int &M, const int &N)
boost::function< boost::tuple< double, bool >(arguments_t)> type
Definition: function.hpp:21
interpolation::PolynomialCoefficient * coeff
interpolation::SquarePolynomialVector * map
size_t num_col() const
returns number of columns in the matrix
size_t num_row() const
returns number of rows in the matrix
SolveFactory is a factory class for solving a set of linear equations to generate a polynomial based ...
Definition: SolveFactory.h:44
SquarePolynomialVector describes a vector of multivariate polynomials.
static std::vector< int > IndexByPower(int index, int nInputVariables)
MMatrix< double > GetCoefficientsAsMatrix() const
void F(const double *point, double *value) const
virtual const std::string & what() const
Return the message string for the exception.
PyMODINIT_FUNC PyInit_polynomial_map(void)
const char * module_docstring