source: sasview/sansmodels/src/python_wrapper/CBinaryHSModel.cpp @ a1d1b90

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 a1d1b90 was 67424cd, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Reorganizing models in preparation of cpp cleanup

  • Property mode set to 100644
File size: 21.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/** 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), PyArray_DOUBLE);
167        if (result == NULL) {
168        const char * message= "Could not create result ";
169        PyErr_SetString(PyExc_RuntimeError , message);
170                return NULL;
171        }
172#pragma omp parallel for
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 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#pragma omp parallel for
215        for (int 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(CBinaryHSModelError, 
226                   "CBinaryHSModel.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(CBinaryHSModel *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->vol_frac_ls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "vol_frac_ls") );
244    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
245    self->model->vol_frac_ss = PyFloat_AsDouble( PyDict_GetItemString(self->params, "vol_frac_ss") );
246    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
247    self->model->ls_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ls_sld") );
248    self->model->ss_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ss_sld") );
249    self->model->s_radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "s_radius") );
250    self->model->l_radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "l_radius") );
251    // Read in dispersion parameters
252    PyObject* disp_dict;
253    DispersionVisitor* visitor = new DispersionVisitor();
254    disp_dict = PyDict_GetItemString(self->dispersion, "l_radius");
255    self->model->l_radius.dispersion->accept_as_destination(visitor, self->model->l_radius.dispersion, disp_dict);
256    disp_dict = PyDict_GetItemString(self->dispersion, "s_radius");
257    self->model->s_radius.dispersion->accept_as_destination(visitor, self->model->s_radius.dispersion, disp_dict);
258
259       
260        // Get input and determine whether we have to supply a 1D or 2D return value.
261        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
262            PyErr_SetString(CBinaryHSModelError, 
263                "CBinaryHSModel.evalDistribution expects a q value.");
264                return NULL;
265        }
266    // Check params
267       
268    if(PyArray_Check(pars)==1) {
269               
270            // Length of list should 1 or 2
271            npars = pars->nd; 
272            if(npars==1) {
273                // input is a numpy array
274                if (PyArray_Check(pars)) {
275                        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
276                    }
277                }else{
278                    PyErr_SetString(CBinaryHSModelError, 
279                   "CBinaryHSModel.evalDistribution expect numpy array of one dimension.");
280                return NULL;
281                }
282    }else if( PyList_Check(pars)==1) {
283        // Length of list should be 2 for I(qx,qy)
284            mpars = PyList_GET_SIZE(pars); 
285            if(mpars!=2) {
286                PyErr_SetString(CBinaryHSModelError, 
287                        "CBinaryHSModel.evalDistribution expects a list of dimension 2.");
288                return NULL;
289            }
290             qx = PyList_GET_ITEM(pars,0);
291             qy = PyList_GET_ITEM(pars,1);
292             if (PyArray_Check(qx) && PyArray_Check(qy)) {
293                 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
294                           (PyArrayObject*)qy);
295                 }else{
296                    PyErr_SetString(CBinaryHSModelError, 
297                   "CBinaryHSModel.evalDistribution expect 2 numpy arrays in list.");
298                return NULL;
299             }
300        }
301        PyErr_SetString(CBinaryHSModelError, 
302                   "CBinaryHSModel.evalDistribution couln't be run.");
303        return NULL;
304       
305}
306
307/**
308 * Function to call to evaluate model
309 * @param args: input q or [q,phi]
310 * @return: function value
311 */
312static PyObject * run(CBinaryHSModel *self, PyObject *args) {
313        double q_value, phi_value;
314        PyObject* pars;
315        int npars;
316       
317        // Get parameters
318       
319            // Reader parameter dictionary
320    self->model->vol_frac_ls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "vol_frac_ls") );
321    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
322    self->model->vol_frac_ss = PyFloat_AsDouble( PyDict_GetItemString(self->params, "vol_frac_ss") );
323    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
324    self->model->ls_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ls_sld") );
325    self->model->ss_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ss_sld") );
326    self->model->s_radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "s_radius") );
327    self->model->l_radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "l_radius") );
328    // Read in dispersion parameters
329    PyObject* disp_dict;
330    DispersionVisitor* visitor = new DispersionVisitor();
331    disp_dict = PyDict_GetItemString(self->dispersion, "l_radius");
332    self->model->l_radius.dispersion->accept_as_destination(visitor, self->model->l_radius.dispersion, disp_dict);
333    disp_dict = PyDict_GetItemString(self->dispersion, "s_radius");
334    self->model->s_radius.dispersion->accept_as_destination(visitor, self->model->s_radius.dispersion, disp_dict);
335
336       
337        // Get input and determine whether we have to supply a 1D or 2D return value.
338        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
339            PyErr_SetString(CBinaryHSModelError, 
340                "CBinaryHSModel.run expects a q value.");
341                return NULL;
342        }
343         
344        // Check params
345        if( PyList_Check(pars)==1) {
346               
347                // Length of list should be 2 for I(q,phi)
348            npars = PyList_GET_SIZE(pars); 
349            if(npars!=2) {
350                PyErr_SetString(CBinaryHSModelError, 
351                        "CBinaryHSModel.run expects a double or a list of dimension 2.");
352                return NULL;
353            }
354            // We have a vector q, get the q and phi values at which
355            // to evaluate I(q,phi)
356            q_value = CBinaryHSModel_readDouble(PyList_GET_ITEM(pars,0));
357            phi_value = CBinaryHSModel_readDouble(PyList_GET_ITEM(pars,1));
358            // Skip zero
359            if (q_value==0) {
360                return Py_BuildValue("d",0.0);
361            }
362                return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
363
364        } else {
365
366                // We have a scalar q, we will evaluate I(q)
367                q_value = CBinaryHSModel_readDouble(pars);             
368               
369                return Py_BuildValue("d",(*(self->model))(q_value));
370        }       
371}
372/**
373 * Function to call to calculate_ER
374 * @return: effective radius value
375 */
376static PyObject * calculate_ER(CBinaryHSModel *self) {
377
378        // Get parameters
379       
380            // Reader parameter dictionary
381    self->model->vol_frac_ls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "vol_frac_ls") );
382    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
383    self->model->vol_frac_ss = PyFloat_AsDouble( PyDict_GetItemString(self->params, "vol_frac_ss") );
384    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
385    self->model->ls_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ls_sld") );
386    self->model->ss_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ss_sld") );
387    self->model->s_radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "s_radius") );
388    self->model->l_radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "l_radius") );
389    // Read in dispersion parameters
390    PyObject* disp_dict;
391    DispersionVisitor* visitor = new DispersionVisitor();
392    disp_dict = PyDict_GetItemString(self->dispersion, "l_radius");
393    self->model->l_radius.dispersion->accept_as_destination(visitor, self->model->l_radius.dispersion, disp_dict);
394    disp_dict = PyDict_GetItemString(self->dispersion, "s_radius");
395    self->model->s_radius.dispersion->accept_as_destination(visitor, self->model->s_radius.dispersion, disp_dict);
396
397               
398        return Py_BuildValue("d",(*(self->model)).calculate_ER());
399
400}
401/**
402 * Function to call to evaluate model in cartesian coordinates
403 * @param args: input q or [qx, qy]]
404 * @return: function value
405 */
406static PyObject * runXY(CBinaryHSModel *self, PyObject *args) {
407        double qx_value, qy_value;
408        PyObject* pars;
409        int npars;
410       
411        // Get parameters
412       
413            // Reader parameter dictionary
414    self->model->vol_frac_ls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "vol_frac_ls") );
415    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
416    self->model->vol_frac_ss = PyFloat_AsDouble( PyDict_GetItemString(self->params, "vol_frac_ss") );
417    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
418    self->model->ls_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ls_sld") );
419    self->model->ss_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ss_sld") );
420    self->model->s_radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "s_radius") );
421    self->model->l_radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "l_radius") );
422    // Read in dispersion parameters
423    PyObject* disp_dict;
424    DispersionVisitor* visitor = new DispersionVisitor();
425    disp_dict = PyDict_GetItemString(self->dispersion, "l_radius");
426    self->model->l_radius.dispersion->accept_as_destination(visitor, self->model->l_radius.dispersion, disp_dict);
427    disp_dict = PyDict_GetItemString(self->dispersion, "s_radius");
428    self->model->s_radius.dispersion->accept_as_destination(visitor, self->model->s_radius.dispersion, disp_dict);
429
430       
431        // Get input and determine whether we have to supply a 1D or 2D return value.
432        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
433            PyErr_SetString(CBinaryHSModelError, 
434                "CBinaryHSModel.run expects a q value.");
435                return NULL;
436        }
437         
438        // Check params
439        if( PyList_Check(pars)==1) {
440               
441                // Length of list should be 2 for I(qx, qy))
442            npars = PyList_GET_SIZE(pars); 
443            if(npars!=2) {
444                PyErr_SetString(CBinaryHSModelError, 
445                        "CBinaryHSModel.run expects a double or a list of dimension 2.");
446                return NULL;
447            }
448            // We have a vector q, get the qx and qy values at which
449            // to evaluate I(qx,qy)
450            qx_value = CBinaryHSModel_readDouble(PyList_GET_ITEM(pars,0));
451            qy_value = CBinaryHSModel_readDouble(PyList_GET_ITEM(pars,1));
452            return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
453
454        } else {
455
456                // We have a scalar q, we will evaluate I(q)
457                qx_value = CBinaryHSModel_readDouble(pars);             
458               
459                return Py_BuildValue("d",(*(self->model))(qx_value));
460        }       
461}
462
463static PyObject * reset(CBinaryHSModel *self, PyObject *args) {
464   
465
466    return Py_BuildValue("d",0.0);
467}
468
469static PyObject * set_dispersion(CBinaryHSModel *self, PyObject *args) {
470        PyObject * disp;
471        const char * par_name;
472
473        if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
474            PyErr_SetString(CBinaryHSModelError,
475                "CBinaryHSModel.set_dispersion expects a DispersionModel object.");
476                return NULL;
477        }
478        void *temp = PyCObject_AsVoidPtr(disp);
479        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
480
481
482        // Ugliness necessary to go from python to C
483            // TODO: refactor this
484    if (!strcmp(par_name, "l_radius")) {
485        self->model->l_radius.dispersion = dispersion;
486    } else    if (!strcmp(par_name, "s_radius")) {
487        self->model->s_radius.dispersion = dispersion;
488    } else {
489            PyErr_SetString(CBinaryHSModelError,
490                "CBinaryHSModel.set_dispersion expects a valid parameter name.");
491                return NULL;
492        }
493
494        DispersionVisitor* visitor = new DispersionVisitor();
495        PyObject * disp_dict = PyDict_New();
496        dispersion->accept_as_source(visitor, dispersion, disp_dict);
497        PyDict_SetItemString(self->dispersion, par_name, disp_dict);
498    return Py_BuildValue("i",1);
499}
500
501
502static PyMethodDef CBinaryHSModel_methods[] = {
503    {"run",      (PyCFunction)run     , METH_VARARGS,
504      "Evaluate the model at a given Q or Q, phi"},
505    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
506      "Evaluate the model at a given Q or Qx, Qy"},
507    {"calculate_ER",      (PyCFunction)calculate_ER     , METH_VARARGS,
508      "Evaluate the model at a given Q or Q, phi"},
509     
510    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
511      "Evaluate the model at a given Q or Qx, Qy vector "},
512    {"reset",    (PyCFunction)reset   , METH_VARARGS,
513      "Reset pair correlation"},
514    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
515      "Set the dispersion model for a given parameter"},
516   {NULL}
517};
518
519static PyTypeObject CBinaryHSModelType = {
520    PyObject_HEAD_INIT(NULL)
521    0,                         /*ob_size*/
522    "CBinaryHSModel",             /*tp_name*/
523    sizeof(CBinaryHSModel),             /*tp_basicsize*/
524    0,                         /*tp_itemsize*/
525    (destructor)CBinaryHSModel_dealloc, /*tp_dealloc*/
526    0,                         /*tp_print*/
527    0,                         /*tp_getattr*/
528    0,                         /*tp_setattr*/
529    0,                         /*tp_compare*/
530    0,                         /*tp_repr*/
531    0,                         /*tp_as_number*/
532    0,                         /*tp_as_sequence*/
533    0,                         /*tp_as_mapping*/
534    0,                         /*tp_hash */
535    0,                         /*tp_call*/
536    0,                         /*tp_str*/
537    0,                         /*tp_getattro*/
538    0,                         /*tp_setattro*/
539    0,                         /*tp_as_buffer*/
540    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
541    "CBinaryHSModel objects",           /* tp_doc */
542    0,                         /* tp_traverse */
543    0,                         /* tp_clear */
544    0,                         /* tp_richcompare */
545    0,                         /* tp_weaklistoffset */
546    0,                         /* tp_iter */
547    0,                         /* tp_iternext */
548    CBinaryHSModel_methods,             /* tp_methods */
549    CBinaryHSModel_members,             /* tp_members */
550    0,                         /* tp_getset */
551    0,                         /* tp_base */
552    0,                         /* tp_dict */
553    0,                         /* tp_descr_get */
554    0,                         /* tp_descr_set */
555    0,                         /* tp_dictoffset */
556    (initproc)CBinaryHSModel_init,      /* tp_init */
557    0,                         /* tp_alloc */
558    CBinaryHSModel_new,                 /* tp_new */
559};
560
561
562//static PyMethodDef module_methods[] = {
563//    {NULL}
564//};
565
566/**
567 * Function used to add the model class to a module
568 * @param module: module to add the class to
569 */ 
570void addCBinaryHSModel(PyObject *module) {
571        PyObject *d;
572       
573    if (PyType_Ready(&CBinaryHSModelType) < 0)
574        return;
575
576    Py_INCREF(&CBinaryHSModelType);
577    PyModule_AddObject(module, "CBinaryHSModel", (PyObject *)&CBinaryHSModelType);
578   
579    d = PyModule_GetDict(module);
580    static char error_name[] = "CBinaryHSModel.error";
581    CBinaryHSModelError = PyErr_NewException(error_name, NULL, NULL);
582    PyDict_SetItemString(d, "CBinaryHSModelError", CBinaryHSModelError);
583}
584
Note: See TracBrowser for help on using the repository browser.