18 #include <structmember.h>
21 #include "PyOpal/Globals.h"
22 #include "PyOpal/PyPolynomialCoefficient.h"
24 namespace PyPolynomialCoefficient {
30 int _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) {
79 PyErr_SetString(PyExc_RuntimeError, (&exc)->what());
85 PyObject *
_alloc(PyTypeObject *
type, Py_ssize_t nitems) {
88 coeff->
coeff =
nullptr;
90 Py_TYPE(coeff) =
type;
91 return reinterpret_cast<PyObject*
>(coeff);
94 PyObject *
_new(PyTypeObject *
type, Py_ssize_t nitems) {
95 return _alloc(type, nitems);
99 if (
self !=
nullptr) {
100 if (self->coeff !=
nullptr)
110 static PyMemberDef _members[] = {
114 static PyMethodDef _methods[] = {
119 std::string(
"PolynomialCoefficient docstring\n");
121 static PyTypeObject PyCoefficientType = {
122 PyObject_HEAD_INIT(
nullptr)
123 "polynomial_coefficient.PolynomialCoefficient",
141 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
142 class_docstring.c_str(),
166 "polynomial_coefficient module contains the PolynomialCoefficient class";
168 static struct PyModuleDef polynomial_coefficient_def = {
169 PyModuleDef_HEAD_INIT,
170 "polynomial_coefficient",
182 PyPolynomialCoefficient::PyCoefficientType.tp_new = PyType_GenericNew;
183 if (PyType_Ready(&PyPolynomialCoefficient::PyCoefficientType) < 0)
186 PyObject* module = PyModule_Create(&polynomial_coefficient_def);
187 if (module ==
nullptr)
190 PyTypeObject* polynomial_coeff_type =
191 &PyPolynomialCoefficient::PyCoefficientType;
192 Py_INCREF(polynomial_coeff_type);
193 PyModule_AddObject(module,
"PolynomialCoefficient",
194 reinterpret_cast<PyObject*>(polynomial_coeff_type));
PolynomialCoefficient represents a coefficient in a multi-dimensional polynomial. ...
void _free(PyCoefficient *self)
const char * module_docstring
interpolation::PolynomialCoefficient * coeff
void _dealloc(PyCoefficient *self)
int _init(PyObject *self, PyObject *args, PyObject *kwds)
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special exception
std::string class_docstring
PyMODINIT_FUNC PyInit_polynomial_coefficient(void)
PyObject * _alloc(PyTypeObject *type, Py_ssize_t nitems)
PyObject * _new(PyTypeObject *type, Py_ssize_t nitems)