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