source: sasview/src/sans/models/c_extension/python_wrapper/generated/CCore2ndMomentModel.cpp @ 400155b

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 400155b was 400155b, checked in by gonzalezm, 9 years ago

Implementing request from ticket 261 - default number of bins in Annulus [Phi View] is now 36 and the first bin is now centered at 0 degrees

  • Property mode set to 100644
File size: 22.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/** CCore2ndMomentModel
16 *
17 * C extension
18 *
19 * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
20 *          DO NOT MODIFY THIS FILE, MODIFY src\sans\models\include\coresecondmoment.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
36}
37
38#include "coresecondmoment.h"
39#include "dispersion_visitor.hh"
40
41/// Error object for raised exceptions
42static PyObject * CCore2ndMomentModelError = 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    Core2ndMomentModel * model;
54    /// Log for unit testing
55    PyObject * log;
56} CCore2ndMomentModel;
57
58
59static void
60CCore2ndMomentModel_dealloc(CCore2ndMomentModel* 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 *
72CCore2ndMomentModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
73{
74    CCore2ndMomentModel *self;
75   
76    self = (CCore2ndMomentModel *)type->tp_alloc(type, 0);
77   
78    return (PyObject *)self;
79}
80
81static int
82CCore2ndMomentModel_init(CCore2ndMomentModel *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
90        self->model = new Core2ndMomentModel();
91
92        // Initialize parameter dictionary
93        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000000000));
94        PyDict_SetItemString(self->params,"second_moment",Py_BuildValue("d",23.000000000000));
95        PyDict_SetItemString(self->params,"density_poly",Py_BuildValue("d",0.700000000000));
96        PyDict_SetItemString(self->params,"ads_amount",Py_BuildValue("d",1.900000000000));
97        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000000000));
98        PyDict_SetItemString(self->params,"volf_cores",Py_BuildValue("d",0.140000000000));
99        PyDict_SetItemString(self->params,"radius_core",Py_BuildValue("d",500.000000000000));
100        PyDict_SetItemString(self->params,"sld_poly",Py_BuildValue("d",0.000001500000));
101        PyDict_SetItemString(self->params,"sld_solv",Py_BuildValue("d",0.000006300000));
102        // Initialize dispersion / averaging parameter dict
103        DispersionVisitor* visitor = new DispersionVisitor();
104        PyObject * disp_dict;
105        disp_dict = PyDict_New();
106        self->model->radius_core.dispersion->accept_as_source(visitor, self->model->radius_core.dispersion, disp_dict);
107        PyDict_SetItemString(self->dispersion, "radius_core", disp_dict);
108
109
110         
111        // Create empty log
112        self->log = PyDict_New();
113       
114       
115
116    }
117    return 0;
118}
119
120static char name_params[] = "params";
121static char def_params[] = "Parameters";
122static char name_dispersion[] = "dispersion";
123static char def_dispersion[] = "Dispersion parameters";
124static char name_log[] = "log";
125static char def_log[] = "Log";
126
127static PyMemberDef CCore2ndMomentModel_members[] = {
128    {name_params, T_OBJECT, offsetof(CCore2ndMomentModel, params), 0, def_params},
129        {name_dispersion, T_OBJECT, offsetof(CCore2ndMomentModel, dispersion), 0, def_dispersion},     
130    {name_log, T_OBJECT, offsetof(CCore2ndMomentModel, log), 0, def_log},
131    {NULL}  /* Sentinel */
132};
133
134/** Read double from PyObject
135    @param p PyObject
136    @return double
137*/
138double CCore2ndMomentModel_readDouble(PyObject *p) {
139    if (PyFloat_Check(p)==1) {
140        return (double)(((PyFloatObject *)(p))->ob_fval);
141    } else if (PyInt_Check(p)==1) {
142        return (double)(((PyIntObject *)(p))->ob_ival);
143    } else if (PyLong_Check(p)==1) {
144        return (double)PyLong_AsLong(p);
145    } else {
146        return 0.0;
147    }
148}
149/**
150 * Function to call to evaluate model
151 * @param args: input numpy array q[]
152 * @return: numpy array object
153 */
154 
155static PyObject *evaluateOneDim(Core2ndMomentModel* model, PyArrayObject *q){
156    PyArrayObject *result;
157   
158    // Check validity of array q , q must be of dimension 1, an array of double
159    if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE)
160    {
161        //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num;
162        //PyErr_SetString(PyExc_ValueError , message);
163        return NULL;
164    }
165    result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), 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#pragma omp parallel for
172         for (int i = 0; i < q->dimensions[0]; i++){
173      double q_value  = *(double *)(q->data + i*q->strides[0]);
174      double *result_value = (double *)(result->data + i*result->strides[0]);
175      *result_value =(*model)(q_value);
176        }
177    return PyArray_Return(result); 
178 }
179
180 /**
181 * Function to call to evaluate model
182 * @param args: input numpy array  [x[],y[]]
183 * @return: numpy array object
184 */
185 static PyObject * evaluateTwoDimXY( Core2ndMomentModel* model, 
186                              PyArrayObject *x, PyArrayObject *y)
187 {
188    PyArrayObject *result;
189    int x_len, y_len, dims[1];
190    //check validity of input vectors
191    if (x->nd != 1 || x->descr->type_num != PyArray_DOUBLE
192        || y->nd != 1 || y->descr->type_num != PyArray_DOUBLE
193        || y->dimensions[0] != x->dimensions[0]){
194        const char * message= "evaluateTwoDimXY  expect 2 numpy arrays";
195        PyErr_SetString(PyExc_ValueError , message); 
196        return NULL;
197    }
198   
199        if (PyArray_Check(x) && PyArray_Check(y)) {
200               
201            x_len = dims[0]= x->dimensions[0];
202        y_len = dims[0]= y->dimensions[0];
203           
204            // Make a new double matrix of same dims
205        result=(PyArrayObject *) PyArray_FromDims(1,dims,NPY_DOUBLE);
206        if (result == NULL){
207            const char * message= "Could not create result ";
208        PyErr_SetString(PyExc_RuntimeError , message);
209            return NULL;
210            }
211       
212        /* Do the calculation. */
213#pragma omp parallel for
214        for (int i=0; i< x_len; i++) {
215            double x_value = *(double *)(x->data + i*x->strides[0]);
216                    double y_value = *(double *)(y->data + i*y->strides[0]);
217                        double *result_value = (double *)(result->data +
218                              i*result->strides[0]);
219                        *result_value = (*model)(x_value, y_value);
220        }           
221        return PyArray_Return(result); 
222       
223        }else{
224                    PyErr_SetString(CCore2ndMomentModelError, 
225                   "CCore2ndMomentModel.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(CCore2ndMomentModel *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->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
243    self->model->second_moment = PyFloat_AsDouble( PyDict_GetItemString(self->params, "second_moment") );
244    self->model->density_poly = PyFloat_AsDouble( PyDict_GetItemString(self->params, "density_poly") );
245    self->model->ads_amount = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ads_amount") );
246    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
247    self->model->volf_cores = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_cores") );
248    self->model->radius_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_core") );
249    self->model->sld_poly = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_poly") );
250    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
251    // Read in dispersion parameters
252    PyObject* disp_dict;
253    DispersionVisitor* visitor = new DispersionVisitor();
254    disp_dict = PyDict_GetItemString(self->dispersion, "radius_core");
255    self->model->radius_core.dispersion->accept_as_destination(visitor, self->model->radius_core.dispersion, disp_dict);
256
257       
258        // Get input and determine whether we have to supply a 1D or 2D return value.
259        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
260            PyErr_SetString(CCore2ndMomentModelError, 
261                "CCore2ndMomentModel.evalDistribution expects a q value.");
262                return NULL;
263        }
264    // Check params
265       
266    if(PyArray_Check(pars)==1) {
267               
268            // Length of list should 1 or 2
269            npars = pars->nd; 
270            if(npars==1) {
271                // input is a numpy array
272                if (PyArray_Check(pars)) {
273                        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
274                    }
275                }else{
276                    PyErr_SetString(CCore2ndMomentModelError, 
277                   "CCore2ndMomentModel.evalDistribution expect numpy array of one dimension.");
278                return NULL;
279                }
280    }else if( PyList_Check(pars)==1) {
281        // Length of list should be 2 for I(qx,qy)
282            mpars = PyList_GET_SIZE(pars); 
283            if(mpars!=2) {
284                PyErr_SetString(CCore2ndMomentModelError, 
285                        "CCore2ndMomentModel.evalDistribution expects a list of dimension 2.");
286                return NULL;
287            }
288             qx = PyList_GET_ITEM(pars,0);
289             qy = PyList_GET_ITEM(pars,1);
290             if (PyArray_Check(qx) && PyArray_Check(qy)) {
291                 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
292                           (PyArrayObject*)qy);
293                 }else{
294                    PyErr_SetString(CCore2ndMomentModelError, 
295                   "CCore2ndMomentModel.evalDistribution expect 2 numpy arrays in list.");
296                return NULL;
297             }
298        }
299        PyErr_SetString(CCore2ndMomentModelError, 
300                   "CCore2ndMomentModel.evalDistribution couln't be run.");
301        return NULL;
302       
303}
304
305/**
306 * Function to call to evaluate model
307 * @param args: input q or [q,phi]
308 * @return: function value
309 */
310static PyObject * run(CCore2ndMomentModel *self, PyObject *args) {
311        double q_value, phi_value;
312        PyObject* pars;
313        int npars;
314       
315        // Get parameters
316       
317            // Reader parameter dictionary
318    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
319    self->model->second_moment = PyFloat_AsDouble( PyDict_GetItemString(self->params, "second_moment") );
320    self->model->density_poly = PyFloat_AsDouble( PyDict_GetItemString(self->params, "density_poly") );
321    self->model->ads_amount = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ads_amount") );
322    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
323    self->model->volf_cores = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_cores") );
324    self->model->radius_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_core") );
325    self->model->sld_poly = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_poly") );
326    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
327    // Read in dispersion parameters
328    PyObject* disp_dict;
329    DispersionVisitor* visitor = new DispersionVisitor();
330    disp_dict = PyDict_GetItemString(self->dispersion, "radius_core");
331    self->model->radius_core.dispersion->accept_as_destination(visitor, self->model->radius_core.dispersion, disp_dict);
332
333       
334        // Get input and determine whether we have to supply a 1D or 2D return value.
335        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
336            PyErr_SetString(CCore2ndMomentModelError, 
337                "CCore2ndMomentModel.run expects a q value.");
338                return NULL;
339        }
340         
341        // Check params
342        if( PyList_Check(pars)==1) {
343               
344                // Length of list should be 2 for I(q,phi)
345            npars = PyList_GET_SIZE(pars); 
346            if(npars!=2) {
347                PyErr_SetString(CCore2ndMomentModelError, 
348                        "CCore2ndMomentModel.run expects a double or a list of dimension 2.");
349                return NULL;
350            }
351            // We have a vector q, get the q and phi values at which
352            // to evaluate I(q,phi)
353            q_value = CCore2ndMomentModel_readDouble(PyList_GET_ITEM(pars,0));
354            phi_value = CCore2ndMomentModel_readDouble(PyList_GET_ITEM(pars,1));
355            // Skip zero
356            if (q_value==0) {
357                return Py_BuildValue("d",0.0);
358            }
359                return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
360
361        } else {
362
363                // We have a scalar q, we will evaluate I(q)
364                q_value = CCore2ndMomentModel_readDouble(pars);         
365               
366                return Py_BuildValue("d",(*(self->model))(q_value));
367        }       
368}
369/**
370 * Function to call to calculate_ER
371 * @return: effective radius value
372 */
373static PyObject * calculate_ER(CCore2ndMomentModel *self) {
374
375        // Get parameters
376       
377            // Reader parameter dictionary
378    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
379    self->model->second_moment = PyFloat_AsDouble( PyDict_GetItemString(self->params, "second_moment") );
380    self->model->density_poly = PyFloat_AsDouble( PyDict_GetItemString(self->params, "density_poly") );
381    self->model->ads_amount = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ads_amount") );
382    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
383    self->model->volf_cores = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_cores") );
384    self->model->radius_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_core") );
385    self->model->sld_poly = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_poly") );
386    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
387    // Read in dispersion parameters
388    PyObject* disp_dict;
389    DispersionVisitor* visitor = new DispersionVisitor();
390    disp_dict = PyDict_GetItemString(self->dispersion, "radius_core");
391    self->model->radius_core.dispersion->accept_as_destination(visitor, self->model->radius_core.dispersion, disp_dict);
392
393               
394        return Py_BuildValue("d",(*(self->model)).calculate_ER());
395
396}
397/**
398 * Function to call to cal the ratio shell volume/ total volume
399 * @return: the ratio shell volume/ total volume
400 */
401static PyObject * calculate_VR(CCore2ndMomentModel *self) {
402
403        // Get parameters
404       
405            // Reader parameter dictionary
406    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
407    self->model->second_moment = PyFloat_AsDouble( PyDict_GetItemString(self->params, "second_moment") );
408    self->model->density_poly = PyFloat_AsDouble( PyDict_GetItemString(self->params, "density_poly") );
409    self->model->ads_amount = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ads_amount") );
410    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
411    self->model->volf_cores = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_cores") );
412    self->model->radius_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_core") );
413    self->model->sld_poly = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_poly") );
414    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
415    // Read in dispersion parameters
416    PyObject* disp_dict;
417    DispersionVisitor* visitor = new DispersionVisitor();
418    disp_dict = PyDict_GetItemString(self->dispersion, "radius_core");
419    self->model->radius_core.dispersion->accept_as_destination(visitor, self->model->radius_core.dispersion, disp_dict);
420
421               
422        return Py_BuildValue("d",(*(self->model)).calculate_VR());
423
424}
425/**
426 * Function to call to evaluate model in cartesian coordinates
427 * @param args: input q or [qx, qy]]
428 * @return: function value
429 */
430static PyObject * runXY(CCore2ndMomentModel *self, PyObject *args) {
431        double qx_value, qy_value;
432        PyObject* pars;
433        int npars;
434       
435        // Get parameters
436       
437            // Reader parameter dictionary
438    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
439    self->model->second_moment = PyFloat_AsDouble( PyDict_GetItemString(self->params, "second_moment") );
440    self->model->density_poly = PyFloat_AsDouble( PyDict_GetItemString(self->params, "density_poly") );
441    self->model->ads_amount = PyFloat_AsDouble( PyDict_GetItemString(self->params, "ads_amount") );
442    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
443    self->model->volf_cores = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_cores") );
444    self->model->radius_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_core") );
445    self->model->sld_poly = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_poly") );
446    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
447    // Read in dispersion parameters
448    PyObject* disp_dict;
449    DispersionVisitor* visitor = new DispersionVisitor();
450    disp_dict = PyDict_GetItemString(self->dispersion, "radius_core");
451    self->model->radius_core.dispersion->accept_as_destination(visitor, self->model->radius_core.dispersion, disp_dict);
452
453       
454        // Get input and determine whether we have to supply a 1D or 2D return value.
455        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
456            PyErr_SetString(CCore2ndMomentModelError, 
457                "CCore2ndMomentModel.run expects a q value.");
458                return NULL;
459        }
460         
461        // Check params
462        if( PyList_Check(pars)==1) {
463               
464                // Length of list should be 2 for I(qx, qy))
465            npars = PyList_GET_SIZE(pars); 
466            if(npars!=2) {
467                PyErr_SetString(CCore2ndMomentModelError, 
468                        "CCore2ndMomentModel.run expects a double or a list of dimension 2.");
469                return NULL;
470            }
471            // We have a vector q, get the qx and qy values at which
472            // to evaluate I(qx,qy)
473            qx_value = CCore2ndMomentModel_readDouble(PyList_GET_ITEM(pars,0));
474            qy_value = CCore2ndMomentModel_readDouble(PyList_GET_ITEM(pars,1));
475            return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
476
477        } else {
478
479                // We have a scalar q, we will evaluate I(q)
480                qx_value = CCore2ndMomentModel_readDouble(pars);               
481               
482                return Py_BuildValue("d",(*(self->model))(qx_value));
483        }       
484}
485
486static PyObject * reset(CCore2ndMomentModel *self, PyObject *args) {
487   
488
489    return Py_BuildValue("d",0.0);
490}
491
492static PyObject * set_dispersion(CCore2ndMomentModel *self, PyObject *args) {
493        PyObject * disp;
494        const char * par_name;
495
496        if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
497            PyErr_SetString(CCore2ndMomentModelError,
498                "CCore2ndMomentModel.set_dispersion expects a DispersionModel object.");
499                return NULL;
500        }
501        void *temp = PyCObject_AsVoidPtr(disp);
502        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
503
504
505        // Ugliness necessary to go from python to C
506            // TODO: refactor this
507    if (!strcmp(par_name, "radius_core")) {
508        self->model->radius_core.dispersion = dispersion;
509    } else {
510            PyErr_SetString(CCore2ndMomentModelError,
511                "CCore2ndMomentModel.set_dispersion expects a valid parameter name.");
512                return NULL;
513        }
514
515        DispersionVisitor* visitor = new DispersionVisitor();
516        PyObject * disp_dict = PyDict_New();
517        dispersion->accept_as_source(visitor, dispersion, disp_dict);
518        PyDict_SetItemString(self->dispersion, par_name, disp_dict);
519    return Py_BuildValue("i",1);
520}
521
522
523static PyMethodDef CCore2ndMomentModel_methods[] = {
524    {"run",      (PyCFunction)run     , METH_VARARGS,
525      "Evaluate the model at a given Q or Q, phi"},
526    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
527      "Evaluate the model at a given Q or Qx, Qy"},
528    {"calculate_ER",      (PyCFunction)calculate_ER     , METH_VARARGS,
529      "Evaluate the model at a given Q or Q, phi"},
530    {"calculate_VR",      (PyCFunction)calculate_VR     , METH_VARARGS,
531      "Evaluate VR"},   
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 CCore2ndMomentModelType = {
542    PyObject_HEAD_INIT(NULL)
543    0,                         /*ob_size*/
544    "CCore2ndMomentModel",             /*tp_name*/
545    sizeof(CCore2ndMomentModel),             /*tp_basicsize*/
546    0,                         /*tp_itemsize*/
547    (destructor)CCore2ndMomentModel_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    "CCore2ndMomentModel 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    CCore2ndMomentModel_methods,             /* tp_methods */
571    CCore2ndMomentModel_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)CCore2ndMomentModel_init,      /* tp_init */
579    0,                         /* tp_alloc */
580    CCore2ndMomentModel_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 addCCore2ndMomentModel(PyObject *module) {
593        PyObject *d;
594       
595    if (PyType_Ready(&CCore2ndMomentModelType) < 0)
596        return;
597
598    Py_INCREF(&CCore2ndMomentModelType);
599    PyModule_AddObject(module, "CCore2ndMomentModel", (PyObject *)&CCore2ndMomentModelType);
600   
601    d = PyModule_GetDict(module);
602    static char error_name[] = "CCore2ndMomentModel.error";
603    CCore2ndMomentModelError = PyErr_NewException(error_name, NULL, NULL);
604    PyDict_SetItemString(d, "CCore2ndMomentModelError", CCore2ndMomentModelError);
605}
606
Note: See TracBrowser for help on using the repository browser.