source: sasview/sansmodels/src/sans/models/c_models/CPearlNecklaceModel.cpp @ 0438933

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 0438933 was 2605da22, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Re #4 Still a few more warnings

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