[af03ddd] | 1 | /** |
---|
| 2 | This software was developed by the University of Tennessee as part of the |
---|
| 3 | Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
| 4 | project funded by the US National Science Foundation. |
---|
| 5 | |
---|
| 6 | If you use DANSE applications to do scientific research that leads to |
---|
| 7 | publication, we ask that you acknowledge the use of the software with the |
---|
| 8 | following sentence: |
---|
| 9 | |
---|
| 10 | "This work benefited from DANSE software developed under NSF award DMR-0520547." |
---|
| 11 | |
---|
| 12 | copyright 2008, University of Tennessee |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | /** [PYTHONCLASS] |
---|
| 16 | * |
---|
| 17 | * C extension |
---|
| 18 | * |
---|
| 19 | * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY |
---|
| 20 | * DO NOT MODIFY THIS FILE, MODIFY [INCLUDE_FILE] |
---|
| 21 | * AND RE-RUN THE GENERATOR SCRIPT |
---|
| 22 | * |
---|
| 23 | */ |
---|
[8344c50] | 24 | #define NO_IMPORT_ARRAY |
---|
| 25 | #define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans |
---|
[af03ddd] | 26 | |
---|
| 27 | extern "C" { |
---|
| 28 | #include <Python.h> |
---|
[8344c50] | 29 | #include <arrayobject.h> |
---|
[af03ddd] | 30 | #include "structmember.h" |
---|
| 31 | #include <stdio.h> |
---|
| 32 | #include <stdlib.h> |
---|
| 33 | #include <math.h> |
---|
| 34 | #include <time.h> |
---|
| 35 | #include "[INCLUDE_FILE]" |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | #include "models.hh" |
---|
| 39 | #include "dispersion_visitor.hh" |
---|
| 40 | |
---|
| 41 | /// Error object for raised exceptions |
---|
| 42 | static PyObject * [PYTHONCLASS]Error = NULL; |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | // Class definition |
---|
| 46 | typedef struct { |
---|
| 47 | PyObject_HEAD |
---|
| 48 | /// Parameters |
---|
| 49 | PyObject * params; |
---|
| 50 | /// Dispersion parameters |
---|
| 51 | PyObject * dispersion; |
---|
| 52 | /// Underlying model object |
---|
| 53 | [CMODEL] * model; |
---|
| 54 | /// Log for unit testing |
---|
| 55 | PyObject * log; |
---|
| 56 | } [PYTHONCLASS]; |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | static void |
---|
| 60 | [PYTHONCLASS]_dealloc([PYTHONCLASS]* self) |
---|
| 61 | { |
---|
| 62 | self->ob_type->tp_free((PyObject*)self); |
---|
| 63 | [NUMERICAL_DEALLOC] |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | static PyObject * |
---|
| 67 | [PYTHONCLASS]_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
---|
| 68 | { |
---|
| 69 | [PYTHONCLASS] *self; |
---|
| 70 | |
---|
| 71 | self = ([PYTHONCLASS] *)type->tp_alloc(type, 0); |
---|
| 72 | |
---|
| 73 | return (PyObject *)self; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | static int |
---|
| 77 | [PYTHONCLASS]_init([PYTHONCLASS] *self, PyObject *args, PyObject *kwds) |
---|
| 78 | { |
---|
| 79 | if (self != NULL) { |
---|
| 80 | |
---|
| 81 | // Create parameters |
---|
| 82 | self->params = PyDict_New(); |
---|
| 83 | self->dispersion = PyDict_New(); |
---|
| 84 | self->model = new [CMODEL](); |
---|
| 85 | |
---|
| 86 | [INITDICTIONARY] |
---|
| 87 | |
---|
| 88 | // Create empty log |
---|
| 89 | self->log = PyDict_New(); |
---|
| 90 | |
---|
| 91 | [NUMERICAL_INIT] |
---|
| 92 | } |
---|
| 93 | return 0; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | static PyMemberDef [PYTHONCLASS]_members[] = { |
---|
| 97 | {"params", T_OBJECT, offsetof([PYTHONCLASS], params), 0, |
---|
| 98 | "Parameters"}, |
---|
| 99 | {"dispersion", T_OBJECT, offsetof([PYTHONCLASS], dispersion), 0, |
---|
| 100 | "Dispersion parameters"}, |
---|
| 101 | {"log", T_OBJECT, offsetof([PYTHONCLASS], log), 0, |
---|
| 102 | "Log"}, |
---|
| 103 | {NULL} /* Sentinel */ |
---|
| 104 | }; |
---|
| 105 | |
---|
| 106 | /** Read double from PyObject |
---|
| 107 | @param p PyObject |
---|
| 108 | @return double |
---|
| 109 | */ |
---|
| 110 | double [PYTHONCLASS]_readDouble(PyObject *p) { |
---|
| 111 | if (PyFloat_Check(p)==1) { |
---|
| 112 | return (double)(((PyFloatObject *)(p))->ob_fval); |
---|
| 113 | } else if (PyInt_Check(p)==1) { |
---|
| 114 | return (double)(((PyIntObject *)(p))->ob_ival); |
---|
| 115 | } else if (PyLong_Check(p)==1) { |
---|
| 116 | return (double)PyLong_AsLong(p); |
---|
| 117 | } else { |
---|
| 118 | return 0.0; |
---|
| 119 | } |
---|
| 120 | } |
---|
[8344c50] | 121 | /** |
---|
| 122 | * Function to call to evaluate model |
---|
| 123 | * @param args: input numpy array q[] |
---|
| 124 | * @return: numpy array object |
---|
| 125 | */ |
---|
| 126 | |
---|
| 127 | static PyObject *evaluateOneDim([CMODEL]* model, PyArrayObject *q){ |
---|
| 128 | PyArrayObject *result; |
---|
| 129 | |
---|
| 130 | // Check validity of array q , q must be of dimension 1, an array of double |
---|
| 131 | if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE) |
---|
| 132 | { |
---|
| 133 | //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; |
---|
| 134 | //PyErr_SetString(PyExc_ValueError , message); |
---|
| 135 | return NULL; |
---|
| 136 | } |
---|
| 137 | result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), |
---|
| 138 | PyArray_DOUBLE); |
---|
| 139 | if (result == NULL) { |
---|
| 140 | const char * message= "Could not create result "; |
---|
| 141 | PyErr_SetString(PyExc_RuntimeError , message); |
---|
| 142 | return NULL; |
---|
| 143 | } |
---|
| 144 | for (int i = 0; i < q->dimensions[0]; i++){ |
---|
| 145 | double q_value = *(double *)(q->data + i*q->strides[0]); |
---|
| 146 | double *result_value = (double *)(result->data + i*result->strides[0]); |
---|
| 147 | *result_value =(*model)(q_value); |
---|
| 148 | } |
---|
| 149 | return PyArray_Return(result); |
---|
| 150 | } |
---|
[af03ddd] | 151 | |
---|
[8344c50] | 152 | /** |
---|
| 153 | * Function to call to evaluate model |
---|
| 154 | * @param args: input numpy array [x[],y[]] |
---|
| 155 | * @return: numpy array object |
---|
| 156 | */ |
---|
| 157 | static PyObject * evaluateTwoDimXY( [CMODEL]* model, |
---|
| 158 | PyArrayObject *x, PyArrayObject *y) |
---|
| 159 | { |
---|
| 160 | PyArrayObject *result; |
---|
| 161 | int i,j, x_len, y_len, dims[2]; |
---|
| 162 | //check validity of input vectors |
---|
| 163 | if (x->nd != 2 || x->descr->type_num != PyArray_DOUBLE |
---|
| 164 | || y->nd != 2 || y->descr->type_num != PyArray_DOUBLE |
---|
| 165 | || y->dimensions[1] != x->dimensions[0]){ |
---|
| 166 | const char * message= "evaluateTwoDimXY expect 2 numpy arrays"; |
---|
| 167 | PyErr_SetString(PyExc_ValueError , message); |
---|
| 168 | return NULL; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | if (PyArray_Check(x) && PyArray_Check(y)) { |
---|
[a8d6888] | 172 | |
---|
| 173 | x_len = dims[1]= x->dimensions[1]; |
---|
| 174 | y_len = dims[0]= y->dimensions[0]; |
---|
[8344c50] | 175 | |
---|
| 176 | // Make a new double matrix of same dims |
---|
| 177 | result=(PyArrayObject *) PyArray_FromDims(2,dims,NPY_DOUBLE); |
---|
| 178 | if (result == NULL){ |
---|
| 179 | const char * message= "Could not create result "; |
---|
| 180 | PyErr_SetString(PyExc_RuntimeError , message); |
---|
| 181 | return NULL; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | /* Do the calculation. */ |
---|
[e0a8a3c] | 185 | for ( j=0; j< y_len; j++) { |
---|
| 186 | for ( i=0; i< x_len; i++) { |
---|
[a8d6888] | 187 | double x_value = *(double *)(x->data + i*x->strides[1]); |
---|
| 188 | double y_value = *(double *)(y->data + j*y->strides[0]); |
---|
[8344c50] | 189 | double *result_value = (double *)(result->data + |
---|
[a8d6888] | 190 | i*result->strides[1] + j*result->strides[0]); |
---|
[8344c50] | 191 | *result_value = (*model)(x_value, y_value); |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | return PyArray_Return(result); |
---|
| 195 | |
---|
| 196 | }else{ |
---|
| 197 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 198 | "[PYTHONCLASS].evaluateTwoDimXY couldn't run."); |
---|
| 199 | return NULL; |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | /** |
---|
| 203 | * evalDistribution function evaluate a model function with input vector |
---|
| 204 | * @param args: input q as vector or [qx, qy] where qx, qy are vectors |
---|
| 205 | * |
---|
| 206 | */ |
---|
| 207 | static PyObject * evalDistribution([PYTHONCLASS] *self, PyObject *args){ |
---|
| 208 | PyObject *qx, *qy; |
---|
| 209 | PyArrayObject * pars; |
---|
| 210 | int npars ,mpars; |
---|
| 211 | |
---|
| 212 | // Get parameters |
---|
| 213 | |
---|
| 214 | [READDICTIONARY] |
---|
| 215 | |
---|
| 216 | // Get input and determine whether we have to supply a 1D or 2D return value. |
---|
| 217 | if ( !PyArg_ParseTuple(args,"O",&pars) ) { |
---|
| 218 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 219 | "[PYTHONCLASS].evalDistribution expects a q value."); |
---|
| 220 | return NULL; |
---|
| 221 | } |
---|
| 222 | // Check params |
---|
| 223 | |
---|
| 224 | if(PyArray_Check(pars)==1) { |
---|
| 225 | |
---|
| 226 | // Length of list should 1 or 2 |
---|
| 227 | npars = pars->nd; |
---|
| 228 | if(npars==1) { |
---|
| 229 | // input is a numpy array |
---|
| 230 | if (PyArray_Check(pars)) { |
---|
| 231 | return evaluateOneDim(self->model, (PyArrayObject*)pars); |
---|
| 232 | } |
---|
| 233 | }else{ |
---|
| 234 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 235 | "[PYTHONCLASS].evalDistribution expect numpy array of one dimension."); |
---|
| 236 | return NULL; |
---|
| 237 | } |
---|
| 238 | }else if( PyList_Check(pars)==1) { |
---|
| 239 | // Length of list should be 2 for I(qx,qy) |
---|
| 240 | mpars = PyList_GET_SIZE(pars); |
---|
| 241 | if(mpars!=2) { |
---|
| 242 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 243 | "[PYTHONCLASS].evalDistribution expects a list of dimension 2."); |
---|
| 244 | return NULL; |
---|
| 245 | } |
---|
| 246 | qx = PyList_GET_ITEM(pars,0); |
---|
| 247 | qy = PyList_GET_ITEM(pars,1); |
---|
| 248 | if (PyArray_Check(qx) && PyArray_Check(qy)) { |
---|
| 249 | return evaluateTwoDimXY(self->model, (PyArrayObject*)qx, |
---|
| 250 | (PyArrayObject*)qy); |
---|
| 251 | }else{ |
---|
| 252 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 253 | "[PYTHONCLASS].evalDistribution expect 2 numpy arrays in list."); |
---|
| 254 | return NULL; |
---|
| 255 | } |
---|
| 256 | } |
---|
[e0a8a3c] | 257 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 258 | "[PYTHONCLASS].evalDistribution couln't be run."); |
---|
| 259 | return NULL; |
---|
| 260 | |
---|
[8344c50] | 261 | } |
---|
[af03ddd] | 262 | |
---|
| 263 | /** |
---|
| 264 | * Function to call to evaluate model |
---|
| 265 | * @param args: input q or [q,phi] |
---|
| 266 | * @return: function value |
---|
| 267 | */ |
---|
| 268 | static PyObject * run([PYTHONCLASS] *self, PyObject *args) { |
---|
| 269 | double q_value, phi_value; |
---|
| 270 | PyObject* pars; |
---|
| 271 | int npars; |
---|
| 272 | |
---|
| 273 | // Get parameters |
---|
| 274 | |
---|
| 275 | [READDICTIONARY] |
---|
| 276 | |
---|
| 277 | // Get input and determine whether we have to supply a 1D or 2D return value. |
---|
| 278 | if ( !PyArg_ParseTuple(args,"O",&pars) ) { |
---|
| 279 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 280 | "[PYTHONCLASS].run expects a q value."); |
---|
| 281 | return NULL; |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | // Check params |
---|
| 285 | if( PyList_Check(pars)==1) { |
---|
| 286 | |
---|
| 287 | // Length of list should be 2 for I(q,phi) |
---|
| 288 | npars = PyList_GET_SIZE(pars); |
---|
| 289 | if(npars!=2) { |
---|
| 290 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 291 | "[PYTHONCLASS].run expects a double or a list of dimension 2."); |
---|
| 292 | return NULL; |
---|
| 293 | } |
---|
| 294 | // We have a vector q, get the q and phi values at which |
---|
| 295 | // to evaluate I(q,phi) |
---|
[4176435] | 296 | q_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0)); |
---|
| 297 | phi_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1)); |
---|
| 298 | // Skip zero |
---|
| 299 | if (q_value==0) { |
---|
| 300 | return Py_BuildValue("d",0.0); |
---|
| 301 | } |
---|
| 302 | return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value)); |
---|
| 303 | |
---|
[af03ddd] | 304 | } else { |
---|
[4176435] | 305 | |
---|
| 306 | // We have a scalar q, we will evaluate I(q) |
---|
[af03ddd] | 307 | q_value = [PYTHONCLASS]_readDouble(pars); |
---|
[4176435] | 308 | |
---|
| 309 | return Py_BuildValue("d",(*(self->model))(q_value)); |
---|
| 310 | } |
---|
[af03ddd] | 311 | } |
---|
| 312 | |
---|
| 313 | /** |
---|
| 314 | * Function to call to evaluate model in cartesian coordinates |
---|
| 315 | * @param args: input q or [qx, qy]] |
---|
| 316 | * @return: function value |
---|
| 317 | */ |
---|
| 318 | static PyObject * runXY([PYTHONCLASS] *self, PyObject *args) { |
---|
| 319 | double qx_value, qy_value; |
---|
| 320 | PyObject* pars; |
---|
| 321 | int npars; |
---|
| 322 | |
---|
| 323 | // Get parameters |
---|
| 324 | |
---|
| 325 | [READDICTIONARY] |
---|
| 326 | |
---|
| 327 | // Get input and determine whether we have to supply a 1D or 2D return value. |
---|
| 328 | if ( !PyArg_ParseTuple(args,"O",&pars) ) { |
---|
| 329 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 330 | "[PYTHONCLASS].run expects a q value."); |
---|
| 331 | return NULL; |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | // Check params |
---|
| 335 | if( PyList_Check(pars)==1) { |
---|
| 336 | |
---|
| 337 | // Length of list should be 2 for I(qx, qy)) |
---|
| 338 | npars = PyList_GET_SIZE(pars); |
---|
| 339 | if(npars!=2) { |
---|
| 340 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 341 | "[PYTHONCLASS].run expects a double or a list of dimension 2."); |
---|
| 342 | return NULL; |
---|
| 343 | } |
---|
| 344 | // We have a vector q, get the qx and qy values at which |
---|
| 345 | // to evaluate I(qx,qy) |
---|
[4176435] | 346 | qx_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0)); |
---|
| 347 | qy_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1)); |
---|
| 348 | return Py_BuildValue("d",(*(self->model))(qx_value,qy_value)); |
---|
[af03ddd] | 349 | |
---|
| 350 | } else { |
---|
[4176435] | 351 | |
---|
| 352 | // We have a scalar q, we will evaluate I(q) |
---|
| 353 | qx_value = [PYTHONCLASS]_readDouble(pars); |
---|
[af03ddd] | 354 | |
---|
[4176435] | 355 | return Py_BuildValue("d",(*(self->model))(qx_value)); |
---|
[af03ddd] | 356 | } |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | static PyObject * reset([PYTHONCLASS] *self, PyObject *args) { |
---|
| 360 | [NUMERICAL_RESET] |
---|
| 361 | return Py_BuildValue("d",0.0); |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | static PyObject * set_dispersion([PYTHONCLASS] *self, PyObject *args) { |
---|
| 365 | PyObject * disp; |
---|
| 366 | const char * par_name; |
---|
| 367 | |
---|
| 368 | if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) { |
---|
| 369 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 370 | "[PYTHONCLASS].set_dispersion expects a DispersionModel object."); |
---|
| 371 | return NULL; |
---|
| 372 | } |
---|
| 373 | void *temp = PyCObject_AsVoidPtr(disp); |
---|
| 374 | DispersionModel * dispersion = static_cast<DispersionModel *>(temp); |
---|
| 375 | |
---|
| 376 | |
---|
| 377 | // Ugliness necessary to go from python to C |
---|
| 378 | [SET_DISPERSION] { |
---|
| 379 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 380 | "[PYTHONCLASS].set_dispersion expects a valid parameter name."); |
---|
| 381 | return NULL; |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | DispersionVisitor* visitor = new DispersionVisitor(); |
---|
| 385 | PyObject * disp_dict = PyDict_New(); |
---|
| 386 | dispersion->accept_as_source(visitor, dispersion, disp_dict); |
---|
| 387 | PyDict_SetItemString(self->dispersion, par_name, disp_dict); |
---|
| 388 | return Py_BuildValue("i",1); |
---|
| 389 | } |
---|
| 390 | |
---|
| 391 | |
---|
| 392 | static PyMethodDef [PYTHONCLASS]_methods[] = { |
---|
| 393 | {"run", (PyCFunction)run , METH_VARARGS, |
---|
| 394 | "Evaluate the model at a given Q or Q, phi"}, |
---|
| 395 | {"runXY", (PyCFunction)runXY , METH_VARARGS, |
---|
| 396 | "Evaluate the model at a given Q or Qx, Qy"}, |
---|
[8344c50] | 397 | |
---|
| 398 | {"evalDistribution", (PyCFunction)evalDistribution , METH_VARARGS, |
---|
| 399 | "Evaluate the model at a given Q or Qx, Qy vector "}, |
---|
[af03ddd] | 400 | {"reset", (PyCFunction)reset , METH_VARARGS, |
---|
| 401 | "Reset pair correlation"}, |
---|
| 402 | {"set_dispersion", (PyCFunction)set_dispersion , METH_VARARGS, |
---|
| 403 | "Set the dispersion model for a given parameter"}, |
---|
| 404 | {NULL} |
---|
| 405 | }; |
---|
| 406 | |
---|
| 407 | static PyTypeObject [PYTHONCLASS]Type = { |
---|
| 408 | PyObject_HEAD_INIT(NULL) |
---|
| 409 | 0, /*ob_size*/ |
---|
| 410 | "[PYTHONCLASS]", /*tp_name*/ |
---|
| 411 | sizeof([PYTHONCLASS]), /*tp_basicsize*/ |
---|
| 412 | 0, /*tp_itemsize*/ |
---|
| 413 | (destructor)[PYTHONCLASS]_dealloc, /*tp_dealloc*/ |
---|
| 414 | 0, /*tp_print*/ |
---|
| 415 | 0, /*tp_getattr*/ |
---|
| 416 | 0, /*tp_setattr*/ |
---|
| 417 | 0, /*tp_compare*/ |
---|
| 418 | 0, /*tp_repr*/ |
---|
| 419 | 0, /*tp_as_number*/ |
---|
| 420 | 0, /*tp_as_sequence*/ |
---|
| 421 | 0, /*tp_as_mapping*/ |
---|
| 422 | 0, /*tp_hash */ |
---|
| 423 | 0, /*tp_call*/ |
---|
| 424 | 0, /*tp_str*/ |
---|
| 425 | 0, /*tp_getattro*/ |
---|
| 426 | 0, /*tp_setattro*/ |
---|
| 427 | 0, /*tp_as_buffer*/ |
---|
| 428 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
---|
| 429 | "[PYTHONCLASS] objects", /* tp_doc */ |
---|
| 430 | 0, /* tp_traverse */ |
---|
| 431 | 0, /* tp_clear */ |
---|
| 432 | 0, /* tp_richcompare */ |
---|
| 433 | 0, /* tp_weaklistoffset */ |
---|
| 434 | 0, /* tp_iter */ |
---|
| 435 | 0, /* tp_iternext */ |
---|
| 436 | [PYTHONCLASS]_methods, /* tp_methods */ |
---|
| 437 | [PYTHONCLASS]_members, /* tp_members */ |
---|
| 438 | 0, /* tp_getset */ |
---|
| 439 | 0, /* tp_base */ |
---|
| 440 | 0, /* tp_dict */ |
---|
| 441 | 0, /* tp_descr_get */ |
---|
| 442 | 0, /* tp_descr_set */ |
---|
| 443 | 0, /* tp_dictoffset */ |
---|
| 444 | (initproc)[PYTHONCLASS]_init, /* tp_init */ |
---|
| 445 | 0, /* tp_alloc */ |
---|
| 446 | [PYTHONCLASS]_new, /* tp_new */ |
---|
| 447 | }; |
---|
| 448 | |
---|
| 449 | |
---|
[8344c50] | 450 | //static PyMethodDef module_methods[] = { |
---|
| 451 | // {NULL} |
---|
| 452 | //}; |
---|
[4176435] | 453 | |
---|
[af03ddd] | 454 | /** |
---|
| 455 | * Function used to add the model class to a module |
---|
| 456 | * @param module: module to add the class to |
---|
| 457 | */ |
---|
| 458 | void add[PYTHONCLASS](PyObject *module) { |
---|
| 459 | PyObject *d; |
---|
| 460 | |
---|
| 461 | if (PyType_Ready(&[PYTHONCLASS]Type) < 0) |
---|
| 462 | return; |
---|
| 463 | |
---|
| 464 | Py_INCREF(&[PYTHONCLASS]Type); |
---|
| 465 | PyModule_AddObject(module, "[PYTHONCLASS]", (PyObject *)&[PYTHONCLASS]Type); |
---|
| 466 | |
---|
| 467 | d = PyModule_GetDict(module); |
---|
| 468 | [PYTHONCLASS]Error = PyErr_NewException("[PYTHONCLASS].error", NULL, NULL); |
---|
| 469 | PyDict_SetItemString(d, "[PYTHONCLASS]Error", [PYTHONCLASS]Error); |
---|
| 470 | } |
---|