18#include <structmember.h>
21#include "PyOpal/Globals.h"
22#include "PyOpal/PyPolynomialCoefficient.h"
30int _init(PyObject* self, PyObject *args, PyObject *kwds) {
33 if (py_coeff ==
nullptr) {
34 PyErr_SetString(PyExc_TypeError,
35 "Failed to resolve self as PolynomialCoefficient in __init__");
40 if (py_coeff->
coeff !=
nullptr) {
41 delete py_coeff->
coeff;
42 py_coeff->
coeff =
nullptr;
49 static char *kwlist[] = {
const_cast<char*
>(
"index_by_vector"),
50 const_cast<char*
>(
"output_axis"),
51 const_cast<char*
>(
"coefficient_value"),
53 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"Oid", kwlist,
54 &py_index, &value_axis, &coefficient)) {
60 if (!PyList_Check(py_index)) {
61 PyErr_SetString(PyExc_TypeError,
62 "Failed to resolve index as a list");
65 size_t list_size = PyList_Size(py_index);
66 std::vector<int> index(list_size);
68 for (
size_t i = 0; i < list_size; ++i) {
69 PyObject* py_value = PyList_GetItem(py_index, i);
70 index[i] = int(PyLong_AsLong(py_value));
71 if (PyErr_Occurred() !=
nullptr) {
78 }
catch (std::exception& exc) {
79 PyErr_SetString(PyExc_RuntimeError, (&exc)->what());
88 coeff->
coeff =
nullptr;
90 Py_TYPE(coeff) =
type;
91 return reinterpret_cast<PyObject*
>(coeff);
94PyObject *
_new(PyTypeObject *
type, Py_ssize_t nitems) {
99 if (self !=
nullptr) {
100 if (self->
coeff !=
nullptr)
119std::string(
"PolynomialCoefficient docstring\n");
122 PyObject_HEAD_INIT(
nullptr)
123 "polynomial_coefficient.PolynomialCoefficient",
141 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
166 "polynomial_coefficient module contains the PolynomialCoefficient class";
169 PyModuleDef_HEAD_INIT,
170 "polynomial_coefficient",
187 if (module ==
nullptr)
190 PyTypeObject* polynomial_coeff_type =
192 Py_INCREF(polynomial_coeff_type);
193 PyModule_AddObject(module,
"PolynomialCoefficient",
194 reinterpret_cast<PyObject*
>(polynomial_coeff_type));
PyMODINIT_FUNC PyInit_polynomial_coefficient(void)
const char * module_docstring
static struct PyModuleDef polynomial_coefficient_def
void Initialise()
Globals namespace provides routines to initialise global objects:
static PyMemberDef _members[]
static PyMethodDef _methods[]
int _init(PyObject *self, PyObject *args, PyObject *kwds)
interpolation::PolynomialCoefficient * coeff
static PyTypeObject PyCoefficientType
PyObject * _alloc(PyTypeObject *type, Py_ssize_t nitems)
std::string class_docstring
void _free(PyCoefficient *self)
void _dealloc(PyCoefficient *self)
PyObject * _new(PyTypeObject *type, Py_ssize_t nitems)
PyPolynomialMap is the python implementation of the C++ PolynomialMap class.
boost::function< boost::tuple< double, bool >(arguments_t)> type
PolynomialCoefficient represents a coefficient in a multi-dimensional polynomial.