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