source: sasview/sansmodels/src/sans/models/c_models/CBinaryHSModel.cpp @ 0b082f3

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

Re #7 Enable openmp for all models

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