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