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

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 c451be9 was 71e2de7, checked in by Gervaise Alina <gervyh@…>, 15 years ago

change destructor for models

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