source: sasview/sansmodels/src/sans/models/c_models/CBinaryHSModel.cpp @ 00c2141

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 00c2141 was 00c2141, checked in by Mathieu Doucet <doucetm@…>, 12 years ago

Re #4 Fixing a few more warnings

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