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