[230f479] | 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 | */ |
---|
| 24 | #define NO_IMPORT_ARRAY |
---|
| 25 | #define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans |
---|
| 26 | |
---|
| 27 | extern "C" { |
---|
| 28 | #include <Python.h> |
---|
| 29 | #include <arrayobject.h> |
---|
| 30 | #include "structmember.h" |
---|
| 31 | #include <stdio.h> |
---|
| 32 | #include <stdlib.h> |
---|
| 33 | #include <math.h> |
---|
| 34 | #include <time.h> |
---|
| 35 | [C_INCLUDE_FILE] |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | [CPP_INCLUDE_FILE] |
---|
| 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 | Py_DECREF(self->params); |
---|
| 63 | Py_DECREF(self->dispersion); |
---|
| 64 | Py_DECREF(self->log); |
---|
| 65 | delete self->model; |
---|
| 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 | |
---|
| 89 | [INITIALIZE_MODEL] |
---|
| 90 | |
---|
| 91 | [INITDICTIONARY] |
---|
| 92 | |
---|
| 93 | // Create empty log |
---|
| 94 | self->log = PyDict_New(); |
---|
| 95 | |
---|
| 96 | [NUMERICAL_INIT] |
---|
| 97 | } |
---|
| 98 | return 0; |
---|
| 99 | } |
---|
| 100 | |
---|
| 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 | |
---|
| 108 | static PyMemberDef [PYTHONCLASS]_members[] = { |
---|
| 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}, |
---|
| 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 | } |
---|
| 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 | } |
---|
| 146 | result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), 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 | #pragma omp parallel for |
---|
| 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 | } |
---|
| 160 | |
---|
| 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; |
---|
| 170 | int x_len, y_len, dims[1]; |
---|
| 171 | //check validity of input vectors |
---|
| 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]){ |
---|
| 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)) { |
---|
| 181 | |
---|
| 182 | x_len = dims[0]= x->dimensions[0]; |
---|
| 183 | y_len = dims[0]= y->dimensions[0]; |
---|
| 184 | |
---|
| 185 | // Make a new double matrix of same dims |
---|
| 186 | result=(PyArrayObject *) PyArray_FromDims(1,dims,NPY_DOUBLE); |
---|
| 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. */ |
---|
| 194 | #pragma omp parallel for |
---|
| 195 | for (int i=0; i< x_len; i++) { |
---|
| 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 | } |
---|
| 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 | } |
---|
| 265 | PyErr_SetString([PYTHONCLASS]Error, |
---|
| 266 | "[PYTHONCLASS].evalDistribution couln't be run."); |
---|
| 267 | return NULL; |
---|
| 268 | |
---|
| 269 | } |
---|
| 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) |
---|
| 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 | |
---|
| 312 | } else { |
---|
| 313 | |
---|
| 314 | // We have a scalar q, we will evaluate I(q) |
---|
| 315 | q_value = [PYTHONCLASS]_readDouble(pars); |
---|
| 316 | |
---|
| 317 | return Py_BuildValue("d",(*(self->model))(q_value)); |
---|
| 318 | } |
---|
| 319 | } |
---|
| 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()); |
---|
| 331 | |
---|
| 332 | } |
---|
| 333 | /** |
---|
| 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 | /** |
---|
| 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) |
---|
| 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)); |
---|
| 382 | |
---|
| 383 | } else { |
---|
| 384 | |
---|
| 385 | // We have a scalar q, we will evaluate I(q) |
---|
| 386 | qx_value = [PYTHONCLASS]_readDouble(pars); |
---|
| 387 | |
---|
| 388 | return Py_BuildValue("d",(*(self->model))(qx_value)); |
---|
| 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"}, |
---|
| 430 | {"calculate_ER", (PyCFunction)calculate_ER , METH_VARARGS, |
---|
| 431 | "Evaluate the model at a given Q or Q, phi"}, |
---|
| 432 | {"calculate_VR", (PyCFunction)calculate_VR , METH_VARARGS, |
---|
| 433 | "Evaluate VR"}, |
---|
| 434 | {"evalDistribution", (PyCFunction)evalDistribution , METH_VARARGS, |
---|
| 435 | "Evaluate the model at a given Q or Qx, Qy vector "}, |
---|
| 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 | |
---|
| 486 | //static PyMethodDef module_methods[] = { |
---|
| 487 | // {NULL} |
---|
| 488 | //}; |
---|
| 489 | |
---|
| 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); |
---|
| 504 | static char error_name[] = "[PYTHONCLASS].error"; |
---|
| 505 | [PYTHONCLASS]Error = PyErr_NewException(error_name, NULL, NULL); |
---|
| 506 | PyDict_SetItemString(d, "[PYTHONCLASS]Error", [PYTHONCLASS]Error); |
---|
| 507 | } |
---|