Changeset a8d6888 in sasview for sansmodels/src/sans/models
- Timestamp:
- Aug 24, 2009 10:08:37 AM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- df4702f
- Parents:
- 2339ff1e
- Location:
- sansmodels/src/sans/models
- Files:
-
- 39 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/c_extensions/CCoreShellCylinderModel.c
r9316609 ra8d6888 1 /** [PYTHONCLASS]1 /** CCoreShellCylinderModel 2 2 * 3 3 * C extension … … 20 20 21 21 /// Error object for raised exceptions 22 static PyObject * [PYTHONCLASS]Error = NULL;22 static PyObject * CCoreShellCylinderModelError = NULL; 23 23 24 24 … … 32 32 /// Model parameters 33 33 CoreShellCylinderParameters model_pars; 34 } [PYTHONCLASS];34 } CCoreShellCylinderModel; 35 35 36 36 37 37 static void 38 [PYTHONCLASS]_dealloc([PYTHONCLASS]* self)38 CCoreShellCylinderModel_dealloc(CCoreShellCylinderModel* self) 39 39 { 40 40 self->ob_type->tp_free((PyObject*)self); … … 44 44 45 45 static PyObject * 46 [PYTHONCLASS]_new(PyTypeObject *type, PyObject *args, PyObject *kwds)46 CCoreShellCylinderModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 47 47 { 48 [PYTHONCLASS]*self;48 CCoreShellCylinderModel *self; 49 49 50 self = ( [PYTHONCLASS]*)type->tp_alloc(type, 0);50 self = (CCoreShellCylinderModel *)type->tp_alloc(type, 0); 51 51 52 52 return (PyObject *)self; … … 54 54 55 55 static int 56 [PYTHONCLASS]_init([PYTHONCLASS]*self, PyObject *args, PyObject *kwds)56 CCoreShellCylinderModel_init(CCoreShellCylinderModel *self, PyObject *args, PyObject *kwds) 57 57 { 58 58 if (self != NULL) { … … 83 83 } 84 84 85 static PyMemberDef [PYTHONCLASS]_members[] = {86 {"params", T_OBJECT, offsetof( [PYTHONCLASS], params), 0,85 static PyMemberDef CCoreShellCylinderModel_members[] = { 86 {"params", T_OBJECT, offsetof(CCoreShellCylinderModel, params), 0, 87 87 "Parameters"}, 88 {"log", T_OBJECT, offsetof( [PYTHONCLASS], log), 0,88 {"log", T_OBJECT, offsetof(CCoreShellCylinderModel, log), 0, 89 89 "Log"}, 90 90 {NULL} /* Sentinel */ … … 95 95 @return double 96 96 */ 97 double [PYTHONCLASS]_readDouble(PyObject *p) {97 double CCoreShellCylinderModel_readDouble(PyObject *p) { 98 98 if (PyFloat_Check(p)==1) { 99 99 return (double)(((PyFloatObject *)(p))->ob_fval); … … 113 113 * @return: function value 114 114 */ 115 static PyObject * run( [PYTHONCLASS]*self, PyObject *args) {115 static PyObject * run(CCoreShellCylinderModel *self, PyObject *args) { 116 116 double q_value, phi_value; 117 117 PyObject* pars; … … 135 135 // Get input and determine whether we have to supply a 1D or 2D return value. 136 136 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 137 PyErr_SetString( [PYTHONCLASS]Error,138 " [PYTHONCLASS].run expects a q value.");137 PyErr_SetString(CCoreShellCylinderModelError, 138 "CCoreShellCylinderModel.run expects a q value."); 139 139 return NULL; 140 140 } … … 146 146 npars = PyList_GET_SIZE(pars); 147 147 if(npars!=2) { 148 PyErr_SetString( [PYTHONCLASS]Error,149 " [PYTHONCLASS].run expects a double or a list of dimension 2.");148 PyErr_SetString(CCoreShellCylinderModelError, 149 "CCoreShellCylinderModel.run expects a double or a list of dimension 2."); 150 150 return NULL; 151 151 } 152 152 // We have a vector q, get the q and phi values at which 153 153 // to evaluate I(q,phi) 154 q_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0));155 phi_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1));154 q_value = CCoreShellCylinderModel_readDouble(PyList_GET_ITEM(pars,0)); 155 phi_value = CCoreShellCylinderModel_readDouble(PyList_GET_ITEM(pars,1)); 156 156 // Skip zero 157 157 if (q_value==0) { … … 163 163 164 164 // We have a scalar q, we will evaluate I(q) 165 q_value = [PYTHONCLASS]_readDouble(pars);165 q_value = CCoreShellCylinderModel_readDouble(pars); 166 166 167 167 return Py_BuildValue("d",core_shell_cylinder_analytical_1D(&(self->model_pars),q_value)); … … 174 174 * @return: function value 175 175 */ 176 static PyObject * runXY( [PYTHONCLASS]*self, PyObject *args) {176 static PyObject * runXY(CCoreShellCylinderModel *self, PyObject *args) { 177 177 double qx_value, qy_value; 178 178 PyObject* pars; … … 196 196 // Get input and determine whether we have to supply a 1D or 2D return value. 197 197 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 198 PyErr_SetString( [PYTHONCLASS]Error,199 " [PYTHONCLASS].run expects a q value.");198 PyErr_SetString(CCoreShellCylinderModelError, 199 "CCoreShellCylinderModel.run expects a q value."); 200 200 return NULL; 201 201 } … … 207 207 npars = PyList_GET_SIZE(pars); 208 208 if(npars!=2) { 209 PyErr_SetString( [PYTHONCLASS]Error,210 " [PYTHONCLASS].run expects a double or a list of dimension 2.");209 PyErr_SetString(CCoreShellCylinderModelError, 210 "CCoreShellCylinderModel.run expects a double or a list of dimension 2."); 211 211 return NULL; 212 212 } 213 213 // We have a vector q, get the qx and qy values at which 214 214 // to evaluate I(qx,qy) 215 qx_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0));216 qy_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1));215 qx_value = CCoreShellCylinderModel_readDouble(PyList_GET_ITEM(pars,0)); 216 qy_value = CCoreShellCylinderModel_readDouble(PyList_GET_ITEM(pars,1)); 217 217 return Py_BuildValue("d",core_shell_cylinder_analytical_2DXY(&(self->model_pars),qx_value,qy_value)); 218 218 … … 220 220 221 221 // We have a scalar q, we will evaluate I(q) 222 qx_value = [PYTHONCLASS]_readDouble(pars);222 qx_value = CCoreShellCylinderModel_readDouble(pars); 223 223 224 224 return Py_BuildValue("d",core_shell_cylinder_analytical_1D(&(self->model_pars),qx_value)); … … 226 226 } 227 227 228 static PyObject * reset( [PYTHONCLASS]*self, PyObject *args) {228 static PyObject * reset(CCoreShellCylinderModel *self, PyObject *args) { 229 229 230 230 … … 233 233 234 234 235 static PyMethodDef [PYTHONCLASS]_methods[] = {235 static PyMethodDef CCoreShellCylinderModel_methods[] = { 236 236 {"run", (PyCFunction)run , METH_VARARGS, 237 237 "Evaluate the model at a given Q or Q, phi"}, … … 245 245 }; 246 246 247 static PyTypeObject [PYTHONCLASS]Type = {247 static PyTypeObject CCoreShellCylinderModelType = { 248 248 PyObject_HEAD_INIT(NULL) 249 249 0, /*ob_size*/ 250 " [PYTHONCLASS]", /*tp_name*/251 sizeof( [PYTHONCLASS]), /*tp_basicsize*/250 "CCoreShellCylinderModel", /*tp_name*/ 251 sizeof(CCoreShellCylinderModel), /*tp_basicsize*/ 252 252 0, /*tp_itemsize*/ 253 (destructor) [PYTHONCLASS]_dealloc, /*tp_dealloc*/253 (destructor)CCoreShellCylinderModel_dealloc, /*tp_dealloc*/ 254 254 0, /*tp_print*/ 255 255 0, /*tp_getattr*/ … … 267 267 0, /*tp_as_buffer*/ 268 268 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 269 " [PYTHONCLASS]objects", /* tp_doc */269 "CCoreShellCylinderModel objects", /* tp_doc */ 270 270 0, /* tp_traverse */ 271 271 0, /* tp_clear */ … … 274 274 0, /* tp_iter */ 275 275 0, /* tp_iternext */ 276 [PYTHONCLASS]_methods, /* tp_methods */277 [PYTHONCLASS]_members, /* tp_members */276 CCoreShellCylinderModel_methods, /* tp_methods */ 277 CCoreShellCylinderModel_members, /* tp_members */ 278 278 0, /* tp_getset */ 279 279 0, /* tp_base */ … … 282 282 0, /* tp_descr_set */ 283 283 0, /* tp_dictoffset */ 284 (initproc) [PYTHONCLASS]_init, /* tp_init */284 (initproc)CCoreShellCylinderModel_init, /* tp_init */ 285 285 0, /* tp_alloc */ 286 [PYTHONCLASS]_new, /* tp_new */286 CCoreShellCylinderModel_new, /* tp_new */ 287 287 }; 288 288 … … 296 296 * @param module: module to add the class to 297 297 */ 298 void add [PYTHONCLASS](PyObject *module) {298 void addCCoreShellCylinderModel(PyObject *module) { 299 299 PyObject *d; 300 300 301 if (PyType_Ready(& [PYTHONCLASS]Type) < 0)301 if (PyType_Ready(&CCoreShellCylinderModelType) < 0) 302 302 return; 303 303 304 Py_INCREF(& [PYTHONCLASS]Type);305 PyModule_AddObject(module, " [PYTHONCLASS]", (PyObject *)&[PYTHONCLASS]Type);304 Py_INCREF(&CCoreShellCylinderModelType); 305 PyModule_AddObject(module, "CCoreShellCylinderModel", (PyObject *)&CCoreShellCylinderModelType); 306 306 307 307 d = PyModule_GetDict(module); 308 [PYTHONCLASS]Error = PyErr_NewException("[PYTHONCLASS].error", NULL, NULL);309 PyDict_SetItemString(d, " [PYTHONCLASS]Error", [PYTHONCLASS]Error);310 } 311 308 CCoreShellCylinderModelError = PyErr_NewException("CCoreShellCylinderModel.error", NULL, NULL); 309 PyDict_SetItemString(d, "CCoreShellCylinderModelError", CCoreShellCylinderModelError); 310 } 311 -
sansmodels/src/sans/models/c_extensions/CCoreShellModel.c
r9316609 ra8d6888 1 /** [PYTHONCLASS]1 /** CCoreShellModel 2 2 * 3 3 * C extension … … 20 20 21 21 /// Error object for raised exceptions 22 static PyObject * [PYTHONCLASS]Error = NULL;22 static PyObject * CCoreShellModelError = NULL; 23 23 24 24 … … 32 32 /// Model parameters 33 33 CoreShellParameters model_pars; 34 } [PYTHONCLASS];34 } CCoreShellModel; 35 35 36 36 37 37 static void 38 [PYTHONCLASS]_dealloc([PYTHONCLASS]* self)38 CCoreShellModel_dealloc(CCoreShellModel* self) 39 39 { 40 40 self->ob_type->tp_free((PyObject*)self); … … 44 44 45 45 static PyObject * 46 [PYTHONCLASS]_new(PyTypeObject *type, PyObject *args, PyObject *kwds)46 CCoreShellModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 47 47 { 48 [PYTHONCLASS]*self;48 CCoreShellModel *self; 49 49 50 self = ( [PYTHONCLASS]*)type->tp_alloc(type, 0);50 self = (CCoreShellModel *)type->tp_alloc(type, 0); 51 51 52 52 return (PyObject *)self; … … 54 54 55 55 static int 56 [PYTHONCLASS]_init([PYTHONCLASS]*self, PyObject *args, PyObject *kwds)56 CCoreShellModel_init(CCoreShellModel *self, PyObject *args, PyObject *kwds) 57 57 { 58 58 if (self != NULL) { … … 80 80 } 81 81 82 static PyMemberDef [PYTHONCLASS]_members[] = {83 {"params", T_OBJECT, offsetof( [PYTHONCLASS], params), 0,82 static PyMemberDef CCoreShellModel_members[] = { 83 {"params", T_OBJECT, offsetof(CCoreShellModel, params), 0, 84 84 "Parameters"}, 85 {"log", T_OBJECT, offsetof( [PYTHONCLASS], log), 0,85 {"log", T_OBJECT, offsetof(CCoreShellModel, log), 0, 86 86 "Log"}, 87 87 {NULL} /* Sentinel */ … … 92 92 @return double 93 93 */ 94 double [PYTHONCLASS]_readDouble(PyObject *p) {94 double CCoreShellModel_readDouble(PyObject *p) { 95 95 if (PyFloat_Check(p)==1) { 96 96 return (double)(((PyFloatObject *)(p))->ob_fval); … … 110 110 * @return: function value 111 111 */ 112 static PyObject * run( [PYTHONCLASS]*self, PyObject *args) {112 static PyObject * run(CCoreShellModel *self, PyObject *args) { 113 113 double q_value, phi_value; 114 114 PyObject* pars; … … 129 129 // Get input and determine whether we have to supply a 1D or 2D return value. 130 130 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 131 PyErr_SetString( [PYTHONCLASS]Error,132 " [PYTHONCLASS].run expects a q value.");131 PyErr_SetString(CCoreShellModelError, 132 "CCoreShellModel.run expects a q value."); 133 133 return NULL; 134 134 } … … 140 140 npars = PyList_GET_SIZE(pars); 141 141 if(npars!=2) { 142 PyErr_SetString( [PYTHONCLASS]Error,143 " [PYTHONCLASS].run expects a double or a list of dimension 2.");142 PyErr_SetString(CCoreShellModelError, 143 "CCoreShellModel.run expects a double or a list of dimension 2."); 144 144 return NULL; 145 145 } 146 146 // We have a vector q, get the q and phi values at which 147 147 // to evaluate I(q,phi) 148 q_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0));149 phi_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1));148 q_value = CCoreShellModel_readDouble(PyList_GET_ITEM(pars,0)); 149 phi_value = CCoreShellModel_readDouble(PyList_GET_ITEM(pars,1)); 150 150 // Skip zero 151 151 if (q_value==0) { … … 157 157 158 158 // We have a scalar q, we will evaluate I(q) 159 q_value = [PYTHONCLASS]_readDouble(pars);159 q_value = CCoreShellModel_readDouble(pars); 160 160 161 161 return Py_BuildValue("d",core_shell_analytical_1D(&(self->model_pars),q_value)); … … 168 168 * @return: function value 169 169 */ 170 static PyObject * runXY( [PYTHONCLASS]*self, PyObject *args) {170 static PyObject * runXY(CCoreShellModel *self, PyObject *args) { 171 171 double qx_value, qy_value; 172 172 PyObject* pars; … … 187 187 // Get input and determine whether we have to supply a 1D or 2D return value. 188 188 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 189 PyErr_SetString( [PYTHONCLASS]Error,190 " [PYTHONCLASS].run expects a q value.");189 PyErr_SetString(CCoreShellModelError, 190 "CCoreShellModel.run expects a q value."); 191 191 return NULL; 192 192 } … … 198 198 npars = PyList_GET_SIZE(pars); 199 199 if(npars!=2) { 200 PyErr_SetString( [PYTHONCLASS]Error,201 " [PYTHONCLASS].run expects a double or a list of dimension 2.");200 PyErr_SetString(CCoreShellModelError, 201 "CCoreShellModel.run expects a double or a list of dimension 2."); 202 202 return NULL; 203 203 } 204 204 // We have a vector q, get the qx and qy values at which 205 205 // to evaluate I(qx,qy) 206 qx_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0));207 qy_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1));206 qx_value = CCoreShellModel_readDouble(PyList_GET_ITEM(pars,0)); 207 qy_value = CCoreShellModel_readDouble(PyList_GET_ITEM(pars,1)); 208 208 return Py_BuildValue("d",core_shell_analytical_2DXY(&(self->model_pars),qx_value,qy_value)); 209 209 … … 211 211 212 212 // We have a scalar q, we will evaluate I(q) 213 qx_value = [PYTHONCLASS]_readDouble(pars);213 qx_value = CCoreShellModel_readDouble(pars); 214 214 215 215 return Py_BuildValue("d",core_shell_analytical_1D(&(self->model_pars),qx_value)); … … 217 217 } 218 218 219 static PyObject * reset( [PYTHONCLASS]*self, PyObject *args) {219 static PyObject * reset(CCoreShellModel *self, PyObject *args) { 220 220 221 221 … … 224 224 225 225 226 static PyMethodDef [PYTHONCLASS]_methods[] = {226 static PyMethodDef CCoreShellModel_methods[] = { 227 227 {"run", (PyCFunction)run , METH_VARARGS, 228 228 "Evaluate the model at a given Q or Q, phi"}, … … 236 236 }; 237 237 238 static PyTypeObject [PYTHONCLASS]Type = {238 static PyTypeObject CCoreShellModelType = { 239 239 PyObject_HEAD_INIT(NULL) 240 240 0, /*ob_size*/ 241 " [PYTHONCLASS]", /*tp_name*/242 sizeof( [PYTHONCLASS]), /*tp_basicsize*/241 "CCoreShellModel", /*tp_name*/ 242 sizeof(CCoreShellModel), /*tp_basicsize*/ 243 243 0, /*tp_itemsize*/ 244 (destructor) [PYTHONCLASS]_dealloc, /*tp_dealloc*/244 (destructor)CCoreShellModel_dealloc, /*tp_dealloc*/ 245 245 0, /*tp_print*/ 246 246 0, /*tp_getattr*/ … … 258 258 0, /*tp_as_buffer*/ 259 259 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 260 " [PYTHONCLASS]objects", /* tp_doc */260 "CCoreShellModel objects", /* tp_doc */ 261 261 0, /* tp_traverse */ 262 262 0, /* tp_clear */ … … 265 265 0, /* tp_iter */ 266 266 0, /* tp_iternext */ 267 [PYTHONCLASS]_methods, /* tp_methods */268 [PYTHONCLASS]_members, /* tp_members */267 CCoreShellModel_methods, /* tp_methods */ 268 CCoreShellModel_members, /* tp_members */ 269 269 0, /* tp_getset */ 270 270 0, /* tp_base */ … … 273 273 0, /* tp_descr_set */ 274 274 0, /* tp_dictoffset */ 275 (initproc) [PYTHONCLASS]_init, /* tp_init */275 (initproc)CCoreShellModel_init, /* tp_init */ 276 276 0, /* tp_alloc */ 277 [PYTHONCLASS]_new, /* tp_new */277 CCoreShellModel_new, /* tp_new */ 278 278 }; 279 279 … … 287 287 * @param module: module to add the class to 288 288 */ 289 void add [PYTHONCLASS](PyObject *module) {289 void addCCoreShellModel(PyObject *module) { 290 290 PyObject *d; 291 291 292 if (PyType_Ready(& [PYTHONCLASS]Type) < 0)292 if (PyType_Ready(&CCoreShellModelType) < 0) 293 293 return; 294 294 295 Py_INCREF(& [PYTHONCLASS]Type);296 PyModule_AddObject(module, " [PYTHONCLASS]", (PyObject *)&[PYTHONCLASS]Type);295 Py_INCREF(&CCoreShellModelType); 296 PyModule_AddObject(module, "CCoreShellModel", (PyObject *)&CCoreShellModelType); 297 297 298 298 d = PyModule_GetDict(module); 299 [PYTHONCLASS]Error = PyErr_NewException("[PYTHONCLASS].error", NULL, NULL);300 PyDict_SetItemString(d, " [PYTHONCLASS]Error", [PYTHONCLASS]Error);301 } 302 299 CCoreShellModelError = PyErr_NewException("CCoreShellModel.error", NULL, NULL); 300 PyDict_SetItemString(d, "CCoreShellModelError", CCoreShellModelError); 301 } 302 -
sansmodels/src/sans/models/c_extensions/CCylinderModel.c
r9316609 ra8d6888 1 /** [PYTHONCLASS]1 /** CCylinderModel 2 2 * 3 3 * C extension 4 4 * 5 5 * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY 6 * DO NOT MODIFY THIS FILE, MODIFY Cylinder.h6 * DO NOT MODIFY THIS FILE, MODIFY cylinder.h 7 7 * AND RE-RUN THE GENERATOR SCRIPT 8 8 * … … 17 17 #include <time.h> 18 18 19 #include " Cylinder.h"19 #include "cylinder.h" 20 20 21 21 /// Error object for raised exceptions 22 static PyObject * [PYTHONCLASS]Error = NULL;22 static PyObject * CCylinderModelError = NULL; 23 23 24 24 … … 32 32 /// Model parameters 33 33 CylinderParameters model_pars; 34 } [PYTHONCLASS];34 } CCylinderModel; 35 35 36 36 37 37 static void 38 [PYTHONCLASS]_dealloc([PYTHONCLASS]* self)38 CCylinderModel_dealloc(CCylinderModel* self) 39 39 { 40 40 self->ob_type->tp_free((PyObject*)self); … … 44 44 45 45 static PyObject * 46 [PYTHONCLASS]_new(PyTypeObject *type, PyObject *args, PyObject *kwds)46 CCylinderModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 47 47 { 48 [PYTHONCLASS]*self;48 CCylinderModel *self; 49 49 50 self = ( [PYTHONCLASS]*)type->tp_alloc(type, 0);50 self = (CCylinderModel *)type->tp_alloc(type, 0); 51 51 52 52 return (PyObject *)self; … … 54 54 55 55 static int 56 [PYTHONCLASS]_init([PYTHONCLASS]*self, PyObject *args, PyObject *kwds)56 CCylinderModel_init(CCylinderModel *self, PyObject *args, PyObject *kwds) 57 57 { 58 58 if (self != NULL) { … … 80 80 } 81 81 82 static PyMemberDef [PYTHONCLASS]_members[] = {83 {"params", T_OBJECT, offsetof( [PYTHONCLASS], params), 0,82 static PyMemberDef CCylinderModel_members[] = { 83 {"params", T_OBJECT, offsetof(CCylinderModel, params), 0, 84 84 "Parameters"}, 85 {"log", T_OBJECT, offsetof( [PYTHONCLASS], log), 0,85 {"log", T_OBJECT, offsetof(CCylinderModel, log), 0, 86 86 "Log"}, 87 87 {NULL} /* Sentinel */ … … 92 92 @return double 93 93 */ 94 double [PYTHONCLASS]_readDouble(PyObject *p) {94 double CCylinderModel_readDouble(PyObject *p) { 95 95 if (PyFloat_Check(p)==1) { 96 96 return (double)(((PyFloatObject *)(p))->ob_fval); … … 110 110 * @return: function value 111 111 */ 112 static PyObject * run( [PYTHONCLASS]*self, PyObject *args) {112 static PyObject * run(CCylinderModel *self, PyObject *args) { 113 113 double q_value, phi_value; 114 114 PyObject* pars; … … 129 129 // Get input and determine whether we have to supply a 1D or 2D return value. 130 130 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 131 PyErr_SetString( [PYTHONCLASS]Error,132 " [PYTHONCLASS].run expects a q value.");131 PyErr_SetString(CCylinderModelError, 132 "CCylinderModel.run expects a q value."); 133 133 return NULL; 134 134 } … … 140 140 npars = PyList_GET_SIZE(pars); 141 141 if(npars!=2) { 142 PyErr_SetString( [PYTHONCLASS]Error,143 " [PYTHONCLASS].run expects a double or a list of dimension 2.");142 PyErr_SetString(CCylinderModelError, 143 "CCylinderModel.run expects a double or a list of dimension 2."); 144 144 return NULL; 145 145 } 146 146 // We have a vector q, get the q and phi values at which 147 147 // to evaluate I(q,phi) 148 q_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0));149 phi_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1));148 q_value = CCylinderModel_readDouble(PyList_GET_ITEM(pars,0)); 149 phi_value = CCylinderModel_readDouble(PyList_GET_ITEM(pars,1)); 150 150 // Skip zero 151 151 if (q_value==0) { 152 152 return Py_BuildValue("d",0.0); 153 153 } 154 return Py_BuildValue("d", Cylinder_analytical_2D(&(self->model_pars),q_value,phi_value));154 return Py_BuildValue("d",cylinder_analytical_2D(&(self->model_pars),q_value,phi_value)); 155 155 156 156 } else { 157 157 158 158 // We have a scalar q, we will evaluate I(q) 159 q_value = [PYTHONCLASS]_readDouble(pars);159 q_value = CCylinderModel_readDouble(pars); 160 160 161 return Py_BuildValue("d", Cylinder_analytical_1D(&(self->model_pars),q_value));161 return Py_BuildValue("d",cylinder_analytical_1D(&(self->model_pars),q_value)); 162 162 } 163 163 } … … 168 168 * @return: function value 169 169 */ 170 static PyObject * runXY( [PYTHONCLASS]*self, PyObject *args) {170 static PyObject * runXY(CCylinderModel *self, PyObject *args) { 171 171 double qx_value, qy_value; 172 172 PyObject* pars; … … 187 187 // Get input and determine whether we have to supply a 1D or 2D return value. 188 188 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 189 PyErr_SetString( [PYTHONCLASS]Error,190 " [PYTHONCLASS].run expects a q value.");189 PyErr_SetString(CCylinderModelError, 190 "CCylinderModel.run expects a q value."); 191 191 return NULL; 192 192 } … … 198 198 npars = PyList_GET_SIZE(pars); 199 199 if(npars!=2) { 200 PyErr_SetString( [PYTHONCLASS]Error,201 " [PYTHONCLASS].run expects a double or a list of dimension 2.");200 PyErr_SetString(CCylinderModelError, 201 "CCylinderModel.run expects a double or a list of dimension 2."); 202 202 return NULL; 203 203 } 204 204 // We have a vector q, get the qx and qy values at which 205 205 // to evaluate I(qx,qy) 206 qx_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0));207 qy_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1));208 return Py_BuildValue("d", Cylinder_analytical_2DXY(&(self->model_pars),qx_value,qy_value));206 qx_value = CCylinderModel_readDouble(PyList_GET_ITEM(pars,0)); 207 qy_value = CCylinderModel_readDouble(PyList_GET_ITEM(pars,1)); 208 return Py_BuildValue("d",cylinder_analytical_2DXY(&(self->model_pars),qx_value,qy_value)); 209 209 210 210 } else { 211 211 212 212 // We have a scalar q, we will evaluate I(q) 213 qx_value = [PYTHONCLASS]_readDouble(pars);213 qx_value = CCylinderModel_readDouble(pars); 214 214 215 return Py_BuildValue("d", Cylinder_analytical_1D(&(self->model_pars),qx_value));215 return Py_BuildValue("d",cylinder_analytical_1D(&(self->model_pars),qx_value)); 216 216 } 217 217 } 218 218 219 static PyObject * reset( [PYTHONCLASS]*self, PyObject *args) {219 static PyObject * reset(CCylinderModel *self, PyObject *args) { 220 220 221 221 … … 224 224 225 225 226 static PyMethodDef [PYTHONCLASS]_methods[] = {226 static PyMethodDef CCylinderModel_methods[] = { 227 227 {"run", (PyCFunction)run , METH_VARARGS, 228 228 "Evaluate the model at a given Q or Q, phi"}, … … 236 236 }; 237 237 238 static PyTypeObject [PYTHONCLASS]Type = {238 static PyTypeObject CCylinderModelType = { 239 239 PyObject_HEAD_INIT(NULL) 240 240 0, /*ob_size*/ 241 " [PYTHONCLASS]", /*tp_name*/242 sizeof( [PYTHONCLASS]), /*tp_basicsize*/241 "CCylinderModel", /*tp_name*/ 242 sizeof(CCylinderModel), /*tp_basicsize*/ 243 243 0, /*tp_itemsize*/ 244 (destructor) [PYTHONCLASS]_dealloc, /*tp_dealloc*/244 (destructor)CCylinderModel_dealloc, /*tp_dealloc*/ 245 245 0, /*tp_print*/ 246 246 0, /*tp_getattr*/ … … 258 258 0, /*tp_as_buffer*/ 259 259 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 260 " [PYTHONCLASS]objects", /* tp_doc */260 "CCylinderModel objects", /* tp_doc */ 261 261 0, /* tp_traverse */ 262 262 0, /* tp_clear */ … … 265 265 0, /* tp_iter */ 266 266 0, /* tp_iternext */ 267 [PYTHONCLASS]_methods, /* tp_methods */268 [PYTHONCLASS]_members, /* tp_members */267 CCylinderModel_methods, /* tp_methods */ 268 CCylinderModel_members, /* tp_members */ 269 269 0, /* tp_getset */ 270 270 0, /* tp_base */ … … 273 273 0, /* tp_descr_set */ 274 274 0, /* tp_dictoffset */ 275 (initproc) [PYTHONCLASS]_init, /* tp_init */275 (initproc)CCylinderModel_init, /* tp_init */ 276 276 0, /* tp_alloc */ 277 [PYTHONCLASS]_new, /* tp_new */277 CCylinderModel_new, /* tp_new */ 278 278 }; 279 279 … … 287 287 * @param module: module to add the class to 288 288 */ 289 void add [PYTHONCLASS](PyObject *module) {289 void addCCylinderModel(PyObject *module) { 290 290 PyObject *d; 291 291 292 if (PyType_Ready(& [PYTHONCLASS]Type) < 0)292 if (PyType_Ready(&CCylinderModelType) < 0) 293 293 return; 294 294 295 Py_INCREF(& [PYTHONCLASS]Type);296 PyModule_AddObject(module, " [PYTHONCLASS]", (PyObject *)&[PYTHONCLASS]Type);295 Py_INCREF(&CCylinderModelType); 296 PyModule_AddObject(module, "CCylinderModel", (PyObject *)&CCylinderModelType); 297 297 298 298 d = PyModule_GetDict(module); 299 [PYTHONCLASS]Error = PyErr_NewException("[PYTHONCLASS].error", NULL, NULL);300 PyDict_SetItemString(d, " [PYTHONCLASS]Error", [PYTHONCLASS]Error);301 } 302 299 CCylinderModelError = PyErr_NewException("CCylinderModel.error", NULL, NULL); 300 PyDict_SetItemString(d, "CCylinderModelError", CCylinderModelError); 301 } 302 -
sansmodels/src/sans/models/c_extensions/CEllipsoidModel.c
r9316609 ra8d6888 1 /** [PYTHONCLASS]1 /** CEllipsoidModel 2 2 * 3 3 * C extension … … 20 20 21 21 /// Error object for raised exceptions 22 static PyObject * [PYTHONCLASS]Error = NULL;22 static PyObject * CEllipsoidModelError = NULL; 23 23 24 24 … … 32 32 /// Model parameters 33 33 EllipsoidParameters model_pars; 34 } [PYTHONCLASS];34 } CEllipsoidModel; 35 35 36 36 37 37 static void 38 [PYTHONCLASS]_dealloc([PYTHONCLASS]* self)38 CEllipsoidModel_dealloc(CEllipsoidModel* self) 39 39 { 40 40 self->ob_type->tp_free((PyObject*)self); … … 44 44 45 45 static PyObject * 46 [PYTHONCLASS]_new(PyTypeObject *type, PyObject *args, PyObject *kwds)46 CEllipsoidModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 47 47 { 48 [PYTHONCLASS]*self;48 CEllipsoidModel *self; 49 49 50 self = ( [PYTHONCLASS]*)type->tp_alloc(type, 0);50 self = (CEllipsoidModel *)type->tp_alloc(type, 0); 51 51 52 52 return (PyObject *)self; … … 54 54 55 55 static int 56 [PYTHONCLASS]_init([PYTHONCLASS]*self, PyObject *args, PyObject *kwds)56 CEllipsoidModel_init(CEllipsoidModel *self, PyObject *args, PyObject *kwds) 57 57 { 58 58 if (self != NULL) { … … 80 80 } 81 81 82 static PyMemberDef [PYTHONCLASS]_members[] = {83 {"params", T_OBJECT, offsetof( [PYTHONCLASS], params), 0,82 static PyMemberDef CEllipsoidModel_members[] = { 83 {"params", T_OBJECT, offsetof(CEllipsoidModel, params), 0, 84 84 "Parameters"}, 85 {"log", T_OBJECT, offsetof( [PYTHONCLASS], log), 0,85 {"log", T_OBJECT, offsetof(CEllipsoidModel, log), 0, 86 86 "Log"}, 87 87 {NULL} /* Sentinel */ … … 92 92 @return double 93 93 */ 94 double [PYTHONCLASS]_readDouble(PyObject *p) {94 double CEllipsoidModel_readDouble(PyObject *p) { 95 95 if (PyFloat_Check(p)==1) { 96 96 return (double)(((PyFloatObject *)(p))->ob_fval); … … 110 110 * @return: function value 111 111 */ 112 static PyObject * run( [PYTHONCLASS]*self, PyObject *args) {112 static PyObject * run(CEllipsoidModel *self, PyObject *args) { 113 113 double q_value, phi_value; 114 114 PyObject* pars; … … 129 129 // Get input and determine whether we have to supply a 1D or 2D return value. 130 130 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 131 PyErr_SetString( [PYTHONCLASS]Error,132 " [PYTHONCLASS].run expects a q value.");131 PyErr_SetString(CEllipsoidModelError, 132 "CEllipsoidModel.run expects a q value."); 133 133 return NULL; 134 134 } … … 140 140 npars = PyList_GET_SIZE(pars); 141 141 if(npars!=2) { 142 PyErr_SetString( [PYTHONCLASS]Error,143 " [PYTHONCLASS].run expects a double or a list of dimension 2.");142 PyErr_SetString(CEllipsoidModelError, 143 "CEllipsoidModel.run expects a double or a list of dimension 2."); 144 144 return NULL; 145 145 } 146 146 // We have a vector q, get the q and phi values at which 147 147 // to evaluate I(q,phi) 148 q_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0));149 phi_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1));148 q_value = CEllipsoidModel_readDouble(PyList_GET_ITEM(pars,0)); 149 phi_value = CEllipsoidModel_readDouble(PyList_GET_ITEM(pars,1)); 150 150 // Skip zero 151 151 if (q_value==0) { … … 157 157 158 158 // We have a scalar q, we will evaluate I(q) 159 q_value = [PYTHONCLASS]_readDouble(pars);159 q_value = CEllipsoidModel_readDouble(pars); 160 160 161 161 return Py_BuildValue("d",ellipsoid_analytical_1D(&(self->model_pars),q_value)); … … 168 168 * @return: function value 169 169 */ 170 static PyObject * runXY( [PYTHONCLASS]*self, PyObject *args) {170 static PyObject * runXY(CEllipsoidModel *self, PyObject *args) { 171 171 double qx_value, qy_value; 172 172 PyObject* pars; … … 187 187 // Get input and determine whether we have to supply a 1D or 2D return value. 188 188 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 189 PyErr_SetString( [PYTHONCLASS]Error,190 " [PYTHONCLASS].run expects a q value.");189 PyErr_SetString(CEllipsoidModelError, 190 "CEllipsoidModel.run expects a q value."); 191 191 return NULL; 192 192 } … … 198 198 npars = PyList_GET_SIZE(pars); 199 199 if(npars!=2) { 200 PyErr_SetString( [PYTHONCLASS]Error,201 " [PYTHONCLASS].run expects a double or a list of dimension 2.");200 PyErr_SetString(CEllipsoidModelError, 201 "CEllipsoidModel.run expects a double or a list of dimension 2."); 202 202 return NULL; 203 203 } 204 204 // We have a vector q, get the qx and qy values at which 205 205 // to evaluate I(qx,qy) 206 qx_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0));207 qy_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1));206 qx_value = CEllipsoidModel_readDouble(PyList_GET_ITEM(pars,0)); 207 qy_value = CEllipsoidModel_readDouble(PyList_GET_ITEM(pars,1)); 208 208 return Py_BuildValue("d",ellipsoid_analytical_2DXY(&(self->model_pars),qx_value,qy_value)); 209 209 … … 211 211 212 212 // We have a scalar q, we will evaluate I(q) 213 qx_value = [PYTHONCLASS]_readDouble(pars);213 qx_value = CEllipsoidModel_readDouble(pars); 214 214 215 215 return Py_BuildValue("d",ellipsoid_analytical_1D(&(self->model_pars),qx_value)); … … 217 217 } 218 218 219 static PyObject * reset( [PYTHONCLASS]*self, PyObject *args) {219 static PyObject * reset(CEllipsoidModel *self, PyObject *args) { 220 220 221 221 … … 224 224 225 225 226 static PyMethodDef [PYTHONCLASS]_methods[] = {226 static PyMethodDef CEllipsoidModel_methods[] = { 227 227 {"run", (PyCFunction)run , METH_VARARGS, 228 228 "Evaluate the model at a given Q or Q, phi"}, … … 236 236 }; 237 237 238 static PyTypeObject [PYTHONCLASS]Type = {238 static PyTypeObject CEllipsoidModelType = { 239 239 PyObject_HEAD_INIT(NULL) 240 240 0, /*ob_size*/ 241 " [PYTHONCLASS]", /*tp_name*/242 sizeof( [PYTHONCLASS]), /*tp_basicsize*/241 "CEllipsoidModel", /*tp_name*/ 242 sizeof(CEllipsoidModel), /*tp_basicsize*/ 243 243 0, /*tp_itemsize*/ 244 (destructor) [PYTHONCLASS]_dealloc, /*tp_dealloc*/244 (destructor)CEllipsoidModel_dealloc, /*tp_dealloc*/ 245 245 0, /*tp_print*/ 246 246 0, /*tp_getattr*/ … … 258 258 0, /*tp_as_buffer*/ 259 259 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 260 " [PYTHONCLASS]objects", /* tp_doc */260 "CEllipsoidModel objects", /* tp_doc */ 261 261 0, /* tp_traverse */ 262 262 0, /* tp_clear */ … … 265 265 0, /* tp_iter */ 266 266 0, /* tp_iternext */ 267 [PYTHONCLASS]_methods, /* tp_methods */268 [PYTHONCLASS]_members, /* tp_members */267 CEllipsoidModel_methods, /* tp_methods */ 268 CEllipsoidModel_members, /* tp_members */ 269 269 0, /* tp_getset */ 270 270 0, /* tp_base */ … … 273 273 0, /* tp_descr_set */ 274 274 0, /* tp_dictoffset */ 275 (initproc) [PYTHONCLASS]_init, /* tp_init */275 (initproc)CEllipsoidModel_init, /* tp_init */ 276 276 0, /* tp_alloc */ 277 [PYTHONCLASS]_new, /* tp_new */277 CEllipsoidModel_new, /* tp_new */ 278 278 }; 279 279 … … 287 287 * @param module: module to add the class to 288 288 */ 289 void add [PYTHONCLASS](PyObject *module) {289 void addCEllipsoidModel(PyObject *module) { 290 290 PyObject *d; 291 291 292 if (PyType_Ready(& [PYTHONCLASS]Type) < 0)292 if (PyType_Ready(&CEllipsoidModelType) < 0) 293 293 return; 294 294 295 Py_INCREF(& [PYTHONCLASS]Type);296 PyModule_AddObject(module, " [PYTHONCLASS]", (PyObject *)&[PYTHONCLASS]Type);295 Py_INCREF(&CEllipsoidModelType); 296 PyModule_AddObject(module, "CEllipsoidModel", (PyObject *)&CEllipsoidModelType); 297 297 298 298 d = PyModule_GetDict(module); 299 [PYTHONCLASS]Error = PyErr_NewException("[PYTHONCLASS].error", NULL, NULL);300 PyDict_SetItemString(d, " [PYTHONCLASS]Error", [PYTHONCLASS]Error);301 } 302 299 CEllipsoidModelError = PyErr_NewException("CEllipsoidModel.error", NULL, NULL); 300 PyDict_SetItemString(d, "CEllipsoidModelError", CEllipsoidModelError); 301 } 302 -
sansmodels/src/sans/models/c_extensions/CEllipticalCylinderModel.c
r9316609 ra8d6888 1 /** [PYTHONCLASS]1 /** CEllipticalCylinderModel 2 2 * 3 3 * C extension … … 20 20 21 21 /// Error object for raised exceptions 22 static PyObject * [PYTHONCLASS]Error = NULL;22 static PyObject * CEllipticalCylinderModelError = NULL; 23 23 24 24 … … 32 32 /// Model parameters 33 33 EllipticalCylinderParameters model_pars; 34 } [PYTHONCLASS];34 } CEllipticalCylinderModel; 35 35 36 36 37 37 static void 38 [PYTHONCLASS]_dealloc([PYTHONCLASS]* self)38 CEllipticalCylinderModel_dealloc(CEllipticalCylinderModel* self) 39 39 { 40 40 self->ob_type->tp_free((PyObject*)self); … … 44 44 45 45 static PyObject * 46 [PYTHONCLASS]_new(PyTypeObject *type, PyObject *args, PyObject *kwds)46 CEllipticalCylinderModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 47 47 { 48 [PYTHONCLASS]*self;48 CEllipticalCylinderModel *self; 49 49 50 self = ( [PYTHONCLASS]*)type->tp_alloc(type, 0);50 self = (CEllipticalCylinderModel *)type->tp_alloc(type, 0); 51 51 52 52 return (PyObject *)self; … … 54 54 55 55 static int 56 [PYTHONCLASS]_init([PYTHONCLASS]*self, PyObject *args, PyObject *kwds)56 CEllipticalCylinderModel_init(CEllipticalCylinderModel *self, PyObject *args, PyObject *kwds) 57 57 { 58 58 if (self != NULL) { … … 82 82 } 83 83 84 static PyMemberDef [PYTHONCLASS]_members[] = {85 {"params", T_OBJECT, offsetof( [PYTHONCLASS], params), 0,84 static PyMemberDef CEllipticalCylinderModel_members[] = { 85 {"params", T_OBJECT, offsetof(CEllipticalCylinderModel, params), 0, 86 86 "Parameters"}, 87 {"log", T_OBJECT, offsetof( [PYTHONCLASS], log), 0,87 {"log", T_OBJECT, offsetof(CEllipticalCylinderModel, log), 0, 88 88 "Log"}, 89 89 {NULL} /* Sentinel */ … … 94 94 @return double 95 95 */ 96 double [PYTHONCLASS]_readDouble(PyObject *p) {96 double CEllipticalCylinderModel_readDouble(PyObject *p) { 97 97 if (PyFloat_Check(p)==1) { 98 98 return (double)(((PyFloatObject *)(p))->ob_fval); … … 112 112 * @return: function value 113 113 */ 114 static PyObject * run( [PYTHONCLASS]*self, PyObject *args) {114 static PyObject * run(CEllipticalCylinderModel *self, PyObject *args) { 115 115 double q_value, phi_value; 116 116 PyObject* pars; … … 133 133 // Get input and determine whether we have to supply a 1D or 2D return value. 134 134 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 135 PyErr_SetString( [PYTHONCLASS]Error,136 " [PYTHONCLASS].run expects a q value.");135 PyErr_SetString(CEllipticalCylinderModelError, 136 "CEllipticalCylinderModel.run expects a q value."); 137 137 return NULL; 138 138 } … … 144 144 npars = PyList_GET_SIZE(pars); 145 145 if(npars!=2) { 146 PyErr_SetString( [PYTHONCLASS]Error,147 " [PYTHONCLASS].run expects a double or a list of dimension 2.");146 PyErr_SetString(CEllipticalCylinderModelError, 147 "CEllipticalCylinderModel.run expects a double or a list of dimension 2."); 148 148 return NULL; 149 149 } 150 150 // We have a vector q, get the q and phi values at which 151 151 // to evaluate I(q,phi) 152 q_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0));153 phi_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1));152 q_value = CEllipticalCylinderModel_readDouble(PyList_GET_ITEM(pars,0)); 153 phi_value = CEllipticalCylinderModel_readDouble(PyList_GET_ITEM(pars,1)); 154 154 // Skip zero 155 155 if (q_value==0) { … … 161 161 162 162 // We have a scalar q, we will evaluate I(q) 163 q_value = [PYTHONCLASS]_readDouble(pars);163 q_value = CEllipticalCylinderModel_readDouble(pars); 164 164 165 165 return Py_BuildValue("d",elliptical_cylinder_analytical_1D(&(self->model_pars),q_value)); … … 172 172 * @return: function value 173 173 */ 174 static PyObject * runXY( [PYTHONCLASS]*self, PyObject *args) {174 static PyObject * runXY(CEllipticalCylinderModel *self, PyObject *args) { 175 175 double qx_value, qy_value; 176 176 PyObject* pars; … … 193 193 // Get input and determine whether we have to supply a 1D or 2D return value. 194 194 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 195 PyErr_SetString( [PYTHONCLASS]Error,196 " [PYTHONCLASS].run expects a q value.");195 PyErr_SetString(CEllipticalCylinderModelError, 196 "CEllipticalCylinderModel.run expects a q value."); 197 197 return NULL; 198 198 } … … 204 204 npars = PyList_GET_SIZE(pars); 205 205 if(npars!=2) { 206 PyErr_SetString( [PYTHONCLASS]Error,207 " [PYTHONCLASS].run expects a double or a list of dimension 2.");206 PyErr_SetString(CEllipticalCylinderModelError, 207 "CEllipticalCylinderModel.run expects a double or a list of dimension 2."); 208 208 return NULL; 209 209 } 210 210 // We have a vector q, get the qx and qy values at which 211 211 // to evaluate I(qx,qy) 212 qx_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0));213 qy_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1));212 qx_value = CEllipticalCylinderModel_readDouble(PyList_GET_ITEM(pars,0)); 213 qy_value = CEllipticalCylinderModel_readDouble(PyList_GET_ITEM(pars,1)); 214 214 return Py_BuildValue("d",elliptical_cylinder_analytical_2DXY(&(self->model_pars),qx_value,qy_value)); 215 215 … … 217 217 218 218 // We have a scalar q, we will evaluate I(q) 219 qx_value = [PYTHONCLASS]_readDouble(pars);219 qx_value = CEllipticalCylinderModel_readDouble(pars); 220 220 221 221 return Py_BuildValue("d",elliptical_cylinder_analytical_1D(&(self->model_pars),qx_value)); … … 223 223 } 224 224 225 static PyObject * reset( [PYTHONCLASS]*self, PyObject *args) {225 static PyObject * reset(CEllipticalCylinderModel *self, PyObject *args) { 226 226 227 227 … … 230 230 231 231 232 static PyMethodDef [PYTHONCLASS]_methods[] = {232 static PyMethodDef CEllipticalCylinderModel_methods[] = { 233 233 {"run", (PyCFunction)run , METH_VARARGS, 234 234 "Evaluate the model at a given Q or Q, phi"}, … … 242 242 }; 243 243 244 static PyTypeObject [PYTHONCLASS]Type = {244 static PyTypeObject CEllipticalCylinderModelType = { 245 245 PyObject_HEAD_INIT(NULL) 246 246 0, /*ob_size*/ 247 " [PYTHONCLASS]", /*tp_name*/248 sizeof( [PYTHONCLASS]), /*tp_basicsize*/247 "CEllipticalCylinderModel", /*tp_name*/ 248 sizeof(CEllipticalCylinderModel), /*tp_basicsize*/ 249 249 0, /*tp_itemsize*/ 250 (destructor) [PYTHONCLASS]_dealloc, /*tp_dealloc*/250 (destructor)CEllipticalCylinderModel_dealloc, /*tp_dealloc*/ 251 251 0, /*tp_print*/ 252 252 0, /*tp_getattr*/ … … 264 264 0, /*tp_as_buffer*/ 265 265 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 266 " [PYTHONCLASS]objects", /* tp_doc */266 "CEllipticalCylinderModel objects", /* tp_doc */ 267 267 0, /* tp_traverse */ 268 268 0, /* tp_clear */ … … 271 271 0, /* tp_iter */ 272 272 0, /* tp_iternext */ 273 [PYTHONCLASS]_methods, /* tp_methods */274 [PYTHONCLASS]_members, /* tp_members */273 CEllipticalCylinderModel_methods, /* tp_methods */ 274 CEllipticalCylinderModel_members, /* tp_members */ 275 275 0, /* tp_getset */ 276 276 0, /* tp_base */ … … 279 279 0, /* tp_descr_set */ 280 280 0, /* tp_dictoffset */ 281 (initproc) [PYTHONCLASS]_init, /* tp_init */281 (initproc)CEllipticalCylinderModel_init, /* tp_init */ 282 282 0, /* tp_alloc */ 283 [PYTHONCLASS]_new, /* tp_new */283 CEllipticalCylinderModel_new, /* tp_new */ 284 284 }; 285 285 … … 293 293 * @param module: module to add the class to 294 294 */ 295 void add [PYTHONCLASS](PyObject *module) {295 void addCEllipticalCylinderModel(PyObject *module) { 296 296 PyObject *d; 297 297 298 if (PyType_Ready(& [PYTHONCLASS]Type) < 0)298 if (PyType_Ready(&CEllipticalCylinderModelType) < 0) 299 299 return; 300 300 301 Py_INCREF(& [PYTHONCLASS]Type);302 PyModule_AddObject(module, " [PYTHONCLASS]", (PyObject *)&[PYTHONCLASS]Type);301 Py_INCREF(&CEllipticalCylinderModelType); 302 PyModule_AddObject(module, "CEllipticalCylinderModel", (PyObject *)&CEllipticalCylinderModelType); 303 303 304 304 d = PyModule_GetDict(module); 305 [PYTHONCLASS]Error = PyErr_NewException("[PYTHONCLASS].error", NULL, NULL);306 PyDict_SetItemString(d, " [PYTHONCLASS]Error", [PYTHONCLASS]Error);307 } 308 305 CEllipticalCylinderModelError = PyErr_NewException("CEllipticalCylinderModel.error", NULL, NULL); 306 PyDict_SetItemString(d, "CEllipticalCylinderModelError", CEllipticalCylinderModelError); 307 } 308 -
sansmodels/src/sans/models/c_extensions/CParallelepipedModel.c
r8a48713 ra8d6888 4 4 * 5 5 * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY 6 * DO NOT MODIFY THIS FILE, MODIFY ..\c_extensions\parallelepiped.h6 * DO NOT MODIFY THIS FILE, MODIFY parallelepiped.h 7 7 * AND RE-RUN THE GENERATOR SCRIPT 8 8 * … … 17 17 #include <time.h> 18 18 19 #include " ..\c_extensions\parallelepiped.h"19 #include "parallelepiped.h" 20 20 21 21 /// Error object for raised exceptions … … 62 62 63 63 // Initialize parameter dictionary 64 PyDict_SetItemString(self->params,"short_a",Py_BuildValue("d",35.000000)); 65 PyDict_SetItemString(self->params,"short_b",Py_BuildValue("d",75.000000)); 64 66 PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000)); 65 PyDict_SetItemString(self->params,"long er_edgeB",Py_BuildValue("d",75.000000));66 PyDict_SetItemString(self->params," longuest_edgeC",Py_BuildValue("d",400.000000));67 PyDict_SetItemString(self->params,"parallel_phi",Py_BuildValue("d", 1.000000));68 PyDict_SetItemString(self->params,"parallel_theta",Py_BuildValue("d", 1.000000));67 PyDict_SetItemString(self->params,"long_c",Py_BuildValue("d",400.000000)); 68 PyDict_SetItemString(self->params,"parallel_psi",Py_BuildValue("d",0.000000)); 69 PyDict_SetItemString(self->params,"parallel_phi",Py_BuildValue("d",0.000000)); 70 PyDict_SetItemString(self->params,"parallel_theta",Py_BuildValue("d",0.000000)); 69 71 PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000)); 70 PyDict_SetItemString(self->params,"short_edgeA",Py_BuildValue("d",35.000000));71 72 PyDict_SetItemString(self->params,"contrast",Py_BuildValue("d",0.000005)); 72 73 … … 119 120 120 121 // Reader parameter dictionary 122 self->model_pars.short_a = PyFloat_AsDouble( PyDict_GetItemString(self->params, "short_a") ); 123 self->model_pars.short_b = PyFloat_AsDouble( PyDict_GetItemString(self->params, "short_b") ); 121 124 self->model_pars.scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") ); 122 self->model_pars.long er_edgeB = PyFloat_AsDouble( PyDict_GetItemString(self->params, "longer_edgeB") );123 self->model_pars. longuest_edgeC = PyFloat_AsDouble( PyDict_GetItemString(self->params, "longuest_edgeC") );125 self->model_pars.long_c = PyFloat_AsDouble( PyDict_GetItemString(self->params, "long_c") ); 126 self->model_pars.parallel_psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_psi") ); 124 127 self->model_pars.parallel_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_phi") ); 125 128 self->model_pars.parallel_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_theta") ); 126 129 self->model_pars.background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); 127 self->model_pars.short_edgeA = PyFloat_AsDouble( PyDict_GetItemString(self->params, "short_edgeA") );128 130 self->model_pars.contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") ); 129 131 … … 154 156 return Py_BuildValue("d",0.0); 155 157 } 156 return Py_BuildValue("d", _analytical_2D(&(self->model_pars),q_value,phi_value));158 return Py_BuildValue("d",parallelepiped_analytical_2D(&(self->model_pars),q_value,phi_value)); 157 159 158 160 } else { … … 161 163 q_value = CParallelepipedModel_readDouble(pars); 162 164 163 return Py_BuildValue("d", _analytical_1D(&(self->model_pars),q_value));165 return Py_BuildValue("d",parallelepiped_analytical_1D(&(self->model_pars),q_value)); 164 166 } 165 167 } … … 178 180 179 181 // Reader parameter dictionary 182 self->model_pars.short_a = PyFloat_AsDouble( PyDict_GetItemString(self->params, "short_a") ); 183 self->model_pars.short_b = PyFloat_AsDouble( PyDict_GetItemString(self->params, "short_b") ); 180 184 self->model_pars.scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") ); 181 self->model_pars.long er_edgeB = PyFloat_AsDouble( PyDict_GetItemString(self->params, "longer_edgeB") );182 self->model_pars. longuest_edgeC = PyFloat_AsDouble( PyDict_GetItemString(self->params, "longuest_edgeC") );185 self->model_pars.long_c = PyFloat_AsDouble( PyDict_GetItemString(self->params, "long_c") ); 186 self->model_pars.parallel_psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_psi") ); 183 187 self->model_pars.parallel_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_phi") ); 184 188 self->model_pars.parallel_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_theta") ); 185 189 self->model_pars.background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); 186 self->model_pars.short_edgeA = PyFloat_AsDouble( PyDict_GetItemString(self->params, "short_edgeA") );187 190 self->model_pars.contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") ); 188 191 … … 209 212 qx_value = CParallelepipedModel_readDouble(PyList_GET_ITEM(pars,0)); 210 213 qy_value = CParallelepipedModel_readDouble(PyList_GET_ITEM(pars,1)); 211 return Py_BuildValue("d", _analytical_2DXY(&(self->model_pars),qx_value,qy_value));214 return Py_BuildValue("d",parallelepiped_analytical_2DXY(&(self->model_pars),qx_value,qy_value)); 212 215 213 216 } else { … … 216 219 qx_value = CParallelepipedModel_readDouble(pars); 217 220 218 return Py_BuildValue("d", _analytical_1D(&(self->model_pars),qx_value));221 return Py_BuildValue("d",parallelepiped_analytical_1D(&(self->model_pars),qx_value)); 219 222 } 220 223 } -
sansmodels/src/sans/models/c_extensions/CSphereModel.c
r9316609 ra8d6888 1 /** [PYTHONCLASS]1 /** CSphereModel 2 2 * 3 3 * C extension … … 20 20 21 21 /// Error object for raised exceptions 22 static PyObject * [PYTHONCLASS]Error = NULL;22 static PyObject * CSphereModelError = NULL; 23 23 24 24 … … 32 32 /// Model parameters 33 33 SphereParameters model_pars; 34 } [PYTHONCLASS];34 } CSphereModel; 35 35 36 36 37 37 static void 38 [PYTHONCLASS]_dealloc([PYTHONCLASS]* self)38 CSphereModel_dealloc(CSphereModel* self) 39 39 { 40 40 self->ob_type->tp_free((PyObject*)self); … … 44 44 45 45 static PyObject * 46 [PYTHONCLASS]_new(PyTypeObject *type, PyObject *args, PyObject *kwds)46 CSphereModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 47 47 { 48 [PYTHONCLASS]*self;49 50 self = ( [PYTHONCLASS]*)type->tp_alloc(type, 0);48 CSphereModel *self; 49 50 self = (CSphereModel *)type->tp_alloc(type, 0); 51 51 52 52 return (PyObject *)self; … … 54 54 55 55 static int 56 [PYTHONCLASS]_init([PYTHONCLASS]*self, PyObject *args, PyObject *kwds)56 CSphereModel_init(CSphereModel *self, PyObject *args, PyObject *kwds) 57 57 { 58 58 if (self != NULL) { … … 62 62 63 63 // Initialize parameter dictionary 64 PyDict_SetItemString(self->params,"scale",Py_BuildValue("d", 0.000001));64 PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000)); 65 65 PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",60.000000)); 66 66 PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000)); 67 PyDict_SetItemString(self->params,"contrast",Py_BuildValue("d", 1.000000));67 PyDict_SetItemString(self->params,"contrast",Py_BuildValue("d",0.000001)); 68 68 69 69 … … 77 77 } 78 78 79 static PyMemberDef [PYTHONCLASS]_members[] = {80 {"params", T_OBJECT, offsetof( [PYTHONCLASS], params), 0,79 static PyMemberDef CSphereModel_members[] = { 80 {"params", T_OBJECT, offsetof(CSphereModel, params), 0, 81 81 "Parameters"}, 82 {"log", T_OBJECT, offsetof( [PYTHONCLASS], log), 0,82 {"log", T_OBJECT, offsetof(CSphereModel, log), 0, 83 83 "Log"}, 84 84 {NULL} /* Sentinel */ … … 89 89 @return double 90 90 */ 91 double [PYTHONCLASS]_readDouble(PyObject *p) {91 double CSphereModel_readDouble(PyObject *p) { 92 92 if (PyFloat_Check(p)==1) { 93 93 return (double)(((PyFloatObject *)(p))->ob_fval); … … 107 107 * @return: function value 108 108 */ 109 static PyObject * run( [PYTHONCLASS]*self, PyObject *args) {109 static PyObject * run(CSphereModel *self, PyObject *args) { 110 110 double q_value, phi_value; 111 111 PyObject* pars; … … 123 123 // Get input and determine whether we have to supply a 1D or 2D return value. 124 124 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 125 PyErr_SetString( [PYTHONCLASS]Error,126 " [PYTHONCLASS].run expects a q value.");125 PyErr_SetString(CSphereModelError, 126 "CSphereModel.run expects a q value."); 127 127 return NULL; 128 128 } … … 134 134 npars = PyList_GET_SIZE(pars); 135 135 if(npars!=2) { 136 PyErr_SetString( [PYTHONCLASS]Error,137 " [PYTHONCLASS].run expects a double or a list of dimension 2.");136 PyErr_SetString(CSphereModelError, 137 "CSphereModel.run expects a double or a list of dimension 2."); 138 138 return NULL; 139 139 } 140 140 // We have a vector q, get the q and phi values at which 141 141 // to evaluate I(q,phi) 142 q_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0));143 phi_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1));142 q_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,0)); 143 phi_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,1)); 144 144 // Skip zero 145 145 if (q_value==0) { … … 151 151 152 152 // We have a scalar q, we will evaluate I(q) 153 q_value = [PYTHONCLASS]_readDouble(pars);153 q_value = CSphereModel_readDouble(pars); 154 154 155 155 return Py_BuildValue("d",sphere_analytical_1D(&(self->model_pars),q_value)); … … 162 162 * @return: function value 163 163 */ 164 static PyObject * runXY( [PYTHONCLASS]*self, PyObject *args) {164 static PyObject * runXY(CSphereModel *self, PyObject *args) { 165 165 double qx_value, qy_value; 166 166 PyObject* pars; … … 178 178 // Get input and determine whether we have to supply a 1D or 2D return value. 179 179 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 180 PyErr_SetString( [PYTHONCLASS]Error,181 " [PYTHONCLASS].run expects a q value.");180 PyErr_SetString(CSphereModelError, 181 "CSphereModel.run expects a q value."); 182 182 return NULL; 183 183 } … … 189 189 npars = PyList_GET_SIZE(pars); 190 190 if(npars!=2) { 191 PyErr_SetString( [PYTHONCLASS]Error,192 " [PYTHONCLASS].run expects a double or a list of dimension 2.");191 PyErr_SetString(CSphereModelError, 192 "CSphereModel.run expects a double or a list of dimension 2."); 193 193 return NULL; 194 194 } 195 195 // We have a vector q, get the qx and qy values at which 196 196 // to evaluate I(qx,qy) 197 qx_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0));198 qy_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1));197 qx_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,0)); 198 qy_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,1)); 199 199 return Py_BuildValue("d",sphere_analytical_2DXY(&(self->model_pars),qx_value,qy_value)); 200 200 … … 202 202 203 203 // We have a scalar q, we will evaluate I(q) 204 qx_value = [PYTHONCLASS]_readDouble(pars);204 qx_value = CSphereModel_readDouble(pars); 205 205 206 206 return Py_BuildValue("d",sphere_analytical_1D(&(self->model_pars),qx_value)); … … 208 208 } 209 209 210 static PyObject * reset( [PYTHONCLASS]*self, PyObject *args) {210 static PyObject * reset(CSphereModel *self, PyObject *args) { 211 211 212 212 … … 215 215 216 216 217 static PyMethodDef [PYTHONCLASS]_methods[] = {217 static PyMethodDef CSphereModel_methods[] = { 218 218 {"run", (PyCFunction)run , METH_VARARGS, 219 219 "Evaluate the model at a given Q or Q, phi"}, … … 227 227 }; 228 228 229 static PyTypeObject [PYTHONCLASS]Type = {229 static PyTypeObject CSphereModelType = { 230 230 PyObject_HEAD_INIT(NULL) 231 231 0, /*ob_size*/ 232 " [PYTHONCLASS]", /*tp_name*/233 sizeof( [PYTHONCLASS]), /*tp_basicsize*/232 "CSphereModel", /*tp_name*/ 233 sizeof(CSphereModel), /*tp_basicsize*/ 234 234 0, /*tp_itemsize*/ 235 (destructor) [PYTHONCLASS]_dealloc, /*tp_dealloc*/235 (destructor)CSphereModel_dealloc, /*tp_dealloc*/ 236 236 0, /*tp_print*/ 237 237 0, /*tp_getattr*/ … … 249 249 0, /*tp_as_buffer*/ 250 250 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 251 " [PYTHONCLASS]objects", /* tp_doc */251 "CSphereModel objects", /* tp_doc */ 252 252 0, /* tp_traverse */ 253 253 0, /* tp_clear */ … … 256 256 0, /* tp_iter */ 257 257 0, /* tp_iternext */ 258 [PYTHONCLASS]_methods, /* tp_methods */259 [PYTHONCLASS]_members, /* tp_members */258 CSphereModel_methods, /* tp_methods */ 259 CSphereModel_members, /* tp_members */ 260 260 0, /* tp_getset */ 261 261 0, /* tp_base */ … … 264 264 0, /* tp_descr_set */ 265 265 0, /* tp_dictoffset */ 266 (initproc) [PYTHONCLASS]_init, /* tp_init */266 (initproc)CSphereModel_init, /* tp_init */ 267 267 0, /* tp_alloc */ 268 [PYTHONCLASS]_new, /* tp_new */268 CSphereModel_new, /* tp_new */ 269 269 }; 270 270 … … 278 278 * @param module: module to add the class to 279 279 */ 280 void add [PYTHONCLASS](PyObject *module) {280 void addCSphereModel(PyObject *module) { 281 281 PyObject *d; 282 282 283 if (PyType_Ready(& [PYTHONCLASS]Type) < 0)283 if (PyType_Ready(&CSphereModelType) < 0) 284 284 return; 285 285 286 Py_INCREF(& [PYTHONCLASS]Type);287 PyModule_AddObject(module, " [PYTHONCLASS]", (PyObject *)&[PYTHONCLASS]Type);286 Py_INCREF(&CSphereModelType); 287 PyModule_AddObject(module, "CSphereModel", (PyObject *)&CSphereModelType); 288 288 289 289 d = PyModule_GetDict(module); 290 [PYTHONCLASS]Error = PyErr_NewException("[PYTHONCLASS].error", NULL, NULL);291 PyDict_SetItemString(d, " [PYTHONCLASS]Error", [PYTHONCLASS]Error);292 } 293 290 CSphereModelError = PyErr_NewException("CSphereModel.error", NULL, NULL); 291 PyDict_SetItemString(d, "CSphereModelError", CSphereModelError); 292 } 293 -
sansmodels/src/sans/models/c_models/CBinaryHSModel.cpp
r975ec8e ra8d6888 18 18 * 19 19 * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY 20 * DO NOT MODIFY THIS FILE, MODIFY binaryH S.h20 * DO NOT MODIFY THIS FILE, MODIFY binaryHs.h 21 21 * AND RE-RUN THE GENERATOR SCRIPT 22 22 * … … 33 33 #include <math.h> 34 34 #include <time.h> 35 #include "binaryH S.h"35 #include "binaryHs.h" 36 36 } 37 37 … … 191 191 192 192 if (PyArray_Check(x) && PyArray_Check(y)) { 193 x_len = dims[0]= x->dimensions[0]; 194 y_len = dims[1]= y->dimensions[1]; 193 194 x_len = dims[1]= x->dimensions[1]; 195 y_len = dims[0]= y->dimensions[0]; 195 196 196 197 // Make a new double matrix of same dims … … 205 206 for ( i=0; i< x_len; i++) { 206 207 for ( j=0; j< y_len; j++) { 207 double x_value = *(double *)(x->data + i*x->strides[ 0]);208 double y_value = *(double *)(y->data + j*y->strides[ 1]);208 double x_value = *(double *)(x->data + i*x->strides[1]); 209 double y_value = *(double *)(y->data + j*y->strides[0]); 209 210 double *result_value = (double *)(result->data + 210 i*result->strides[ 0] + j*result->strides[1]);211 i*result->strides[1] + j*result->strides[0]); 211 212 *result_value = (*model)(x_value, y_value); 212 213 } -
sansmodels/src/sans/models/c_models/CBinaryHSPSF11Model.cpp
r9bd69098 ra8d6888 170 170 return PyArray_Return(result); 171 171 } 172 /** 173 * Function to call to evaluate model 174 * @param args: input numpy array [q[],phi[]] 175 * @return: numpy array object 176 */ 177 static PyObject * evaluateTwoDim( BinaryHSPSF11Model* model, 178 PyArrayObject *q, PyArrayObject *phi) 179 { 180 PyArrayObject *result; 181 //check validity of input vectors 182 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 183 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 184 || phi->dimensions[0] != q->dimensions[0]){ 185 186 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 187 PyErr_SetString(PyExc_ValueError ,"wrong input"); 188 return NULL; 189 } 190 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 191 192 if (result == NULL){ 193 const char * message= "Could not create result "; 194 PyErr_SetString(PyExc_RuntimeError , message); 195 return NULL; 196 } 197 198 for (int i = 0; i < q->dimensions[0]; i++) { 199 double q_value = *(double *)(q->data + i*q->strides[0]); 200 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 201 double *result_value = (double *)(result->data + i*result->strides[0]); 202 if (q_value == 0) 203 *result_value = 0.0; 204 else 205 *result_value = model->evaluate_rphi(q_value, phi_value); 206 } 207 return PyArray_Return(result); 208 } 172 209 173 /** 210 174 * Function to call to evaluate model … … 227 191 228 192 if (PyArray_Check(x) && PyArray_Check(y)) { 229 x_len = dims[0]= x->dimensions[0]; 230 y_len = dims[1]= y->dimensions[1]; 193 194 x_len = dims[1]= x->dimensions[1]; 195 y_len = dims[0]= y->dimensions[0]; 231 196 232 197 // Make a new double matrix of same dims … … 241 206 for ( i=0; i< x_len; i++) { 242 207 for ( j=0; j< y_len; j++) { 243 double x_value = *(double *)(x->data + i*x->strides[ 0]);244 double y_value = *(double *)(y->data + j*y->strides[ 1]);208 double x_value = *(double *)(x->data + i*x->strides[1]); 209 double y_value = *(double *)(y->data + j*y->strides[0]); 245 210 double *result_value = (double *)(result->data + 246 i*result->strides[ 0] + j*result->strides[1]);211 i*result->strides[1] + j*result->strides[0]); 247 212 *result_value = (*model)(x_value, y_value); 248 213 } -
sansmodels/src/sans/models/c_models/CCoreShellCylinderModel.cpp
r9bd69098 ra8d6888 181 181 return PyArray_Return(result); 182 182 } 183 /** 184 * Function to call to evaluate model 185 * @param args: input numpy array [q[],phi[]] 186 * @return: numpy array object 187 */ 188 static PyObject * evaluateTwoDim( CoreShellCylinderModel* model, 189 PyArrayObject *q, PyArrayObject *phi) 190 { 191 PyArrayObject *result; 192 //check validity of input vectors 193 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 194 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 195 || phi->dimensions[0] != q->dimensions[0]){ 196 197 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 198 PyErr_SetString(PyExc_ValueError ,"wrong input"); 199 return NULL; 200 } 201 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 202 203 if (result == NULL){ 204 const char * message= "Could not create result "; 205 PyErr_SetString(PyExc_RuntimeError , message); 206 return NULL; 207 } 208 209 for (int i = 0; i < q->dimensions[0]; i++) { 210 double q_value = *(double *)(q->data + i*q->strides[0]); 211 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 212 double *result_value = (double *)(result->data + i*result->strides[0]); 213 if (q_value == 0) 214 *result_value = 0.0; 215 else 216 *result_value = model->evaluate_rphi(q_value, phi_value); 217 } 218 return PyArray_Return(result); 219 } 183 220 184 /** 221 185 * Function to call to evaluate model … … 238 202 239 203 if (PyArray_Check(x) && PyArray_Check(y)) { 240 x_len = dims[0]= x->dimensions[0]; 241 y_len = dims[1]= y->dimensions[1]; 204 205 x_len = dims[1]= x->dimensions[1]; 206 y_len = dims[0]= y->dimensions[0]; 242 207 243 208 // Make a new double matrix of same dims … … 252 217 for ( i=0; i< x_len; i++) { 253 218 for ( j=0; j< y_len; j++) { 254 double x_value = *(double *)(x->data + i*x->strides[ 0]);255 double y_value = *(double *)(y->data + j*y->strides[ 1]);219 double x_value = *(double *)(x->data + i*x->strides[1]); 220 double y_value = *(double *)(y->data + j*y->strides[0]); 256 221 double *result_value = (double *)(result->data + 257 i*result->strides[ 0] + j*result->strides[1]);222 i*result->strides[1] + j*result->strides[0]); 258 223 *result_value = (*model)(x_value, y_value); 259 224 } -
sansmodels/src/sans/models/c_models/CCoreShellEllipsoidModel.cpp
reddff027 ra8d6888 205 205 206 206 if (PyArray_Check(x) && PyArray_Check(y)) { 207 x_len = dims[0]= x->dimensions[0]; 208 y_len = dims[1]= y->dimensions[1]; 207 208 x_len = dims[1]= x->dimensions[1]; 209 y_len = dims[0]= y->dimensions[0]; 209 210 210 211 // Make a new double matrix of same dims … … 219 220 for ( i=0; i< x_len; i++) { 220 221 for ( j=0; j< y_len; j++) { 221 double x_value = *(double *)(x->data + i*x->strides[ 0]);222 double y_value = *(double *)(y->data + j*y->strides[ 1]);222 double x_value = *(double *)(x->data + i*x->strides[1]); 223 double y_value = *(double *)(y->data + j*y->strides[0]); 223 224 double *result_value = (double *)(result->data + 224 i*result->strides[ 0] + j*result->strides[1]);225 i*result->strides[1] + j*result->strides[0]); 225 226 *result_value = (*model)(x_value, y_value); 226 227 } -
sansmodels/src/sans/models/c_models/CCoreShellModel.cpp
r9bd69098 ra8d6888 169 169 return PyArray_Return(result); 170 170 } 171 /** 172 * Function to call to evaluate model 173 * @param args: input numpy array [q[],phi[]] 174 * @return: numpy array object 175 */ 176 static PyObject * evaluateTwoDim( CoreShellModel* model, 177 PyArrayObject *q, PyArrayObject *phi) 178 { 179 PyArrayObject *result; 180 //check validity of input vectors 181 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 182 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 183 || phi->dimensions[0] != q->dimensions[0]){ 184 185 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 186 PyErr_SetString(PyExc_ValueError ,"wrong input"); 187 return NULL; 188 } 189 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 190 191 if (result == NULL){ 192 const char * message= "Could not create result "; 193 PyErr_SetString(PyExc_RuntimeError , message); 194 return NULL; 195 } 196 197 for (int i = 0; i < q->dimensions[0]; i++) { 198 double q_value = *(double *)(q->data + i*q->strides[0]); 199 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 200 double *result_value = (double *)(result->data + i*result->strides[0]); 201 if (q_value == 0) 202 *result_value = 0.0; 203 else 204 *result_value = model->evaluate_rphi(q_value, phi_value); 205 } 206 return PyArray_Return(result); 207 } 171 208 172 /** 209 173 * Function to call to evaluate model … … 226 190 227 191 if (PyArray_Check(x) && PyArray_Check(y)) { 228 x_len = dims[0]= x->dimensions[0]; 229 y_len = dims[1]= y->dimensions[1]; 192 193 x_len = dims[1]= x->dimensions[1]; 194 y_len = dims[0]= y->dimensions[0]; 230 195 231 196 // Make a new double matrix of same dims … … 240 205 for ( i=0; i< x_len; i++) { 241 206 for ( j=0; j< y_len; j++) { 242 double x_value = *(double *)(x->data + i*x->strides[ 0]);243 double y_value = *(double *)(y->data + j*y->strides[ 1]);207 double x_value = *(double *)(x->data + i*x->strides[1]); 208 double y_value = *(double *)(y->data + j*y->strides[0]); 244 209 double *result_value = (double *)(result->data + 245 i*result->strides[ 0] + j*result->strides[1]);210 i*result->strides[1] + j*result->strides[0]); 246 211 *result_value = (*model)(x_value, y_value); 247 212 } -
sansmodels/src/sans/models/c_models/CCylinderModel.cpp
r975ec8e ra8d6888 196 196 197 197 if (PyArray_Check(x) && PyArray_Check(y)) { 198 x_len = dims[0]= x->dimensions[0]; 199 y_len = dims[1]= y->dimensions[1]; 198 199 x_len = dims[1]= x->dimensions[1]; 200 y_len = dims[0]= y->dimensions[0]; 200 201 201 202 // Make a new double matrix of same dims … … 210 211 for ( i=0; i< x_len; i++) { 211 212 for ( j=0; j< y_len; j++) { 212 double x_value = *(double *)(x->data + i*x->strides[ 0]);213 double y_value = *(double *)(y->data + j*y->strides[ 1]);213 double x_value = *(double *)(x->data + i*x->strides[1]); 214 double y_value = *(double *)(y->data + j*y->strides[0]); 214 215 double *result_value = (double *)(result->data + 215 i*result->strides[ 0] + j*result->strides[1]);216 i*result->strides[1] + j*result->strides[0]); 216 217 *result_value = (*model)(x_value, y_value); 217 218 } -
sansmodels/src/sans/models/c_models/CDiamCylFunc.cpp
r9bd69098 ra8d6888 164 164 return PyArray_Return(result); 165 165 } 166 /** 167 * Function to call to evaluate model 168 * @param args: input numpy array [q[],phi[]] 169 * @return: numpy array object 170 */ 171 static PyObject * evaluateTwoDim( DiamCylFunc* model, 172 PyArrayObject *q, PyArrayObject *phi) 173 { 174 PyArrayObject *result; 175 //check validity of input vectors 176 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 177 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 178 || phi->dimensions[0] != q->dimensions[0]){ 179 180 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 181 PyErr_SetString(PyExc_ValueError ,"wrong input"); 182 return NULL; 183 } 184 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 185 186 if (result == NULL){ 187 const char * message= "Could not create result "; 188 PyErr_SetString(PyExc_RuntimeError , message); 189 return NULL; 190 } 191 192 for (int i = 0; i < q->dimensions[0]; i++) { 193 double q_value = *(double *)(q->data + i*q->strides[0]); 194 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 195 double *result_value = (double *)(result->data + i*result->strides[0]); 196 if (q_value == 0) 197 *result_value = 0.0; 198 else 199 *result_value = model->evaluate_rphi(q_value, phi_value); 200 } 201 return PyArray_Return(result); 202 } 166 203 167 /** 204 168 * Function to call to evaluate model … … 221 185 222 186 if (PyArray_Check(x) && PyArray_Check(y)) { 223 x_len = dims[0]= x->dimensions[0]; 224 y_len = dims[1]= y->dimensions[1]; 187 188 x_len = dims[1]= x->dimensions[1]; 189 y_len = dims[0]= y->dimensions[0]; 225 190 226 191 // Make a new double matrix of same dims … … 235 200 for ( i=0; i< x_len; i++) { 236 201 for ( j=0; j< y_len; j++) { 237 double x_value = *(double *)(x->data + i*x->strides[ 0]);238 double y_value = *(double *)(y->data + j*y->strides[ 1]);202 double x_value = *(double *)(x->data + i*x->strides[1]); 203 double y_value = *(double *)(y->data + j*y->strides[0]); 239 204 double *result_value = (double *)(result->data + 240 i*result->strides[ 0] + j*result->strides[1]);205 i*result->strides[1] + j*result->strides[0]); 241 206 *result_value = (*model)(x_value, y_value); 242 207 } -
sansmodels/src/sans/models/c_models/CDiamEllipFunc.cpp
r63c2095 ra8d6888 22 22 * 23 23 */ 24 #define NO_IMPORT_ARRAY 25 #define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans 24 26 25 27 extern "C" { 26 28 #include <Python.h> 29 #include <arrayobject.h> 27 30 #include "structmember.h" 28 31 #include <stdio.h> … … 131 134 } 132 135 } 133 136 /** 137 * Function to call to evaluate model 138 * @param args: input numpy array q[] 139 * @return: numpy array object 140 */ 141 142 static PyObject *evaluateOneDim(DiamEllipFunc* model, PyArrayObject *q){ 143 PyArrayObject *result; 144 145 // Check validity of array q , q must be of dimension 1, an array of double 146 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE) 147 { 148 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 149 //PyErr_SetString(PyExc_ValueError , message); 150 return NULL; 151 } 152 result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), 153 PyArray_DOUBLE); 154 if (result == NULL) { 155 const char * message= "Could not create result "; 156 PyErr_SetString(PyExc_RuntimeError , message); 157 return NULL; 158 } 159 for (int i = 0; i < q->dimensions[0]; i++){ 160 double q_value = *(double *)(q->data + i*q->strides[0]); 161 double *result_value = (double *)(result->data + i*result->strides[0]); 162 *result_value =(*model)(q_value); 163 } 164 return PyArray_Return(result); 165 } 166 167 /** 168 * Function to call to evaluate model 169 * @param args: input numpy array [x[],y[]] 170 * @return: numpy array object 171 */ 172 static PyObject * evaluateTwoDimXY( DiamEllipFunc* model, 173 PyArrayObject *x, PyArrayObject *y) 174 { 175 PyArrayObject *result; 176 int i,j, x_len, y_len, dims[2]; 177 //check validity of input vectors 178 if (x->nd != 2 || x->descr->type_num != PyArray_DOUBLE 179 || y->nd != 2 || y->descr->type_num != PyArray_DOUBLE 180 || y->dimensions[1] != x->dimensions[0]){ 181 const char * message= "evaluateTwoDimXY expect 2 numpy arrays"; 182 PyErr_SetString(PyExc_ValueError , message); 183 return NULL; 184 } 185 186 if (PyArray_Check(x) && PyArray_Check(y)) { 187 188 x_len = dims[1]= x->dimensions[1]; 189 y_len = dims[0]= y->dimensions[0]; 190 191 // Make a new double matrix of same dims 192 result=(PyArrayObject *) PyArray_FromDims(2,dims,NPY_DOUBLE); 193 if (result == NULL){ 194 const char * message= "Could not create result "; 195 PyErr_SetString(PyExc_RuntimeError , message); 196 return NULL; 197 } 198 199 /* Do the calculation. */ 200 for ( i=0; i< x_len; i++) { 201 for ( j=0; j< y_len; j++) { 202 double x_value = *(double *)(x->data + i*x->strides[1]); 203 double y_value = *(double *)(y->data + j*y->strides[0]); 204 double *result_value = (double *)(result->data + 205 i*result->strides[1] + j*result->strides[0]); 206 *result_value = (*model)(x_value, y_value); 207 } 208 } 209 return PyArray_Return(result); 210 211 }else{ 212 PyErr_SetString(CDiamEllipFuncError, 213 "CDiamEllipFunc.evaluateTwoDimXY couldn't run."); 214 return NULL; 215 } 216 } 217 /** 218 * evalDistribution function evaluate a model function with input vector 219 * @param args: input q as vector or [qx, qy] where qx, qy are vectors 220 * 221 */ 222 static PyObject * evalDistribution(CDiamEllipFunc *self, PyObject *args){ 223 PyObject *qx, *qy; 224 PyArrayObject * pars; 225 int npars ,mpars; 226 227 // Get parameters 228 229 // Reader parameter dictionary 230 self->model->radius_b = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_b") ); 231 self->model->radius_a = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_a") ); 232 // Read in dispersion parameters 233 PyObject* disp_dict; 234 DispersionVisitor* visitor = new DispersionVisitor(); 235 disp_dict = PyDict_GetItemString(self->dispersion, "radius_a"); 236 self->model->radius_a.dispersion->accept_as_destination(visitor, self->model->radius_a.dispersion, disp_dict); 237 disp_dict = PyDict_GetItemString(self->dispersion, "radius_b"); 238 self->model->radius_b.dispersion->accept_as_destination(visitor, self->model->radius_b.dispersion, disp_dict); 239 240 241 // Get input and determine whether we have to supply a 1D or 2D return value. 242 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 243 PyErr_SetString(CDiamEllipFuncError, 244 "CDiamEllipFunc.evalDistribution expects a q value."); 245 return NULL; 246 } 247 // Check params 248 249 if(PyArray_Check(pars)==1) { 250 251 // Length of list should 1 or 2 252 npars = pars->nd; 253 if(npars==1) { 254 // input is a numpy array 255 if (PyArray_Check(pars)) { 256 return evaluateOneDim(self->model, (PyArrayObject*)pars); 257 } 258 }else{ 259 PyErr_SetString(CDiamEllipFuncError, 260 "CDiamEllipFunc.evalDistribution expect numpy array of one dimension."); 261 return NULL; 262 } 263 }else if( PyList_Check(pars)==1) { 264 // Length of list should be 2 for I(qx,qy) 265 mpars = PyList_GET_SIZE(pars); 266 if(mpars!=2) { 267 PyErr_SetString(CDiamEllipFuncError, 268 "CDiamEllipFunc.evalDistribution expects a list of dimension 2."); 269 return NULL; 270 } 271 qx = PyList_GET_ITEM(pars,0); 272 qy = PyList_GET_ITEM(pars,1); 273 if (PyArray_Check(qx) && PyArray_Check(qy)) { 274 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx, 275 (PyArrayObject*)qy); 276 }else{ 277 PyErr_SetString(CDiamEllipFuncError, 278 "CDiamEllipFunc.evalDistribution expect 2 numpy arrays in list."); 279 return NULL; 280 } 281 }else{ 282 PyErr_SetString(CDiamEllipFuncError, 283 "CDiamEllipFunc.evalDistribution couln't be run."); 284 return NULL; 285 } 286 } 134 287 135 288 /** … … 293 446 {"runXY", (PyCFunction)runXY , METH_VARARGS, 294 447 "Evaluate the model at a given Q or Qx, Qy"}, 448 449 {"evalDistribution", (PyCFunction)evalDistribution , METH_VARARGS, 450 "Evaluate the model at a given Q or Qx, Qy vector "}, 295 451 {"reset", (PyCFunction)reset , METH_VARARGS, 296 452 "Reset pair correlation"}, … … 343 499 344 500 345 static PyMethodDef module_methods[] = {346 {NULL}347 };501 //static PyMethodDef module_methods[] = { 502 // {NULL} 503 //}; 348 504 349 505 /** -
sansmodels/src/sans/models/c_models/CEllipsoidModel.cpp
r975ec8e ra8d6888 196 196 197 197 if (PyArray_Check(x) && PyArray_Check(y)) { 198 x_len = dims[0]= x->dimensions[0]; 199 y_len = dims[1]= y->dimensions[1]; 198 199 x_len = dims[1]= x->dimensions[1]; 200 y_len = dims[0]= y->dimensions[0]; 200 201 201 202 // Make a new double matrix of same dims … … 210 211 for ( i=0; i< x_len; i++) { 211 212 for ( j=0; j< y_len; j++) { 212 double x_value = *(double *)(x->data + i*x->strides[ 0]);213 double y_value = *(double *)(y->data + j*y->strides[ 1]);213 double x_value = *(double *)(x->data + i*x->strides[1]); 214 double y_value = *(double *)(y->data + j*y->strides[0]); 214 215 double *result_value = (double *)(result->data + 215 i*result->strides[ 0] + j*result->strides[1]);216 i*result->strides[1] + j*result->strides[0]); 216 217 *result_value = (*model)(x_value, y_value); 217 218 } -
sansmodels/src/sans/models/c_models/CEllipticalCylinderModel.cpp
r975ec8e ra8d6888 204 204 205 205 if (PyArray_Check(x) && PyArray_Check(y)) { 206 x_len = dims[0]= x->dimensions[0]; 207 y_len = dims[1]= y->dimensions[1]; 206 207 x_len = dims[1]= x->dimensions[1]; 208 y_len = dims[0]= y->dimensions[0]; 208 209 209 210 // Make a new double matrix of same dims … … 218 219 for ( i=0; i< x_len; i++) { 219 220 for ( j=0; j< y_len; j++) { 220 double x_value = *(double *)(x->data + i*x->strides[ 0]);221 double y_value = *(double *)(y->data + j*y->strides[ 1]);221 double x_value = *(double *)(x->data + i*x->strides[1]); 222 double y_value = *(double *)(y->data + j*y->strides[0]); 222 223 double *result_value = (double *)(result->data + 223 i*result->strides[ 0] + j*result->strides[1]);224 i*result->strides[1] + j*result->strides[0]); 224 225 *result_value = (*model)(x_value, y_value); 225 226 } -
sansmodels/src/sans/models/c_models/CFlexibleCylinderModel.cpp
r9bd69098 ra8d6888 171 171 return PyArray_Return(result); 172 172 } 173 /** 174 * Function to call to evaluate model 175 * @param args: input numpy array [q[],phi[]] 176 * @return: numpy array object 177 */ 178 static PyObject * evaluateTwoDim( FlexibleCylinderModel* model, 179 PyArrayObject *q, PyArrayObject *phi) 180 { 181 PyArrayObject *result; 182 //check validity of input vectors 183 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 184 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 185 || phi->dimensions[0] != q->dimensions[0]){ 186 187 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 188 PyErr_SetString(PyExc_ValueError ,"wrong input"); 189 return NULL; 190 } 191 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 192 193 if (result == NULL){ 194 const char * message= "Could not create result "; 195 PyErr_SetString(PyExc_RuntimeError , message); 196 return NULL; 197 } 198 199 for (int i = 0; i < q->dimensions[0]; i++) { 200 double q_value = *(double *)(q->data + i*q->strides[0]); 201 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 202 double *result_value = (double *)(result->data + i*result->strides[0]); 203 if (q_value == 0) 204 *result_value = 0.0; 205 else 206 *result_value = model->evaluate_rphi(q_value, phi_value); 207 } 208 return PyArray_Return(result); 209 } 173 210 174 /** 211 175 * Function to call to evaluate model … … 228 192 229 193 if (PyArray_Check(x) && PyArray_Check(y)) { 230 x_len = dims[0]= x->dimensions[0]; 231 y_len = dims[1]= y->dimensions[1]; 194 195 x_len = dims[1]= x->dimensions[1]; 196 y_len = dims[0]= y->dimensions[0]; 232 197 233 198 // Make a new double matrix of same dims … … 242 207 for ( i=0; i< x_len; i++) { 243 208 for ( j=0; j< y_len; j++) { 244 double x_value = *(double *)(x->data + i*x->strides[ 0]);245 double y_value = *(double *)(y->data + j*y->strides[ 1]);209 double x_value = *(double *)(x->data + i*x->strides[1]); 210 double y_value = *(double *)(y->data + j*y->strides[0]); 246 211 double *result_value = (double *)(result->data + 247 i*result->strides[ 0] + j*result->strides[1]);212 i*result->strides[1] + j*result->strides[0]); 248 213 *result_value = (*model)(x_value, y_value); 249 214 } -
sansmodels/src/sans/models/c_models/CGaussian.cpp
r9bd69098 ra8d6888 159 159 return PyArray_Return(result); 160 160 } 161 /** 162 * Function to call to evaluate model 163 * @param args: input numpy array [q[],phi[]] 164 * @return: numpy array object 165 */ 166 static PyObject * evaluateTwoDim( Gaussian* model, 167 PyArrayObject *q, PyArrayObject *phi) 168 { 169 PyArrayObject *result; 170 //check validity of input vectors 171 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 172 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 173 || phi->dimensions[0] != q->dimensions[0]){ 174 175 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 176 PyErr_SetString(PyExc_ValueError ,"wrong input"); 177 return NULL; 178 } 179 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 180 181 if (result == NULL){ 182 const char * message= "Could not create result "; 183 PyErr_SetString(PyExc_RuntimeError , message); 184 return NULL; 185 } 186 187 for (int i = 0; i < q->dimensions[0]; i++) { 188 double q_value = *(double *)(q->data + i*q->strides[0]); 189 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 190 double *result_value = (double *)(result->data + i*result->strides[0]); 191 if (q_value == 0) 192 *result_value = 0.0; 193 else 194 *result_value = model->evaluate_rphi(q_value, phi_value); 195 } 196 return PyArray_Return(result); 197 } 161 198 162 /** 199 163 * Function to call to evaluate model … … 216 180 217 181 if (PyArray_Check(x) && PyArray_Check(y)) { 218 x_len = dims[0]= x->dimensions[0]; 219 y_len = dims[1]= y->dimensions[1]; 182 183 x_len = dims[1]= x->dimensions[1]; 184 y_len = dims[0]= y->dimensions[0]; 220 185 221 186 // Make a new double matrix of same dims … … 230 195 for ( i=0; i< x_len; i++) { 231 196 for ( j=0; j< y_len; j++) { 232 double x_value = *(double *)(x->data + i*x->strides[ 0]);233 double y_value = *(double *)(y->data + j*y->strides[ 1]);197 double x_value = *(double *)(x->data + i*x->strides[1]); 198 double y_value = *(double *)(y->data + j*y->strides[0]); 234 199 double *result_value = (double *)(result->data + 235 i*result->strides[ 0] + j*result->strides[1]);200 i*result->strides[1] + j*result->strides[0]); 236 201 *result_value = (*model)(x_value, y_value); 237 202 } -
sansmodels/src/sans/models/c_models/CHardsphereStructure.cpp
r9bd69098 ra8d6888 161 161 return PyArray_Return(result); 162 162 } 163 /** 164 * Function to call to evaluate model 165 * @param args: input numpy array [q[],phi[]] 166 * @return: numpy array object 167 */ 168 static PyObject * evaluateTwoDim( HardsphereStructure* model, 169 PyArrayObject *q, PyArrayObject *phi) 170 { 171 PyArrayObject *result; 172 //check validity of input vectors 173 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 174 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 175 || phi->dimensions[0] != q->dimensions[0]){ 176 177 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 178 PyErr_SetString(PyExc_ValueError ,"wrong input"); 179 return NULL; 180 } 181 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 182 183 if (result == NULL){ 184 const char * message= "Could not create result "; 185 PyErr_SetString(PyExc_RuntimeError , message); 186 return NULL; 187 } 188 189 for (int i = 0; i < q->dimensions[0]; i++) { 190 double q_value = *(double *)(q->data + i*q->strides[0]); 191 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 192 double *result_value = (double *)(result->data + i*result->strides[0]); 193 if (q_value == 0) 194 *result_value = 0.0; 195 else 196 *result_value = model->evaluate_rphi(q_value, phi_value); 197 } 198 return PyArray_Return(result); 199 } 163 200 164 /** 201 165 * Function to call to evaluate model … … 218 182 219 183 if (PyArray_Check(x) && PyArray_Check(y)) { 220 x_len = dims[0]= x->dimensions[0]; 221 y_len = dims[1]= y->dimensions[1]; 184 185 x_len = dims[1]= x->dimensions[1]; 186 y_len = dims[0]= y->dimensions[0]; 222 187 223 188 // Make a new double matrix of same dims … … 232 197 for ( i=0; i< x_len; i++) { 233 198 for ( j=0; j< y_len; j++) { 234 double x_value = *(double *)(x->data + i*x->strides[ 0]);235 double y_value = *(double *)(y->data + j*y->strides[ 1]);199 double x_value = *(double *)(x->data + i*x->strides[1]); 200 double y_value = *(double *)(y->data + j*y->strides[0]); 236 201 double *result_value = (double *)(result->data + 237 i*result->strides[ 0] + j*result->strides[1]);202 i*result->strides[1] + j*result->strides[0]); 238 203 *result_value = (*model)(x_value, y_value); 239 204 } -
sansmodels/src/sans/models/c_models/CHayterMSAStructure.cpp
r9bd69098 ra8d6888 165 165 return PyArray_Return(result); 166 166 } 167 /** 168 * Function to call to evaluate model 169 * @param args: input numpy array [q[],phi[]] 170 * @return: numpy array object 171 */ 172 static PyObject * evaluateTwoDim( HayterMSAStructure* model, 173 PyArrayObject *q, PyArrayObject *phi) 174 { 175 PyArrayObject *result; 176 //check validity of input vectors 177 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 178 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 179 || phi->dimensions[0] != q->dimensions[0]){ 180 181 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 182 PyErr_SetString(PyExc_ValueError ,"wrong input"); 183 return NULL; 184 } 185 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 186 187 if (result == NULL){ 188 const char * message= "Could not create result "; 189 PyErr_SetString(PyExc_RuntimeError , message); 190 return NULL; 191 } 192 193 for (int i = 0; i < q->dimensions[0]; i++) { 194 double q_value = *(double *)(q->data + i*q->strides[0]); 195 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 196 double *result_value = (double *)(result->data + i*result->strides[0]); 197 if (q_value == 0) 198 *result_value = 0.0; 199 else 200 *result_value = model->evaluate_rphi(q_value, phi_value); 201 } 202 return PyArray_Return(result); 203 } 167 204 168 /** 205 169 * Function to call to evaluate model … … 222 186 223 187 if (PyArray_Check(x) && PyArray_Check(y)) { 224 x_len = dims[0]= x->dimensions[0]; 225 y_len = dims[1]= y->dimensions[1]; 188 189 x_len = dims[1]= x->dimensions[1]; 190 y_len = dims[0]= y->dimensions[0]; 226 191 227 192 // Make a new double matrix of same dims … … 236 201 for ( i=0; i< x_len; i++) { 237 202 for ( j=0; j< y_len; j++) { 238 double x_value = *(double *)(x->data + i*x->strides[ 0]);239 double y_value = *(double *)(y->data + j*y->strides[ 1]);203 double x_value = *(double *)(x->data + i*x->strides[1]); 204 double y_value = *(double *)(y->data + j*y->strides[0]); 240 205 double *result_value = (double *)(result->data + 241 i*result->strides[ 0] + j*result->strides[1]);206 i*result->strides[1] + j*result->strides[0]); 242 207 *result_value = (*model)(x_value, y_value); 243 208 } -
sansmodels/src/sans/models/c_models/CHollowCylinderModel.cpp
r9bd69098 ra8d6888 179 179 return PyArray_Return(result); 180 180 } 181 /** 182 * Function to call to evaluate model 183 * @param args: input numpy array [q[],phi[]] 184 * @return: numpy array object 185 */ 186 static PyObject * evaluateTwoDim( HollowCylinderModel* model, 187 PyArrayObject *q, PyArrayObject *phi) 188 { 189 PyArrayObject *result; 190 //check validity of input vectors 191 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 192 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 193 || phi->dimensions[0] != q->dimensions[0]){ 194 195 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 196 PyErr_SetString(PyExc_ValueError ,"wrong input"); 197 return NULL; 198 } 199 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 200 201 if (result == NULL){ 202 const char * message= "Could not create result "; 203 PyErr_SetString(PyExc_RuntimeError , message); 204 return NULL; 205 } 206 207 for (int i = 0; i < q->dimensions[0]; i++) { 208 double q_value = *(double *)(q->data + i*q->strides[0]); 209 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 210 double *result_value = (double *)(result->data + i*result->strides[0]); 211 if (q_value == 0) 212 *result_value = 0.0; 213 else 214 *result_value = model->evaluate_rphi(q_value, phi_value); 215 } 216 return PyArray_Return(result); 217 } 181 218 182 /** 219 183 * Function to call to evaluate model … … 236 200 237 201 if (PyArray_Check(x) && PyArray_Check(y)) { 238 x_len = dims[0]= x->dimensions[0]; 239 y_len = dims[1]= y->dimensions[1]; 202 203 x_len = dims[1]= x->dimensions[1]; 204 y_len = dims[0]= y->dimensions[0]; 240 205 241 206 // Make a new double matrix of same dims … … 250 215 for ( i=0; i< x_len; i++) { 251 216 for ( j=0; j< y_len; j++) { 252 double x_value = *(double *)(x->data + i*x->strides[ 0]);253 double y_value = *(double *)(y->data + j*y->strides[ 1]);217 double x_value = *(double *)(x->data + i*x->strides[1]); 218 double y_value = *(double *)(y->data + j*y->strides[0]); 254 219 double *result_value = (double *)(result->data + 255 i*result->strides[ 0] + j*result->strides[1]);220 i*result->strides[1] + j*result->strides[0]); 256 221 *result_value = (*model)(x_value, y_value); 257 222 } -
sansmodels/src/sans/models/c_models/CLamellarFFHGModel.cpp
r9bd69098 ra8d6888 169 169 return PyArray_Return(result); 170 170 } 171 /** 172 * Function to call to evaluate model 173 * @param args: input numpy array [q[],phi[]] 174 * @return: numpy array object 175 */ 176 static PyObject * evaluateTwoDim( LamellarFFHGModel* model, 177 PyArrayObject *q, PyArrayObject *phi) 178 { 179 PyArrayObject *result; 180 //check validity of input vectors 181 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 182 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 183 || phi->dimensions[0] != q->dimensions[0]){ 184 185 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 186 PyErr_SetString(PyExc_ValueError ,"wrong input"); 187 return NULL; 188 } 189 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 190 191 if (result == NULL){ 192 const char * message= "Could not create result "; 193 PyErr_SetString(PyExc_RuntimeError , message); 194 return NULL; 195 } 196 197 for (int i = 0; i < q->dimensions[0]; i++) { 198 double q_value = *(double *)(q->data + i*q->strides[0]); 199 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 200 double *result_value = (double *)(result->data + i*result->strides[0]); 201 if (q_value == 0) 202 *result_value = 0.0; 203 else 204 *result_value = model->evaluate_rphi(q_value, phi_value); 205 } 206 return PyArray_Return(result); 207 } 171 208 172 /** 209 173 * Function to call to evaluate model … … 226 190 227 191 if (PyArray_Check(x) && PyArray_Check(y)) { 228 x_len = dims[0]= x->dimensions[0]; 229 y_len = dims[1]= y->dimensions[1]; 192 193 x_len = dims[1]= x->dimensions[1]; 194 y_len = dims[0]= y->dimensions[0]; 230 195 231 196 // Make a new double matrix of same dims … … 240 205 for ( i=0; i< x_len; i++) { 241 206 for ( j=0; j< y_len; j++) { 242 double x_value = *(double *)(x->data + i*x->strides[ 0]);243 double y_value = *(double *)(y->data + j*y->strides[ 1]);207 double x_value = *(double *)(x->data + i*x->strides[1]); 208 double y_value = *(double *)(y->data + j*y->strides[0]); 244 209 double *result_value = (double *)(result->data + 245 i*result->strides[ 0] + j*result->strides[1]);210 i*result->strides[1] + j*result->strides[0]); 246 211 *result_value = (*model)(x_value, y_value); 247 212 } -
sansmodels/src/sans/models/c_models/CLamellarModel.cpp
r975ec8e ra8d6888 185 185 186 186 if (PyArray_Check(x) && PyArray_Check(y)) { 187 x_len = dims[0]= x->dimensions[0]; 188 y_len = dims[1]= y->dimensions[1]; 187 188 x_len = dims[1]= x->dimensions[1]; 189 y_len = dims[0]= y->dimensions[0]; 189 190 190 191 // Make a new double matrix of same dims … … 199 200 for ( i=0; i< x_len; i++) { 200 201 for ( j=0; j< y_len; j++) { 201 double x_value = *(double *)(x->data + i*x->strides[ 0]);202 double y_value = *(double *)(y->data + j*y->strides[ 1]);202 double x_value = *(double *)(x->data + i*x->strides[1]); 203 double y_value = *(double *)(y->data + j*y->strides[0]); 203 204 double *result_value = (double *)(result->data + 204 i*result->strides[ 0] + j*result->strides[1]);205 i*result->strides[1] + j*result->strides[0]); 205 206 *result_value = (*model)(x_value, y_value); 206 207 } -
sansmodels/src/sans/models/c_models/CLamellarPSHGModel.cpp
r96b59384 ra8d6888 22 22 * 23 23 */ 24 #define NO_IMPORT_ARRAY 25 #define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans 24 26 25 27 extern "C" { 26 28 #include <Python.h> 29 #include <arrayobject.h> 27 30 #include "structmember.h" 28 31 #include <stdio.h> … … 142 145 } 143 146 } 144 145 146 147 /** 147 148 * Function to call to evaluate model 148 * @param args: input q or [q,phi]149 * @return: function value149 * @param args: input numpy array q[] 150 * @return: numpy array object 150 151 */ 151 static PyObject * run(CLamellarPSHGModel *self, PyObject *args) { 152 double q_value, phi_value; 153 PyObject* pars; 154 int npars; 152 153 static PyObject *evaluateOneDim(LamellarPSHGModel* model, PyArrayObject *q){ 154 PyArrayObject *result; 155 156 // Check validity of array q , q must be of dimension 1, an array of double 157 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE) 158 { 159 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 160 //PyErr_SetString(PyExc_ValueError , message); 161 return NULL; 162 } 163 result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), 164 PyArray_DOUBLE); 165 if (result == NULL) { 166 const char * message= "Could not create result "; 167 PyErr_SetString(PyExc_RuntimeError , message); 168 return NULL; 169 } 170 for (int i = 0; i < q->dimensions[0]; i++){ 171 double q_value = *(double *)(q->data + i*q->strides[0]); 172 double *result_value = (double *)(result->data + i*result->strides[0]); 173 *result_value =(*model)(q_value); 174 } 175 return PyArray_Return(result); 176 } 177 178 /** 179 * Function to call to evaluate model 180 * @param args: input numpy array [x[],y[]] 181 * @return: numpy array object 182 */ 183 static PyObject * evaluateTwoDimXY( LamellarPSHGModel* model, 184 PyArrayObject *x, PyArrayObject *y) 185 { 186 PyArrayObject *result; 187 int i,j, x_len, y_len, dims[2]; 188 //check validity of input vectors 189 if (x->nd != 2 || x->descr->type_num != PyArray_DOUBLE 190 || y->nd != 2 || y->descr->type_num != PyArray_DOUBLE 191 || y->dimensions[1] != x->dimensions[0]){ 192 const char * message= "evaluateTwoDimXY expect 2 numpy arrays"; 193 PyErr_SetString(PyExc_ValueError , message); 194 return NULL; 195 } 196 197 if (PyArray_Check(x) && PyArray_Check(y)) { 198 199 x_len = dims[1]= x->dimensions[1]; 200 y_len = dims[0]= y->dimensions[0]; 201 202 // Make a new double matrix of same dims 203 result=(PyArrayObject *) PyArray_FromDims(2,dims,NPY_DOUBLE); 204 if (result == NULL){ 205 const char * message= "Could not create result "; 206 PyErr_SetString(PyExc_RuntimeError , message); 207 return NULL; 208 } 209 210 /* Do the calculation. */ 211 for ( i=0; i< x_len; i++) { 212 for ( j=0; j< y_len; j++) { 213 double x_value = *(double *)(x->data + i*x->strides[1]); 214 double y_value = *(double *)(y->data + j*y->strides[0]); 215 double *result_value = (double *)(result->data + 216 i*result->strides[1] + j*result->strides[0]); 217 *result_value = (*model)(x_value, y_value); 218 } 219 } 220 return PyArray_Return(result); 221 222 }else{ 223 PyErr_SetString(CLamellarPSHGModelError, 224 "CLamellarPSHGModel.evaluateTwoDimXY couldn't run."); 225 return NULL; 226 } 227 } 228 /** 229 * evalDistribution function evaluate a model function with input vector 230 * @param args: input q as vector or [qx, qy] where qx, qy are vectors 231 * 232 */ 233 static PyObject * evalDistribution(CLamellarPSHGModel *self, PyObject *args){ 234 PyObject *qx, *qy; 235 PyArrayObject * pars; 236 int npars ,mpars; 155 237 156 238 // Get parameters … … 181 263 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 182 264 PyErr_SetString(CLamellarPSHGModelError, 265 "CLamellarPSHGModel.evalDistribution expects a q value."); 266 return NULL; 267 } 268 // Check params 269 270 if(PyArray_Check(pars)==1) { 271 272 // Length of list should 1 or 2 273 npars = pars->nd; 274 if(npars==1) { 275 // input is a numpy array 276 if (PyArray_Check(pars)) { 277 return evaluateOneDim(self->model, (PyArrayObject*)pars); 278 } 279 }else{ 280 PyErr_SetString(CLamellarPSHGModelError, 281 "CLamellarPSHGModel.evalDistribution expect numpy array of one dimension."); 282 return NULL; 283 } 284 }else if( PyList_Check(pars)==1) { 285 // Length of list should be 2 for I(qx,qy) 286 mpars = PyList_GET_SIZE(pars); 287 if(mpars!=2) { 288 PyErr_SetString(CLamellarPSHGModelError, 289 "CLamellarPSHGModel.evalDistribution expects a list of dimension 2."); 290 return NULL; 291 } 292 qx = PyList_GET_ITEM(pars,0); 293 qy = PyList_GET_ITEM(pars,1); 294 if (PyArray_Check(qx) && PyArray_Check(qy)) { 295 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx, 296 (PyArrayObject*)qy); 297 }else{ 298 PyErr_SetString(CLamellarPSHGModelError, 299 "CLamellarPSHGModel.evalDistribution expect 2 numpy arrays in list."); 300 return NULL; 301 } 302 }else{ 303 PyErr_SetString(CLamellarPSHGModelError, 304 "CLamellarPSHGModel.evalDistribution couln't be run."); 305 return NULL; 306 } 307 } 308 309 /** 310 * Function to call to evaluate model 311 * @param args: input q or [q,phi] 312 * @return: function value 313 */ 314 static PyObject * run(CLamellarPSHGModel *self, PyObject *args) { 315 double q_value, phi_value; 316 PyObject* pars; 317 int npars; 318 319 // Get parameters 320 321 // Reader parameter dictionary 322 self->model->n_plates = PyFloat_AsDouble( PyDict_GetItemString(self->params, "n_plates") ); 323 self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") ); 324 self->model->deltaT = PyFloat_AsDouble( PyDict_GetItemString(self->params, "deltaT") ); 325 self->model->spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "spacing") ); 326 self->model->sld_tail = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_tail") ); 327 self->model->sld_solvent = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solvent") ); 328 self->model->caille = PyFloat_AsDouble( PyDict_GetItemString(self->params, "caille") ); 329 self->model->sld_head = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_head") ); 330 self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); 331 self->model->deltaH = PyFloat_AsDouble( PyDict_GetItemString(self->params, "deltaH") ); 332 // Read in dispersion parameters 333 PyObject* disp_dict; 334 DispersionVisitor* visitor = new DispersionVisitor(); 335 disp_dict = PyDict_GetItemString(self->dispersion, "deltaT"); 336 self->model->deltaT.dispersion->accept_as_destination(visitor, self->model->deltaT.dispersion, disp_dict); 337 disp_dict = PyDict_GetItemString(self->dispersion, "deltaH"); 338 self->model->deltaH.dispersion->accept_as_destination(visitor, self->model->deltaH.dispersion, disp_dict); 339 disp_dict = PyDict_GetItemString(self->dispersion, "spacing"); 340 self->model->spacing.dispersion->accept_as_destination(visitor, self->model->spacing.dispersion, disp_dict); 341 342 343 // Get input and determine whether we have to supply a 1D or 2D return value. 344 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 345 PyErr_SetString(CLamellarPSHGModelError, 183 346 "CLamellarPSHGModel.run expects a q value."); 184 347 return NULL; … … 326 489 {"runXY", (PyCFunction)runXY , METH_VARARGS, 327 490 "Evaluate the model at a given Q or Qx, Qy"}, 491 492 {"evalDistribution", (PyCFunction)evalDistribution , METH_VARARGS, 493 "Evaluate the model at a given Q or Qx, Qy vector "}, 328 494 {"reset", (PyCFunction)reset , METH_VARARGS, 329 495 "Reset pair correlation"}, … … 376 542 377 543 378 static PyMethodDef module_methods[] = {379 {NULL}380 };544 //static PyMethodDef module_methods[] = { 545 // {NULL} 546 //}; 381 547 382 548 /** -
sansmodels/src/sans/models/c_models/CLamellarPSModel.cpp
rc1c29b6 ra8d6888 190 190 191 191 if (PyArray_Check(x) && PyArray_Check(y)) { 192 x_len = dims[0]= x->dimensions[0]; 193 y_len = dims[1]= y->dimensions[1]; 192 193 x_len = dims[1]= x->dimensions[1]; 194 y_len = dims[0]= y->dimensions[0]; 194 195 195 196 // Make a new double matrix of same dims … … 204 205 for ( i=0; i< x_len; i++) { 205 206 for ( j=0; j< y_len; j++) { 206 double x_value = *(double *)(x->data + i*x->strides[ 0]);207 double y_value = *(double *)(y->data + j*y->strides[ 1]);207 double x_value = *(double *)(x->data + i*x->strides[1]); 208 double y_value = *(double *)(y->data + j*y->strides[0]); 208 209 double *result_value = (double *)(result->data + 209 i*result->strides[ 0] + j*result->strides[1]);210 i*result->strides[1] + j*result->strides[0]); 210 211 *result_value = (*model)(x_value, y_value); 211 212 } -
sansmodels/src/sans/models/c_models/CLogNormal.cpp
r5b56b7a ra8d6888 159 159 return PyArray_Return(result); 160 160 } 161 /** 162 * Function to call to evaluate model 163 * @param args: input numpy array [q[],phi[]] 164 * @return: numpy array object 165 */ 166 static PyObject * evaluateTwoDim( LogNormal* model, 167 PyArrayObject *q, PyArrayObject *phi) 168 { 169 PyArrayObject *result; 170 //check validity of input vectors 171 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 172 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 173 || phi->dimensions[0] != q->dimensions[0]){ 174 175 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 176 PyErr_SetString(PyExc_ValueError ,"wrong input"); 177 return NULL; 178 } 179 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 180 181 if (result == NULL){ 182 const char * message= "Could not create result "; 183 PyErr_SetString(PyExc_RuntimeError , message); 184 return NULL; 185 } 186 187 for (int i = 0; i < q->dimensions[0]; i++) { 188 double q_value = *(double *)(q->data + i*q->strides[0]); 189 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 190 double *result_value = (double *)(result->data + i*result->strides[0]); 191 if (q_value == 0) 192 *result_value = 0.0; 193 else 194 *result_value = model->evaluate_rphi(q_value, phi_value); 195 } 196 return PyArray_Return(result); 197 } 161 198 162 /** 199 163 * Function to call to evaluate model … … 216 180 217 181 if (PyArray_Check(x) && PyArray_Check(y)) { 218 x_len = dims[0]= x->dimensions[0]; 219 y_len = dims[1]= y->dimensions[1]; 182 183 x_len = dims[1]= x->dimensions[1]; 184 y_len = dims[0]= y->dimensions[0]; 220 185 221 186 // Make a new double matrix of same dims … … 230 195 for ( i=0; i< x_len; i++) { 231 196 for ( j=0; j< y_len; j++) { 232 double x_value = *(double *)(x->data + i*x->strides[ 0]);233 double y_value = *(double *)(y->data + j*y->strides[ 1]);197 double x_value = *(double *)(x->data + i*x->strides[1]); 198 double y_value = *(double *)(y->data + j*y->strides[0]); 234 199 double *result_value = (double *)(result->data + 235 i*result->strides[ 0] + j*result->strides[1]);200 i*result->strides[1] + j*result->strides[0]); 236 201 *result_value = (*model)(x_value, y_value); 237 202 } -
sansmodels/src/sans/models/c_models/CLorentzian.cpp
r9bd69098 ra8d6888 159 159 return PyArray_Return(result); 160 160 } 161 /** 162 * Function to call to evaluate model 163 * @param args: input numpy array [q[],phi[]] 164 * @return: numpy array object 165 */ 166 static PyObject * evaluateTwoDim( Lorentzian* model, 167 PyArrayObject *q, PyArrayObject *phi) 168 { 169 PyArrayObject *result; 170 //check validity of input vectors 171 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 172 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 173 || phi->dimensions[0] != q->dimensions[0]){ 174 175 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 176 PyErr_SetString(PyExc_ValueError ,"wrong input"); 177 return NULL; 178 } 179 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 180 181 if (result == NULL){ 182 const char * message= "Could not create result "; 183 PyErr_SetString(PyExc_RuntimeError , message); 184 return NULL; 185 } 186 187 for (int i = 0; i < q->dimensions[0]; i++) { 188 double q_value = *(double *)(q->data + i*q->strides[0]); 189 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 190 double *result_value = (double *)(result->data + i*result->strides[0]); 191 if (q_value == 0) 192 *result_value = 0.0; 193 else 194 *result_value = model->evaluate_rphi(q_value, phi_value); 195 } 196 return PyArray_Return(result); 197 } 161 198 162 /** 199 163 * Function to call to evaluate model … … 216 180 217 181 if (PyArray_Check(x) && PyArray_Check(y)) { 218 x_len = dims[0]= x->dimensions[0]; 219 y_len = dims[1]= y->dimensions[1]; 182 183 x_len = dims[1]= x->dimensions[1]; 184 y_len = dims[0]= y->dimensions[0]; 220 185 221 186 // Make a new double matrix of same dims … … 230 195 for ( i=0; i< x_len; i++) { 231 196 for ( j=0; j< y_len; j++) { 232 double x_value = *(double *)(x->data + i*x->strides[ 0]);233 double y_value = *(double *)(y->data + j*y->strides[ 1]);197 double x_value = *(double *)(x->data + i*x->strides[1]); 198 double y_value = *(double *)(y->data + j*y->strides[0]); 234 199 double *result_value = (double *)(result->data + 235 i*result->strides[ 0] + j*result->strides[1]);200 i*result->strides[1] + j*result->strides[0]); 236 201 *result_value = (*model)(x_value, y_value); 237 202 } -
sansmodels/src/sans/models/c_models/CMultiShellModel.cpp
r9bd69098 ra8d6888 173 173 return PyArray_Return(result); 174 174 } 175 /** 176 * Function to call to evaluate model 177 * @param args: input numpy array [q[],phi[]] 178 * @return: numpy array object 179 */ 180 static PyObject * evaluateTwoDim( MultiShellModel* model, 181 PyArrayObject *q, PyArrayObject *phi) 182 { 183 PyArrayObject *result; 184 //check validity of input vectors 185 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 186 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 187 || phi->dimensions[0] != q->dimensions[0]){ 188 189 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 190 PyErr_SetString(PyExc_ValueError ,"wrong input"); 191 return NULL; 192 } 193 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 194 195 if (result == NULL){ 196 const char * message= "Could not create result "; 197 PyErr_SetString(PyExc_RuntimeError , message); 198 return NULL; 199 } 200 201 for (int i = 0; i < q->dimensions[0]; i++) { 202 double q_value = *(double *)(q->data + i*q->strides[0]); 203 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 204 double *result_value = (double *)(result->data + i*result->strides[0]); 205 if (q_value == 0) 206 *result_value = 0.0; 207 else 208 *result_value = model->evaluate_rphi(q_value, phi_value); 209 } 210 return PyArray_Return(result); 211 } 175 212 176 /** 213 177 * Function to call to evaluate model … … 230 194 231 195 if (PyArray_Check(x) && PyArray_Check(y)) { 232 x_len = dims[0]= x->dimensions[0]; 233 y_len = dims[1]= y->dimensions[1]; 196 197 x_len = dims[1]= x->dimensions[1]; 198 y_len = dims[0]= y->dimensions[0]; 234 199 235 200 // Make a new double matrix of same dims … … 244 209 for ( i=0; i< x_len; i++) { 245 210 for ( j=0; j< y_len; j++) { 246 double x_value = *(double *)(x->data + i*x->strides[ 0]);247 double y_value = *(double *)(y->data + j*y->strides[ 1]);211 double x_value = *(double *)(x->data + i*x->strides[1]); 212 double y_value = *(double *)(y->data + j*y->strides[0]); 248 213 double *result_value = (double *)(result->data + 249 i*result->strides[ 0] + j*result->strides[1]);214 i*result->strides[1] + j*result->strides[0]); 250 215 *result_value = (*model)(x_value, y_value); 251 216 } -
sansmodels/src/sans/models/c_models/COblateModel.cpp
r975ec8e ra8d6888 199 199 200 200 if (PyArray_Check(x) && PyArray_Check(y)) { 201 x_len = dims[0]= x->dimensions[0]; 202 y_len = dims[1]= y->dimensions[1]; 201 202 x_len = dims[1]= x->dimensions[1]; 203 y_len = dims[0]= y->dimensions[0]; 203 204 204 205 // Make a new double matrix of same dims … … 213 214 for ( i=0; i< x_len; i++) { 214 215 for ( j=0; j< y_len; j++) { 215 double x_value = *(double *)(x->data + i*x->strides[ 0]);216 double y_value = *(double *)(y->data + j*y->strides[ 1]);216 double x_value = *(double *)(x->data + i*x->strides[1]); 217 double y_value = *(double *)(y->data + j*y->strides[0]); 217 218 double *result_value = (double *)(result->data + 218 i*result->strides[ 0] + j*result->strides[1]);219 i*result->strides[1] + j*result->strides[0]); 219 220 *result_value = (*model)(x_value, y_value); 220 221 } -
sansmodels/src/sans/models/c_models/CParallelepipedModel.cpp
r8e36cdd ra8d6888 204 204 205 205 if (PyArray_Check(x) && PyArray_Check(y)) { 206 x_len = dims[0]= x->dimensions[0]; 207 y_len = dims[1]= y->dimensions[1]; 206 207 x_len = dims[1]= x->dimensions[1]; 208 y_len = dims[0]= y->dimensions[0]; 208 209 209 210 // Make a new double matrix of same dims … … 218 219 for ( i=0; i< x_len; i++) { 219 220 for ( j=0; j< y_len; j++) { 220 double x_value = *(double *)(x->data + i*x->strides[ 0]);221 double y_value = *(double *)(y->data + j*y->strides[ 1]);221 double x_value = *(double *)(x->data + i*x->strides[1]); 222 double y_value = *(double *)(y->data + j*y->strides[0]); 222 223 double *result_value = (double *)(result->data + 223 i*result->strides[ 0] + j*result->strides[1]);224 i*result->strides[1] + j*result->strides[0]); 224 225 *result_value = (*model)(x_value, y_value); 225 226 } -
sansmodels/src/sans/models/c_models/CProlateModel.cpp
r9bd69098 ra8d6888 176 176 return PyArray_Return(result); 177 177 } 178 /** 179 * Function to call to evaluate model 180 * @param args: input numpy array [q[],phi[]] 181 * @return: numpy array object 182 */ 183 static 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 } 178 215 179 /** 216 180 * Function to call to evaluate model … … 233 197 234 198 if (PyArray_Check(x) && PyArray_Check(y)) { 235 x_len = dims[0]= x->dimensions[0]; 236 y_len = dims[1]= y->dimensions[1]; 199 200 x_len = dims[1]= x->dimensions[1]; 201 y_len = dims[0]= y->dimensions[0]; 237 202 238 203 // Make a new double matrix of same dims … … 247 212 for ( i=0; i< x_len; i++) { 248 213 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]);214 double x_value = *(double *)(x->data + i*x->strides[1]); 215 double y_value = *(double *)(y->data + j*y->strides[0]); 251 216 double *result_value = (double *)(result->data + 252 i*result->strides[ 0] + j*result->strides[1]);217 i*result->strides[1] + j*result->strides[0]); 253 218 *result_value = (*model)(x_value, y_value); 254 219 } -
sansmodels/src/sans/models/c_models/CSphereModel.cpp
r975ec8e ra8d6888 184 184 185 185 if (PyArray_Check(x) && PyArray_Check(y)) { 186 x_len = dims[0]= x->dimensions[0]; 187 y_len = dims[1]= y->dimensions[1]; 186 187 x_len = dims[1]= x->dimensions[1]; 188 y_len = dims[0]= y->dimensions[0]; 188 189 189 190 // Make a new double matrix of same dims … … 198 199 for ( i=0; i< x_len; i++) { 199 200 for ( j=0; j< y_len; j++) { 200 double x_value = *(double *)(x->data + i*x->strides[ 0]);201 double y_value = *(double *)(y->data + j*y->strides[ 1]);201 double x_value = *(double *)(x->data + i*x->strides[1]); 202 double y_value = *(double *)(y->data + j*y->strides[0]); 202 203 double *result_value = (double *)(result->data + 203 i*result->strides[ 0] + j*result->strides[1]);204 i*result->strides[1] + j*result->strides[0]); 204 205 *result_value = (*model)(x_value, y_value); 205 206 } -
sansmodels/src/sans/models/c_models/CSquareWellStructure.cpp
r9bd69098 ra8d6888 163 163 return PyArray_Return(result); 164 164 } 165 /** 166 * Function to call to evaluate model 167 * @param args: input numpy array [q[],phi[]] 168 * @return: numpy array object 169 */ 170 static PyObject * evaluateTwoDim( SquareWellStructure* model, 171 PyArrayObject *q, PyArrayObject *phi) 172 { 173 PyArrayObject *result; 174 //check validity of input vectors 175 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 176 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 177 || phi->dimensions[0] != q->dimensions[0]){ 178 179 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 180 PyErr_SetString(PyExc_ValueError ,"wrong input"); 181 return NULL; 182 } 183 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 184 185 if (result == NULL){ 186 const char * message= "Could not create result "; 187 PyErr_SetString(PyExc_RuntimeError , message); 188 return NULL; 189 } 190 191 for (int i = 0; i < q->dimensions[0]; i++) { 192 double q_value = *(double *)(q->data + i*q->strides[0]); 193 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 194 double *result_value = (double *)(result->data + i*result->strides[0]); 195 if (q_value == 0) 196 *result_value = 0.0; 197 else 198 *result_value = model->evaluate_rphi(q_value, phi_value); 199 } 200 return PyArray_Return(result); 201 } 165 202 166 /** 203 167 * Function to call to evaluate model … … 220 184 221 185 if (PyArray_Check(x) && PyArray_Check(y)) { 222 x_len = dims[0]= x->dimensions[0]; 223 y_len = dims[1]= y->dimensions[1]; 186 187 x_len = dims[1]= x->dimensions[1]; 188 y_len = dims[0]= y->dimensions[0]; 224 189 225 190 // Make a new double matrix of same dims … … 234 199 for ( i=0; i< x_len; i++) { 235 200 for ( j=0; j< y_len; j++) { 236 double x_value = *(double *)(x->data + i*x->strides[ 0]);237 double y_value = *(double *)(y->data + j*y->strides[ 1]);201 double x_value = *(double *)(x->data + i*x->strides[1]); 202 double y_value = *(double *)(y->data + j*y->strides[0]); 238 203 double *result_value = (double *)(result->data + 239 i*result->strides[ 0] + j*result->strides[1]);204 i*result->strides[1] + j*result->strides[0]); 240 205 *result_value = (*model)(x_value, y_value); 241 206 } -
sansmodels/src/sans/models/c_models/CStackedDisksModel.cpp
r975ec8e ra8d6888 204 204 205 205 if (PyArray_Check(x) && PyArray_Check(y)) { 206 x_len = dims[0]= x->dimensions[0]; 207 y_len = dims[1]= y->dimensions[1]; 206 207 x_len = dims[1]= x->dimensions[1]; 208 y_len = dims[0]= y->dimensions[0]; 208 209 209 210 // Make a new double matrix of same dims … … 218 219 for ( i=0; i< x_len; i++) { 219 220 for ( j=0; j< y_len; j++) { 220 double x_value = *(double *)(x->data + i*x->strides[ 0]);221 double y_value = *(double *)(y->data + j*y->strides[ 1]);221 double x_value = *(double *)(x->data + i*x->strides[1]); 222 double y_value = *(double *)(y->data + j*y->strides[0]); 222 223 double *result_value = (double *)(result->data + 223 i*result->strides[ 0] + j*result->strides[1]);224 i*result->strides[1] + j*result->strides[0]); 224 225 *result_value = (*model)(x_value, y_value); 225 226 } -
sansmodels/src/sans/models/c_models/CStickyHSStructure.cpp
r9bd69098 ra8d6888 163 163 return PyArray_Return(result); 164 164 } 165 /** 166 * Function to call to evaluate model 167 * @param args: input numpy array [q[],phi[]] 168 * @return: numpy array object 169 */ 170 static PyObject * evaluateTwoDim( StickyHSStructure* model, 171 PyArrayObject *q, PyArrayObject *phi) 172 { 173 PyArrayObject *result; 174 //check validity of input vectors 175 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 176 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 177 || phi->dimensions[0] != q->dimensions[0]){ 178 179 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 180 PyErr_SetString(PyExc_ValueError ,"wrong input"); 181 return NULL; 182 } 183 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 184 185 if (result == NULL){ 186 const char * message= "Could not create result "; 187 PyErr_SetString(PyExc_RuntimeError , message); 188 return NULL; 189 } 190 191 for (int i = 0; i < q->dimensions[0]; i++) { 192 double q_value = *(double *)(q->data + i*q->strides[0]); 193 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 194 double *result_value = (double *)(result->data + i*result->strides[0]); 195 if (q_value == 0) 196 *result_value = 0.0; 197 else 198 *result_value = model->evaluate_rphi(q_value, phi_value); 199 } 200 return PyArray_Return(result); 201 } 165 202 166 /** 203 167 * Function to call to evaluate model … … 220 184 221 185 if (PyArray_Check(x) && PyArray_Check(y)) { 222 x_len = dims[0]= x->dimensions[0]; 223 y_len = dims[1]= y->dimensions[1]; 186 187 x_len = dims[1]= x->dimensions[1]; 188 y_len = dims[0]= y->dimensions[0]; 224 189 225 190 // Make a new double matrix of same dims … … 234 199 for ( i=0; i< x_len; i++) { 235 200 for ( j=0; j< y_len; j++) { 236 double x_value = *(double *)(x->data + i*x->strides[ 0]);237 double y_value = *(double *)(y->data + j*y->strides[ 1]);201 double x_value = *(double *)(x->data + i*x->strides[1]); 202 double y_value = *(double *)(y->data + j*y->strides[0]); 238 203 double *result_value = (double *)(result->data + 239 i*result->strides[ 0] + j*result->strides[1]);204 i*result->strides[1] + j*result->strides[0]); 240 205 *result_value = (*model)(x_value, y_value); 241 206 } -
sansmodels/src/sans/models/c_models/CTriaxialEllipsoidModel.cpp
r3c102d4 ra8d6888 195 195 196 196 if (PyArray_Check(x) && PyArray_Check(y)) { 197 x_len = dims[0]= x->dimensions[0]; 198 y_len = dims[1]= y->dimensions[1]; 197 198 x_len = dims[1]= x->dimensions[1]; 199 y_len = dims[0]= y->dimensions[0]; 199 200 200 201 // Make a new double matrix of same dims … … 209 210 for ( i=0; i< x_len; i++) { 210 211 for ( j=0; j< y_len; j++) { 211 double x_value = *(double *)(x->data + i*x->strides[ 0]);212 double y_value = *(double *)(y->data + j*y->strides[ 1]);212 double x_value = *(double *)(x->data + i*x->strides[1]); 213 double y_value = *(double *)(y->data + j*y->strides[0]); 213 214 double *result_value = (double *)(result->data + 214 i*result->strides[ 0] + j*result->strides[1]);215 i*result->strides[1] + j*result->strides[0]); 215 216 *result_value = (*model)(x_value, y_value); 216 217 } -
sansmodels/src/sans/models/c_models/CVesicleModel.cpp
r42f193a ra8d6888 22 22 * 23 23 */ 24 #define NO_IMPORT_ARRAY 25 #define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans 24 26 25 27 extern "C" { 26 28 #include <Python.h> 29 #include <arrayobject.h> 27 30 #include "structmember.h" 28 31 #include <stdio.h> … … 135 138 } 136 139 } 137 140 /** 141 * Function to call to evaluate model 142 * @param args: input numpy array q[] 143 * @return: numpy array object 144 */ 145 146 static PyObject *evaluateOneDim(VesicleModel* model, PyArrayObject *q){ 147 PyArrayObject *result; 148 149 // Check validity of array q , q must be of dimension 1, an array of double 150 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE) 151 { 152 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 153 //PyErr_SetString(PyExc_ValueError , message); 154 return NULL; 155 } 156 result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), 157 PyArray_DOUBLE); 158 if (result == NULL) { 159 const char * message= "Could not create result "; 160 PyErr_SetString(PyExc_RuntimeError , message); 161 return NULL; 162 } 163 for (int i = 0; i < q->dimensions[0]; i++){ 164 double q_value = *(double *)(q->data + i*q->strides[0]); 165 double *result_value = (double *)(result->data + i*result->strides[0]); 166 *result_value =(*model)(q_value); 167 } 168 return PyArray_Return(result); 169 } 170 171 /** 172 * Function to call to evaluate model 173 * @param args: input numpy array [x[],y[]] 174 * @return: numpy array object 175 */ 176 static PyObject * evaluateTwoDimXY( VesicleModel* model, 177 PyArrayObject *x, PyArrayObject *y) 178 { 179 PyArrayObject *result; 180 int i,j, x_len, y_len, dims[2]; 181 //check validity of input vectors 182 if (x->nd != 2 || x->descr->type_num != PyArray_DOUBLE 183 || y->nd != 2 || y->descr->type_num != PyArray_DOUBLE 184 || y->dimensions[1] != x->dimensions[0]){ 185 const char * message= "evaluateTwoDimXY expect 2 numpy arrays"; 186 PyErr_SetString(PyExc_ValueError , message); 187 return NULL; 188 } 189 190 if (PyArray_Check(x) && PyArray_Check(y)) { 191 192 x_len = dims[1]= x->dimensions[1]; 193 y_len = dims[0]= y->dimensions[0]; 194 195 // Make a new double matrix of same dims 196 result=(PyArrayObject *) PyArray_FromDims(2,dims,NPY_DOUBLE); 197 if (result == NULL){ 198 const char * message= "Could not create result "; 199 PyErr_SetString(PyExc_RuntimeError , message); 200 return NULL; 201 } 202 203 /* Do the calculation. */ 204 for ( i=0; i< x_len; i++) { 205 for ( j=0; j< y_len; j++) { 206 double x_value = *(double *)(x->data + i*x->strides[1]); 207 double y_value = *(double *)(y->data + j*y->strides[0]); 208 double *result_value = (double *)(result->data + 209 i*result->strides[1] + j*result->strides[0]); 210 *result_value = (*model)(x_value, y_value); 211 } 212 } 213 return PyArray_Return(result); 214 215 }else{ 216 PyErr_SetString(CVesicleModelError, 217 "CVesicleModel.evaluateTwoDimXY couldn't run."); 218 return NULL; 219 } 220 } 221 /** 222 * evalDistribution function evaluate a model function with input vector 223 * @param args: input q as vector or [qx, qy] where qx, qy are vectors 224 * 225 */ 226 static PyObject * evalDistribution(CVesicleModel *self, PyObject *args){ 227 PyObject *qx, *qy; 228 PyArrayObject * pars; 229 int npars ,mpars; 230 231 // Get parameters 232 233 // Reader parameter dictionary 234 self->model->core_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_sld") ); 235 self->model->core_radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_radius") ); 236 self->model->thickness = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thickness") ); 237 self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") ); 238 self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); 239 self->model->shell_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "shell_sld") ); 240 // Read in dispersion parameters 241 PyObject* disp_dict; 242 DispersionVisitor* visitor = new DispersionVisitor(); 243 disp_dict = PyDict_GetItemString(self->dispersion, "core_radius"); 244 self->model->core_radius.dispersion->accept_as_destination(visitor, self->model->core_radius.dispersion, disp_dict); 245 disp_dict = PyDict_GetItemString(self->dispersion, "thickness"); 246 self->model->thickness.dispersion->accept_as_destination(visitor, self->model->thickness.dispersion, disp_dict); 247 248 249 // Get input and determine whether we have to supply a 1D or 2D return value. 250 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 251 PyErr_SetString(CVesicleModelError, 252 "CVesicleModel.evalDistribution expects a q value."); 253 return NULL; 254 } 255 // Check params 256 257 if(PyArray_Check(pars)==1) { 258 259 // Length of list should 1 or 2 260 npars = pars->nd; 261 if(npars==1) { 262 // input is a numpy array 263 if (PyArray_Check(pars)) { 264 return evaluateOneDim(self->model, (PyArrayObject*)pars); 265 } 266 }else{ 267 PyErr_SetString(CVesicleModelError, 268 "CVesicleModel.evalDistribution expect numpy array of one dimension."); 269 return NULL; 270 } 271 }else if( PyList_Check(pars)==1) { 272 // Length of list should be 2 for I(qx,qy) 273 mpars = PyList_GET_SIZE(pars); 274 if(mpars!=2) { 275 PyErr_SetString(CVesicleModelError, 276 "CVesicleModel.evalDistribution expects a list of dimension 2."); 277 return NULL; 278 } 279 qx = PyList_GET_ITEM(pars,0); 280 qy = PyList_GET_ITEM(pars,1); 281 if (PyArray_Check(qx) && PyArray_Check(qy)) { 282 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx, 283 (PyArrayObject*)qy); 284 }else{ 285 PyErr_SetString(CVesicleModelError, 286 "CVesicleModel.evalDistribution expect 2 numpy arrays in list."); 287 return NULL; 288 } 289 }else{ 290 PyErr_SetString(CVesicleModelError, 291 "CVesicleModel.evalDistribution couln't be run."); 292 return NULL; 293 } 294 } 138 295 139 296 /** … … 305 462 {"runXY", (PyCFunction)runXY , METH_VARARGS, 306 463 "Evaluate the model at a given Q or Qx, Qy"}, 464 465 {"evalDistribution", (PyCFunction)evalDistribution , METH_VARARGS, 466 "Evaluate the model at a given Q or Qx, Qy vector "}, 307 467 {"reset", (PyCFunction)reset , METH_VARARGS, 308 468 "Reset pair correlation"}, … … 355 515 356 516 357 static PyMethodDef module_methods[] = {358 {NULL}359 };517 //static PyMethodDef module_methods[] = { 518 // {NULL} 519 //}; 360 520 361 521 /** -
sansmodels/src/sans/models/c_models/classTemplate.txt
r26e4a24 ra8d6888 170 170 171 171 if (PyArray_Check(x) && PyArray_Check(y)) { 172 x_len = dims[0]= x->dimensions[0]; 173 y_len = dims[1]= y->dimensions[1]; 172 173 x_len = dims[1]= x->dimensions[1]; 174 y_len = dims[0]= y->dimensions[0]; 174 175 175 176 // Make a new double matrix of same dims … … 184 185 for ( i=0; i< x_len; i++) { 185 186 for ( j=0; j< y_len; j++) { 186 double x_value = *(double *)(x->data + i*x->strides[ 0]);187 double y_value = *(double *)(y->data + j*y->strides[ 1]);187 double x_value = *(double *)(x->data + i*x->strides[1]); 188 double y_value = *(double *)(y->data + j*y->strides[0]); 188 189 double *result_value = (double *)(result->data + 189 i*result->strides[ 0] + j*result->strides[1]);190 i*result->strides[1] + j*result->strides[0]); 190 191 *result_value = (*model)(x_value, y_value); 191 192 }
Note: See TracChangeset
for help on using the changeset viewer.