[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 | } |
---|
| 151 | /** |
---|
| 152 | * Function to call to evaluate model |
---|
| 153 | * @param args: input numpy array [q[],phi[]] |
---|
| 154 | * @return: numpy array object |
---|
| 155 | */ |
---|
| 156 | static PyObject * evaluateTwoDim( [CMODEL]* model, |
---|
| 157 | PyArrayObject *q, PyArrayObject *phi) |
---|
| 158 | { |
---|
| 159 | PyArrayObject *result; |
---|
| 160 | //check validity of input vectors |
---|
| 161 | if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE |
---|
| 162 | || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE |
---|
| 163 | || phi->dimensions[0] != q->dimensions[0]){ |
---|
| 164 | |
---|
| 165 | //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; |
---|
| 166 | PyErr_SetString(PyExc_ValueError ,"wrong input"); |
---|
| 167 | return NULL; |
---|
| 168 | } |
---|
| 169 | result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); |
---|
[af03ddd] | 170 | |
---|
[8344c50] | 171 | if (result == NULL){ |
---|
| 172 | const char * message= "Could not create result "; |
---|
| 173 | PyErr_SetString(PyExc_RuntimeError , message); |
---|
| 174 | return NULL; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | for (int i = 0; i < q->dimensions[0]; i++) { |
---|
| 178 | double q_value = *(double *)(q->data + i*q->strides[0]); |
---|
| 179 | double phi_value = *(double *)(phi->data + i*phi->strides[0]); |
---|
| 180 | double *result_value = (double *)(result->data + i*result->strides[0]); |
---|
| 181 | if (q_value == 0) |
---|
| 182 | *result_value = 0.0; |
---|
| 183 | else |
---|
| 184 | *result_value = model->evaluate_rphi(q_value, phi_value); |
---|
| 185 | } |
---|
| 186 | return PyArray_Return(result); |
---|
| 187 | } |
---|
| 188 | /** |
---|
| 189 | * Function to call to evaluate model |
---|
| 190 | * @param args: input numpy array [x[],y[]] |
---|
| 191 | * @return: numpy array object |
---|
| 192 | */ |
---|
| 193 | static PyObject * evaluateTwoDimXY( [CMODEL]* model, |
---|
| 194 | PyArrayObject *x, PyArrayObject *y) |
---|
| 195 | { |
---|
| 196 | PyArrayObject *result; |
---|
| 197 | int i,j, x_len, y_len, dims[2]; |
---|
| 198 | //check validity of input vectors |
---|
| 199 | if (x->nd != 2 || x->descr->type_num != PyArray_DOUBLE |
---|
| 200 | || y->nd != 2 || y->descr->type_num != PyArray_DOUBLE |
---|
| 201 | || y->dimensions[1] != x->dimensions[0]){ |
---|
| 202 | const char * message= "evaluateTwoDimXY expect 2 numpy arrays"; |
---|
| 203 | PyErr_SetString(PyExc_ValueError , message); |
---|
| 204 | return NULL; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | if (PyArray_Check(x) && PyArray_Check(y)) { |
---|
| 208 | x_len = dims[0]= x->dimensions[0]; |
---|
| 209 | y_len = dims[1]= y->dimensions[1]; |
---|
| 210 | |
---|
| 211 | // Make a new double matrix of same dims |
---|
| 212 | result=(PyArrayObject *) PyArray_FromDims(2,dims,NPY_DOUBLE); |
---|
| 213 | if (result == NULL){ |
---|
| 214 | const char * message= "Could not create result "; |
---|
| 215 | PyErr_SetString(PyExc_RuntimeError , message); |
---|
| 216 | return NULL; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | /* Do the calculation. */ |
---|
| 220 | for ( i=0; i< x_len; i++) { |
---|
| 221 | for ( j=0; j< y_len; j++) { |
---|
| 222 | double x_value = *(double *)(x->data + i*x->strides[0]); |
---|
| 223 | double y_value = *(double *)(y->data + j*y->strides[1]); |
---|
| 224 | double *result_value = (double *)(result->data + |
---|
| 225 | i*result->strides[0] + j*result->strides[1]); |
---|
| 226 | *result_value = (*model)(x_value, y_value); |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | return PyArray_Return(result); |
---|
| 230 | |
---|
| 231 | }else{ |
---|
| 232 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 233 | "[PYTHONCLASS].evaluateTwoDimXY couldn't run."); |
---|
| 234 | return NULL; |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | /** |
---|
| 238 | * evalDistribution function evaluate a model function with input vector |
---|
| 239 | * @param args: input q as vector or [qx, qy] where qx, qy are vectors |
---|
| 240 | * |
---|
| 241 | */ |
---|
| 242 | static PyObject * evalDistribution([PYTHONCLASS] *self, PyObject *args){ |
---|
| 243 | PyObject *qx, *qy; |
---|
| 244 | PyArrayObject * pars; |
---|
| 245 | int npars ,mpars; |
---|
| 246 | |
---|
| 247 | // Get parameters |
---|
| 248 | |
---|
| 249 | [READDICTIONARY] |
---|
| 250 | |
---|
| 251 | // Get input and determine whether we have to supply a 1D or 2D return value. |
---|
| 252 | if ( !PyArg_ParseTuple(args,"O",&pars) ) { |
---|
| 253 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 254 | "[PYTHONCLASS].evalDistribution expects a q value."); |
---|
| 255 | return NULL; |
---|
| 256 | } |
---|
| 257 | // Check params |
---|
| 258 | |
---|
| 259 | if(PyArray_Check(pars)==1) { |
---|
| 260 | |
---|
| 261 | // Length of list should 1 or 2 |
---|
| 262 | npars = pars->nd; |
---|
| 263 | if(npars==1) { |
---|
| 264 | // input is a numpy array |
---|
| 265 | if (PyArray_Check(pars)) { |
---|
| 266 | return evaluateOneDim(self->model, (PyArrayObject*)pars); |
---|
| 267 | } |
---|
| 268 | }else{ |
---|
| 269 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 270 | "[PYTHONCLASS].evalDistribution expect numpy array of one dimension."); |
---|
| 271 | return NULL; |
---|
| 272 | } |
---|
| 273 | }else if( PyList_Check(pars)==1) { |
---|
| 274 | // Length of list should be 2 for I(qx,qy) |
---|
| 275 | mpars = PyList_GET_SIZE(pars); |
---|
| 276 | if(mpars!=2) { |
---|
| 277 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 278 | "[PYTHONCLASS].evalDistribution expects a list of dimension 2."); |
---|
| 279 | return NULL; |
---|
| 280 | } |
---|
| 281 | qx = PyList_GET_ITEM(pars,0); |
---|
| 282 | qy = PyList_GET_ITEM(pars,1); |
---|
| 283 | if (PyArray_Check(qx) && PyArray_Check(qy)) { |
---|
| 284 | return evaluateTwoDimXY(self->model, (PyArrayObject*)qx, |
---|
| 285 | (PyArrayObject*)qy); |
---|
| 286 | }else{ |
---|
| 287 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 288 | "[PYTHONCLASS].evalDistribution expect 2 numpy arrays in list."); |
---|
| 289 | return NULL; |
---|
| 290 | } |
---|
| 291 | }else{ |
---|
| 292 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 293 | "[PYTHONCLASS].evalDistribution couln't be run."); |
---|
| 294 | return NULL; |
---|
| 295 | } |
---|
| 296 | } |
---|
[af03ddd] | 297 | |
---|
| 298 | /** |
---|
| 299 | * Function to call to evaluate model |
---|
| 300 | * @param args: input q or [q,phi] |
---|
| 301 | * @return: function value |
---|
| 302 | */ |
---|
| 303 | static PyObject * run([PYTHONCLASS] *self, PyObject *args) { |
---|
| 304 | double q_value, phi_value; |
---|
| 305 | PyObject* pars; |
---|
| 306 | int npars; |
---|
| 307 | |
---|
| 308 | // Get parameters |
---|
| 309 | |
---|
| 310 | [READDICTIONARY] |
---|
| 311 | |
---|
| 312 | // Get input and determine whether we have to supply a 1D or 2D return value. |
---|
| 313 | if ( !PyArg_ParseTuple(args,"O",&pars) ) { |
---|
| 314 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 315 | "[PYTHONCLASS].run expects a q value."); |
---|
| 316 | return NULL; |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | // Check params |
---|
| 320 | if( PyList_Check(pars)==1) { |
---|
| 321 | |
---|
| 322 | // Length of list should be 2 for I(q,phi) |
---|
| 323 | npars = PyList_GET_SIZE(pars); |
---|
| 324 | if(npars!=2) { |
---|
| 325 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 326 | "[PYTHONCLASS].run expects a double or a list of dimension 2."); |
---|
| 327 | return NULL; |
---|
| 328 | } |
---|
| 329 | // We have a vector q, get the q and phi values at which |
---|
| 330 | // to evaluate I(q,phi) |
---|
[4176435] | 331 | q_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0)); |
---|
| 332 | phi_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1)); |
---|
| 333 | // Skip zero |
---|
| 334 | if (q_value==0) { |
---|
| 335 | return Py_BuildValue("d",0.0); |
---|
| 336 | } |
---|
| 337 | return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value)); |
---|
| 338 | |
---|
[af03ddd] | 339 | } else { |
---|
[4176435] | 340 | |
---|
| 341 | // We have a scalar q, we will evaluate I(q) |
---|
[af03ddd] | 342 | q_value = [PYTHONCLASS]_readDouble(pars); |
---|
[4176435] | 343 | |
---|
| 344 | return Py_BuildValue("d",(*(self->model))(q_value)); |
---|
| 345 | } |
---|
[af03ddd] | 346 | } |
---|
| 347 | |
---|
| 348 | /** |
---|
| 349 | * Function to call to evaluate model in cartesian coordinates |
---|
| 350 | * @param args: input q or [qx, qy]] |
---|
| 351 | * @return: function value |
---|
| 352 | */ |
---|
| 353 | static PyObject * runXY([PYTHONCLASS] *self, PyObject *args) { |
---|
| 354 | double qx_value, qy_value; |
---|
| 355 | PyObject* pars; |
---|
| 356 | int npars; |
---|
| 357 | |
---|
| 358 | // Get parameters |
---|
| 359 | |
---|
| 360 | [READDICTIONARY] |
---|
| 361 | |
---|
| 362 | // Get input and determine whether we have to supply a 1D or 2D return value. |
---|
| 363 | if ( !PyArg_ParseTuple(args,"O",&pars) ) { |
---|
| 364 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 365 | "[PYTHONCLASS].run expects a q value."); |
---|
| 366 | return NULL; |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | // Check params |
---|
| 370 | if( PyList_Check(pars)==1) { |
---|
| 371 | |
---|
| 372 | // Length of list should be 2 for I(qx, qy)) |
---|
| 373 | npars = PyList_GET_SIZE(pars); |
---|
| 374 | if(npars!=2) { |
---|
| 375 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 376 | "[PYTHONCLASS].run expects a double or a list of dimension 2."); |
---|
| 377 | return NULL; |
---|
| 378 | } |
---|
| 379 | // We have a vector q, get the qx and qy values at which |
---|
| 380 | // to evaluate I(qx,qy) |
---|
[4176435] | 381 | qx_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0)); |
---|
| 382 | qy_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1)); |
---|
| 383 | return Py_BuildValue("d",(*(self->model))(qx_value,qy_value)); |
---|
[af03ddd] | 384 | |
---|
| 385 | } else { |
---|
[4176435] | 386 | |
---|
| 387 | // We have a scalar q, we will evaluate I(q) |
---|
| 388 | qx_value = [PYTHONCLASS]_readDouble(pars); |
---|
[af03ddd] | 389 | |
---|
[4176435] | 390 | return Py_BuildValue("d",(*(self->model))(qx_value)); |
---|
[af03ddd] | 391 | } |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | static PyObject * reset([PYTHONCLASS] *self, PyObject *args) { |
---|
| 395 | [NUMERICAL_RESET] |
---|
| 396 | return Py_BuildValue("d",0.0); |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | static PyObject * set_dispersion([PYTHONCLASS] *self, PyObject *args) { |
---|
| 400 | PyObject * disp; |
---|
| 401 | const char * par_name; |
---|
| 402 | |
---|
| 403 | if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) { |
---|
| 404 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 405 | "[PYTHONCLASS].set_dispersion expects a DispersionModel object."); |
---|
| 406 | return NULL; |
---|
| 407 | } |
---|
| 408 | void *temp = PyCObject_AsVoidPtr(disp); |
---|
| 409 | DispersionModel * dispersion = static_cast<DispersionModel *>(temp); |
---|
| 410 | |
---|
| 411 | |
---|
| 412 | // Ugliness necessary to go from python to C |
---|
| 413 | [SET_DISPERSION] { |
---|
| 414 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 415 | "[PYTHONCLASS].set_dispersion expects a valid parameter name."); |
---|
| 416 | return NULL; |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | DispersionVisitor* visitor = new DispersionVisitor(); |
---|
| 420 | PyObject * disp_dict = PyDict_New(); |
---|
| 421 | dispersion->accept_as_source(visitor, dispersion, disp_dict); |
---|
| 422 | PyDict_SetItemString(self->dispersion, par_name, disp_dict); |
---|
| 423 | return Py_BuildValue("i",1); |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | |
---|
| 427 | static PyMethodDef [PYTHONCLASS]_methods[] = { |
---|
| 428 | {"run", (PyCFunction)run , METH_VARARGS, |
---|
| 429 | "Evaluate the model at a given Q or Q, phi"}, |
---|
| 430 | {"runXY", (PyCFunction)runXY , METH_VARARGS, |
---|
| 431 | "Evaluate the model at a given Q or Qx, Qy"}, |
---|
[8344c50] | 432 | |
---|
| 433 | {"evalDistribution", (PyCFunction)evalDistribution , METH_VARARGS, |
---|
| 434 | "Evaluate the model at a given Q or Qx, Qy vector "}, |
---|
[af03ddd] | 435 | {"reset", (PyCFunction)reset , METH_VARARGS, |
---|
| 436 | "Reset pair correlation"}, |
---|
| 437 | {"set_dispersion", (PyCFunction)set_dispersion , METH_VARARGS, |
---|
| 438 | "Set the dispersion model for a given parameter"}, |
---|
| 439 | {NULL} |
---|
| 440 | }; |
---|
| 441 | |
---|
| 442 | static PyTypeObject [PYTHONCLASS]Type = { |
---|
| 443 | PyObject_HEAD_INIT(NULL) |
---|
| 444 | 0, /*ob_size*/ |
---|
| 445 | "[PYTHONCLASS]", /*tp_name*/ |
---|
| 446 | sizeof([PYTHONCLASS]), /*tp_basicsize*/ |
---|
| 447 | 0, /*tp_itemsize*/ |
---|
| 448 | (destructor)[PYTHONCLASS]_dealloc, /*tp_dealloc*/ |
---|
| 449 | 0, /*tp_print*/ |
---|
| 450 | 0, /*tp_getattr*/ |
---|
| 451 | 0, /*tp_setattr*/ |
---|
| 452 | 0, /*tp_compare*/ |
---|
| 453 | 0, /*tp_repr*/ |
---|
| 454 | 0, /*tp_as_number*/ |
---|
| 455 | 0, /*tp_as_sequence*/ |
---|
| 456 | 0, /*tp_as_mapping*/ |
---|
| 457 | 0, /*tp_hash */ |
---|
| 458 | 0, /*tp_call*/ |
---|
| 459 | 0, /*tp_str*/ |
---|
| 460 | 0, /*tp_getattro*/ |
---|
| 461 | 0, /*tp_setattro*/ |
---|
| 462 | 0, /*tp_as_buffer*/ |
---|
| 463 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
---|
| 464 | "[PYTHONCLASS] objects", /* tp_doc */ |
---|
| 465 | 0, /* tp_traverse */ |
---|
| 466 | 0, /* tp_clear */ |
---|
| 467 | 0, /* tp_richcompare */ |
---|
| 468 | 0, /* tp_weaklistoffset */ |
---|
| 469 | 0, /* tp_iter */ |
---|
| 470 | 0, /* tp_iternext */ |
---|
| 471 | [PYTHONCLASS]_methods, /* tp_methods */ |
---|
| 472 | [PYTHONCLASS]_members, /* tp_members */ |
---|
| 473 | 0, /* tp_getset */ |
---|
| 474 | 0, /* tp_base */ |
---|
| 475 | 0, /* tp_dict */ |
---|
| 476 | 0, /* tp_descr_get */ |
---|
| 477 | 0, /* tp_descr_set */ |
---|
| 478 | 0, /* tp_dictoffset */ |
---|
| 479 | (initproc)[PYTHONCLASS]_init, /* tp_init */ |
---|
| 480 | 0, /* tp_alloc */ |
---|
| 481 | [PYTHONCLASS]_new, /* tp_new */ |
---|
| 482 | }; |
---|
| 483 | |
---|
| 484 | |
---|
[8344c50] | 485 | //static PyMethodDef module_methods[] = { |
---|
| 486 | // {NULL} |
---|
| 487 | //}; |
---|
[4176435] | 488 | |
---|
[af03ddd] | 489 | /** |
---|
| 490 | * Function used to add the model class to a module |
---|
| 491 | * @param module: module to add the class to |
---|
| 492 | */ |
---|
| 493 | void add[PYTHONCLASS](PyObject *module) { |
---|
| 494 | PyObject *d; |
---|
| 495 | |
---|
| 496 | if (PyType_Ready(&[PYTHONCLASS]Type) < 0) |
---|
| 497 | return; |
---|
| 498 | |
---|
| 499 | Py_INCREF(&[PYTHONCLASS]Type); |
---|
| 500 | PyModule_AddObject(module, "[PYTHONCLASS]", (PyObject *)&[PYTHONCLASS]Type); |
---|
| 501 | |
---|
| 502 | d = PyModule_GetDict(module); |
---|
| 503 | [PYTHONCLASS]Error = PyErr_NewException("[PYTHONCLASS].error", NULL, NULL); |
---|
| 504 | PyDict_SetItemString(d, "[PYTHONCLASS]Error", [PYTHONCLASS]Error); |
---|
| 505 | } |
---|