source: sasview/sansmodels/src/sans/models/c_models/CProlateModel.cpp @ 7ad9887

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 7ad9887 was 9ce41c6, checked in by Gervaise Alina <gervyh@…>, 15 years ago

wrote unittest for all model untested , haven' test critial point error handling

  • Property mode set to 100644
File size: 23.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/** 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 /**
180 * Function to call to evaluate model
181 * @param args: input numpy array  [x[],y[]]
182 * @return: numpy array object
183 */
184 static PyObject * evaluateTwoDimXY( ProlateModel* model, 
185                              PyArrayObject *x, PyArrayObject *y)
186 {
187    PyArrayObject *result;
188    int i,j, x_len, y_len, dims[2];
189    //check validity of input vectors
190    if (x->nd != 2 || x->descr->type_num != PyArray_DOUBLE
191        || y->nd != 2 || y->descr->type_num != PyArray_DOUBLE
192        || y->dimensions[1] != x->dimensions[0]){
193        const char * message= "evaluateTwoDimXY  expect 2 numpy arrays";
194        PyErr_SetString(PyExc_ValueError , message); 
195        return NULL;
196    }
197   
198        if (PyArray_Check(x) && PyArray_Check(y)) {
199               
200            x_len = dims[1]= x->dimensions[1];
201        y_len = dims[0]= y->dimensions[0];
202           
203            // Make a new double matrix of same dims
204        result=(PyArrayObject *) PyArray_FromDims(2,dims,NPY_DOUBLE);
205        if (result == NULL){
206            const char * message= "Could not create result ";
207        PyErr_SetString(PyExc_RuntimeError , message);
208            return NULL;
209            }
210       
211        /* Do the calculation. */
212        for ( j=0; j< y_len; j++) {
213            for ( i=0; i< x_len; i++) {
214                double x_value = *(double *)(x->data + i*x->strides[1]);
215                    double y_value = *(double *)(y->data + j*y->strides[0]);
216                        double *result_value = (double *)(result->data +
217                              j*result->strides[0] + i*result->strides[1]);
218                        *result_value = (*model)(x_value, y_value);
219            }           
220        }
221        return PyArray_Return(result); 
222       
223        }else{
224                    PyErr_SetString(CProlateModelError, 
225                   "CProlateModel.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(CProlateModel *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->major_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "major_core") );
243    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
244    self->model->minor_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "minor_core") );
245    self->model->sld_solvent = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solvent") );
246    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
247    self->model->major_shell = PyFloat_AsDouble( PyDict_GetItemString(self->params, "major_shell") );
248    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
249    self->model->minor_shell = PyFloat_AsDouble( PyDict_GetItemString(self->params, "minor_shell") );
250    // Read in dispersion parameters
251    PyObject* disp_dict;
252    DispersionVisitor* visitor = new DispersionVisitor();
253    disp_dict = PyDict_GetItemString(self->dispersion, "major_core");
254    self->model->major_core.dispersion->accept_as_destination(visitor, self->model->major_core.dispersion, disp_dict);
255    disp_dict = PyDict_GetItemString(self->dispersion, "minor_core");
256    self->model->minor_core.dispersion->accept_as_destination(visitor, self->model->minor_core.dispersion, disp_dict);
257    disp_dict = PyDict_GetItemString(self->dispersion, "major_shell");
258    self->model->major_shell.dispersion->accept_as_destination(visitor, self->model->major_shell.dispersion, disp_dict);
259    disp_dict = PyDict_GetItemString(self->dispersion, "minor_shell");
260    self->model->minor_shell.dispersion->accept_as_destination(visitor, self->model->minor_shell.dispersion, disp_dict);
261
262       
263        // Get input and determine whether we have to supply a 1D or 2D return value.
264        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
265            PyErr_SetString(CProlateModelError, 
266                "CProlateModel.evalDistribution expects a q value.");
267                return NULL;
268        }
269    // Check params
270       
271    if(PyArray_Check(pars)==1) {
272               
273            // Length of list should 1 or 2
274            npars = pars->nd; 
275            if(npars==1) {
276                // input is a numpy array
277                if (PyArray_Check(pars)) {
278                        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
279                    }
280                }else{
281                    PyErr_SetString(CProlateModelError, 
282                   "CProlateModel.evalDistribution expect numpy array of one dimension.");
283                return NULL;
284                }
285    }else if( PyList_Check(pars)==1) {
286        // Length of list should be 2 for I(qx,qy)
287            mpars = PyList_GET_SIZE(pars); 
288            if(mpars!=2) {
289                PyErr_SetString(CProlateModelError, 
290                        "CProlateModel.evalDistribution expects a list of dimension 2.");
291                return NULL;
292            }
293             qx = PyList_GET_ITEM(pars,0);
294             qy = PyList_GET_ITEM(pars,1);
295             if (PyArray_Check(qx) && PyArray_Check(qy)) {
296                 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
297                           (PyArrayObject*)qy);
298                 }else{
299                    PyErr_SetString(CProlateModelError, 
300                   "CProlateModel.evalDistribution expect 2 numpy arrays in list.");
301                return NULL;
302             }
303        }
304        PyErr_SetString(CProlateModelError, 
305                   "CProlateModel.evalDistribution couln't be run.");
306        return NULL;
307       
308}
309
310/**
311 * Function to call to evaluate model
312 * @param args: input q or [q,phi]
313 * @return: function value
314 */
315static PyObject * run(CProlateModel *self, PyObject *args) {
316        double q_value, phi_value;
317        PyObject* pars;
318        int npars;
319       
320        // Get parameters
321       
322            // Reader parameter dictionary
323    self->model->major_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "major_core") );
324    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
325    self->model->minor_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "minor_core") );
326    self->model->sld_solvent = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solvent") );
327    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
328    self->model->major_shell = PyFloat_AsDouble( PyDict_GetItemString(self->params, "major_shell") );
329    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
330    self->model->minor_shell = PyFloat_AsDouble( PyDict_GetItemString(self->params, "minor_shell") );
331    // Read in dispersion parameters
332    PyObject* disp_dict;
333    DispersionVisitor* visitor = new DispersionVisitor();
334    disp_dict = PyDict_GetItemString(self->dispersion, "major_core");
335    self->model->major_core.dispersion->accept_as_destination(visitor, self->model->major_core.dispersion, disp_dict);
336    disp_dict = PyDict_GetItemString(self->dispersion, "minor_core");
337    self->model->minor_core.dispersion->accept_as_destination(visitor, self->model->minor_core.dispersion, disp_dict);
338    disp_dict = PyDict_GetItemString(self->dispersion, "major_shell");
339    self->model->major_shell.dispersion->accept_as_destination(visitor, self->model->major_shell.dispersion, disp_dict);
340    disp_dict = PyDict_GetItemString(self->dispersion, "minor_shell");
341    self->model->minor_shell.dispersion->accept_as_destination(visitor, self->model->minor_shell.dispersion, disp_dict);
342
343       
344        // Get input and determine whether we have to supply a 1D or 2D return value.
345        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
346            PyErr_SetString(CProlateModelError, 
347                "CProlateModel.run expects a q value.");
348                return NULL;
349        }
350         
351        // Check params
352        if( PyList_Check(pars)==1) {
353               
354                // Length of list should be 2 for I(q,phi)
355            npars = PyList_GET_SIZE(pars); 
356            if(npars!=2) {
357                PyErr_SetString(CProlateModelError, 
358                        "CProlateModel.run expects a double or a list of dimension 2.");
359                return NULL;
360            }
361            // We have a vector q, get the q and phi values at which
362            // to evaluate I(q,phi)
363            q_value = CProlateModel_readDouble(PyList_GET_ITEM(pars,0));
364            phi_value = CProlateModel_readDouble(PyList_GET_ITEM(pars,1));
365            // Skip zero
366            if (q_value==0) {
367                return Py_BuildValue("d",0.0);
368            }
369                return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
370
371        } else {
372
373                // We have a scalar q, we will evaluate I(q)
374                q_value = CProlateModel_readDouble(pars);               
375               
376                return Py_BuildValue("d",(*(self->model))(q_value));
377        }       
378}
379/**
380 * Function to call to calculate_ER
381 * @return: effective radius value
382 */
383static PyObject * calculate_ER(CProlateModel *self) {
384
385        PyObject* pars;
386        int npars;
387       
388        // Get parameters
389       
390            // Reader parameter dictionary
391    self->model->major_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "major_core") );
392    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
393    self->model->minor_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "minor_core") );
394    self->model->sld_solvent = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solvent") );
395    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
396    self->model->major_shell = PyFloat_AsDouble( PyDict_GetItemString(self->params, "major_shell") );
397    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
398    self->model->minor_shell = PyFloat_AsDouble( PyDict_GetItemString(self->params, "minor_shell") );
399    // Read in dispersion parameters
400    PyObject* disp_dict;
401    DispersionVisitor* visitor = new DispersionVisitor();
402    disp_dict = PyDict_GetItemString(self->dispersion, "major_core");
403    self->model->major_core.dispersion->accept_as_destination(visitor, self->model->major_core.dispersion, disp_dict);
404    disp_dict = PyDict_GetItemString(self->dispersion, "minor_core");
405    self->model->minor_core.dispersion->accept_as_destination(visitor, self->model->minor_core.dispersion, disp_dict);
406    disp_dict = PyDict_GetItemString(self->dispersion, "major_shell");
407    self->model->major_shell.dispersion->accept_as_destination(visitor, self->model->major_shell.dispersion, disp_dict);
408    disp_dict = PyDict_GetItemString(self->dispersion, "minor_shell");
409    self->model->minor_shell.dispersion->accept_as_destination(visitor, self->model->minor_shell.dispersion, disp_dict);
410
411               
412        return Py_BuildValue("d",(*(self->model)).calculate_ER());
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    {"calculate_ER",      (PyCFunction)calculate_ER     , METH_VARARGS,
530      "Evaluate the model at a given Q or Q, phi"},
531     
532    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
533      "Evaluate the model at a given Q or Qx, Qy vector "},
534    {"reset",    (PyCFunction)reset   , METH_VARARGS,
535      "Reset pair correlation"},
536    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
537      "Set the dispersion model for a given parameter"},
538   {NULL}
539};
540
541static PyTypeObject CProlateModelType = {
542    PyObject_HEAD_INIT(NULL)
543    0,                         /*ob_size*/
544    "CProlateModel",             /*tp_name*/
545    sizeof(CProlateModel),             /*tp_basicsize*/
546    0,                         /*tp_itemsize*/
547    (destructor)CProlateModel_dealloc, /*tp_dealloc*/
548    0,                         /*tp_print*/
549    0,                         /*tp_getattr*/
550    0,                         /*tp_setattr*/
551    0,                         /*tp_compare*/
552    0,                         /*tp_repr*/
553    0,                         /*tp_as_number*/
554    0,                         /*tp_as_sequence*/
555    0,                         /*tp_as_mapping*/
556    0,                         /*tp_hash */
557    0,                         /*tp_call*/
558    0,                         /*tp_str*/
559    0,                         /*tp_getattro*/
560    0,                         /*tp_setattro*/
561    0,                         /*tp_as_buffer*/
562    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
563    "CProlateModel objects",           /* tp_doc */
564    0,                         /* tp_traverse */
565    0,                         /* tp_clear */
566    0,                         /* tp_richcompare */
567    0,                         /* tp_weaklistoffset */
568    0,                         /* tp_iter */
569    0,                         /* tp_iternext */
570    CProlateModel_methods,             /* tp_methods */
571    CProlateModel_members,             /* tp_members */
572    0,                         /* tp_getset */
573    0,                         /* tp_base */
574    0,                         /* tp_dict */
575    0,                         /* tp_descr_get */
576    0,                         /* tp_descr_set */
577    0,                         /* tp_dictoffset */
578    (initproc)CProlateModel_init,      /* tp_init */
579    0,                         /* tp_alloc */
580    CProlateModel_new,                 /* tp_new */
581};
582
583
584//static PyMethodDef module_methods[] = {
585//    {NULL}
586//};
587
588/**
589 * Function used to add the model class to a module
590 * @param module: module to add the class to
591 */ 
592void addCProlateModel(PyObject *module) {
593        PyObject *d;
594       
595    if (PyType_Ready(&CProlateModelType) < 0)
596        return;
597
598    Py_INCREF(&CProlateModelType);
599    PyModule_AddObject(module, "CProlateModel", (PyObject *)&CProlateModelType);
600   
601    d = PyModule_GetDict(module);
602    CProlateModelError = PyErr_NewException("CProlateModel.error", NULL, NULL);
603    PyDict_SetItemString(d, "CProlateModelError", CProlateModelError);
604}
605
Note: See TracBrowser for help on using the repository browser.