source: sasview/sansmodels/src/sans/models/c_models/CProlateModel.cpp @ 1d67243

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 1d67243 was 9bd69098, checked in by Jae Cho <jhjcho@…>, 15 years ago

recompiled all due to Alina's new eval(run) function

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