Changeset 812b901 in sasview for sansmodels
- Timestamp:
- Jul 27, 2009 3:56:14 PM (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:
- 4176435
- Parents:
- 6f2c919
- Location:
- sansmodels/src
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/c_extensions/c_models.c
r2c4b289 r812b901 6 6 */ 7 7 #include <Python.h> 8 8 #define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans 9 #include "arrayobject.h" 9 10 /** 10 11 * Define empty module … … 25 26 m = Py_InitModule3("c_models", module_methods, 26 27 "C extension module for SANS scattering models."); 27 28 29 import_array(); 28 30 addCCylinderModel(m); 29 31 addCParallelepipedModel(m); -
sansmodels/src/sans/models/c_models/CCylinderModel.cpp
r0f5bc9f r812b901 23 23 */ 24 24 25 #define NO_IMPORT_ARRAY 26 #define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans 27 25 28 extern "C" { 26 29 #include <Python.h> 30 #include <arrayobject.h> 27 31 #include "structmember.h" 28 32 #include <stdio.h> … … 142 146 } 143 147 } 144 145 148 /** 149 * Function to call to evaluate model 150 * @param args: input numpy array q[] 151 * @return: numpy array object 152 */ 153 154 static PyObject *evaluateOneDim(CylinderModel* model, PyArrayObject *q){ 155 PyArrayObject *result; 156 157 // Check validity of array q , q must be of dimension 1, an array of double 158 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE) 159 { 160 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 161 //PyErr_SetString(PyExc_ValueError , message); 162 return NULL; 163 } 164 result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), 165 PyArray_DOUBLE); 166 if (result == NULL) { 167 const char * message= "Could not create result "; 168 PyErr_SetString(PyExc_RuntimeError , message); 169 return NULL; 170 } 171 for (int i = 0; i < q->dimensions[0]; i++){ 172 double q_value = *(double *)(q->data + i*q->strides[0]); 173 double *result_value = (double *)(result->data + i*result->strides[0]); 174 *result_value =(*model)(q_value); 175 } 176 return PyArray_Return(result); 177 } 178 /** 179 * Function to call to evaluate model 180 * @param args: input numpy array [q[],phi[]] 181 * @return: numpy array object 182 */ 183 static PyObject * evaluateTwoDim( CylinderModel* 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 , message); 194 return NULL; 195 } 196 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 197 198 if (result == NULL){ 199 const char * message= "Could not create result "; 200 PyErr_SetString(PyExc_RuntimeError , message); 201 return NULL; 202 } 203 204 for (int i = 0; i < q->dimensions[0]; i++) { 205 double q_value = *(double *)(q->data + i*q->strides[0]); 206 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 207 double *result_value = (double *)(result->data + i*result->strides[0]); 208 if (q_value == 0) 209 *result_value = 0.0; 210 else 211 *result_value = model->evaluate_rphi(q_value, phi_value); 212 } 213 return PyArray_Return(result); 214 } 215 216 /** 217 * Function to call to evaluate model 218 * @param args: input numpy array [x[],y[]] 219 * @return: numpy array object 220 */ 221 static PyObject * evaluateTwoDimXY( CylinderModel* model, 222 PyArrayObject *x, PyArrayObject *y) 223 { 224 PyArrayObject *result; 225 //check validity of input vectors 226 if (x->nd != 1 || x->descr->type_num != PyArray_DOUBLE 227 || y->nd != 1 || y->descr->type_num != PyArray_DOUBLE 228 || y->dimensions[0] != x->dimensions[0]){ 229 230 //const char * message= "Invalid array: x->nd=%d,type_num=%d\n",x->nd,x->descr->type_num; 231 //PyErr_SetString(PyExc_ValueError , message); 232 return NULL; 233 } 234 result= (PyArrayObject *)PyArray_FromDims(x->nd,(int*)(x->dimensions), PyArray_DOUBLE); 235 236 if (result == NULL){ 237 const char * message= "Could not create result "; 238 PyErr_SetString(PyExc_RuntimeError , message); 239 return NULL; 240 } 241 242 for (int i = 0; i < x->dimensions[0]; i++) { 243 double x_value = *(double *)(x->data + i*x->strides[0]); 244 double y_value = *(double *)(y->data + i*y->strides[0]); 245 double *result_value = (double *)(result->data + i*result->strides[0]); 246 *result_value = (*model)(x_value, y_value); 247 } 248 return PyArray_Return(result); 249 } 250 146 251 /** 147 252 * Function to call to evaluate model … … 194 299 return NULL; 195 300 } 301 196 302 // We have a vector q, get the q and phi values at which 197 303 // to evaluate I(q,phi) 198 q_value = CCylinderModel_readDouble(PyList_GET_ITEM(pars,0)); 199 phi_value = CCylinderModel_readDouble(PyList_GET_ITEM(pars,1)); 200 // Skip zero 201 if (q_value==0) { 202 return Py_BuildValue("d",0.0); 203 } 204 return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value)); 205 304 PyObject *q, *phi; 305 q = PyList_GET_ITEM(pars,0); 306 phi = PyList_GET_ITEM(pars,1); 307 308 if (PyArray_Check(q) && PyArray_Check(phi)) { 309 return evaluateTwoDim(self->model, (PyArrayObject*)q, (PyArrayObject*)phi); 310 } else if (PyArray_Check(q) || PyArray_Check(phi)) { 311 return NULL; 312 } else { 313 q_value = CCylinderModel_readDouble(PyList_GET_ITEM(pars,0)); 314 phi_value = CCylinderModel_readDouble(PyList_GET_ITEM(pars,1)); 315 // Skip zero 316 if (q_value==0) { 317 return Py_BuildValue("d",0.0); 318 } 319 return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value)); 320 } 206 321 } else { 207 208 // We have a scalar q, we will evaluate I(q) 322 if (PyArray_Check(pars)) { 323 return evaluateOneDim(self->model, (PyArrayObject*)pars); 324 } else { 325 // We have a scalar q, we will evaluate I(q) 209 326 q_value = CCylinderModel_readDouble(pars); 210 211 return Py_BuildValue("d",(*(self->model))(q_value));212 } 327 return Py_BuildValue("d",(*(self->model))(q_value)); 328 } 329 } 213 330 } 214 331 … … 265 382 // We have a vector q, get the qx and qy values at which 266 383 // to evaluate I(qx,qy) 267 qx_value = CCylinderModel_readDouble(PyList_GET_ITEM(pars,0)); 268 qy_value = CCylinderModel_readDouble(PyList_GET_ITEM(pars,1)); 269 return Py_BuildValue("d",(*(self->model))(qx_value,qy_value)); 384 PyObject *x, *y; 385 x = PyList_GET_ITEM(pars,0); 386 y = PyList_GET_ITEM(pars,1); 387 388 if (PyArray_Check(x) && PyArray_Check(y)) { 389 390 return evaluateTwoDimXY(self->model, (PyArrayObject*)x, (PyArrayObject*)y); 391 } else if (PyArray_Check(x) || PyArray_Check(y)) { 392 return NULL; 393 } else { 394 qx_value = CCylinderModel_readDouble(PyList_GET_ITEM(pars,0)); 395 qy_value = CCylinderModel_readDouble(PyList_GET_ITEM(pars,1)); 396 return Py_BuildValue("d",(*(self->model))(qx_value,qy_value)); 397 } 270 398 271 399 } else { 272 273 // We have a scalar q, we will evaluate I(q) 274 qx_value = CCylinderModel_readDouble(pars); 400 if (PyArray_Check(pars)) { 401 return evaluateOneDim(self->model, (PyArrayObject*)pars); 402 } else { 403 // We have a scalar q, we will evaluate I(q) 404 qx_value = CCylinderModel_readDouble(pars); 275 405 276 return Py_BuildValue("d",(*(self->model))(qx_value)); 406 return Py_BuildValue("d",(*(self->model))(qx_value)); 407 } 277 408 } 278 409 } … … 376 507 377 508 378 static PyMethodDef module_methods[] = {379 {NULL}380 };381 382 509 /** 383 510 * Function used to add the model class to a module -
sansmodels/src/sans/models/c_models/CSphereModel.cpp
r836fe6e r812b901 23 23 */ 24 24 25 #define NO_IMPORT_ARRAY 26 #define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans 27 25 28 extern "C" { 26 29 #include <Python.h> 30 #include <arrayobject.h> 27 31 #include "structmember.h" 28 32 #include <stdio.h> … … 130 134 } 131 135 } 132 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(SphereModel* 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 * Function to call to evaluate model 168 * @param args: input numpy array [q[],phi[]] 169 * @return: numpy array object 170 */ 171 static PyObject * evaluateTwoDim( SphereModel* 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 , message); 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 } 203 204 /** 205 * Function to call to evaluate model 206 * @param args: input numpy array [x[],y[]] 207 * @return: numpy array object 208 */ 209 static PyObject * evaluateTwoDimXY( SphereModel* model, 210 PyArrayObject *x, PyArrayObject *y) 211 { 212 PyArrayObject *result; 213 //check validity of input vectors 214 if (x->nd != 1 || x->descr->type_num != PyArray_DOUBLE 215 || y->nd != 1 || y->descr->type_num != PyArray_DOUBLE 216 || y->dimensions[0] != x->dimensions[0]){ 217 218 //const char * message= "Invalid array: x->nd=%d,type_num=%d\n",x->nd,x->descr->type_num; 219 //PyErr_SetString(PyExc_ValueError , message); 220 return NULL; 221 } 222 result= (PyArrayObject *)PyArray_FromDims(x->nd,(int*)(x->dimensions), PyArray_DOUBLE); 223 224 if (result == NULL){ 225 const char * message= "Could not create result "; 226 PyErr_SetString(PyExc_RuntimeError , message); 227 return NULL; 228 } 229 230 for (int i = 0; i < x->dimensions[0]; i++) { 231 double x_value = *(double *)(x->data + i*x->strides[0]); 232 double y_value = *(double *)(y->data + i*y->strides[0]); 233 double *result_value = (double *)(result->data + i*result->strides[0]); 234 if (x_value == 0) 235 *result_value = 0.0; 236 else 237 *result_value = (*model)(x_value, y_value); 238 } 239 return PyArray_Return(result); 240 } 241 134 242 /** 135 243 * Function to call to evaluate model … … 173 281 return NULL; 174 282 } 283 175 284 // We have a vector q, get the q and phi values at which 176 285 // to evaluate I(q,phi) 177 q_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,0)); 178 phi_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,1)); 179 // Skip zero 180 if (q_value==0) { 181 return Py_BuildValue("d",0.0); 182 } 183 return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value)); 184 286 PyObject *q, *phi; 287 q = PyList_GET_ITEM(pars,0); 288 phi = PyList_GET_ITEM(pars,1); 289 290 if (PyArray_Check(q) && PyArray_Check(phi)) { 291 return evaluateTwoDim(self->model, (PyArrayObject*)q, (PyArrayObject*)phi); 292 } else if (PyArray_Check(q) || PyArray_Check(phi)) { 293 return NULL; 294 } else { 295 q_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,0)); 296 phi_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,1)); 297 // Skip zero 298 if (q_value==0) { 299 return Py_BuildValue("d",0.0); 300 } 301 return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value)); 302 } 185 303 } else { 186 187 // We have a scalar q, we will evaluate I(q) 304 if (PyArray_Check(pars)) { 305 return evaluateOneDim(self->model, (PyArrayObject*)pars); 306 } else { 307 // We have a scalar q, we will evaluate I(q) 188 308 q_value = CSphereModel_readDouble(pars); 189 190 return Py_BuildValue("d",(*(self->model))(q_value));191 } 309 return Py_BuildValue("d",(*(self->model))(q_value)); 310 } 311 } 192 312 } 193 313 … … 235 355 // We have a vector q, get the qx and qy values at which 236 356 // to evaluate I(qx,qy) 237 qx_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,0)); 238 qy_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,1)); 239 return Py_BuildValue("d",(*(self->model))(qx_value,qy_value)); 357 PyObject *x, *y; 358 x = PyList_GET_ITEM(pars,0); 359 y = PyList_GET_ITEM(pars,1); 360 361 if (PyArray_Check(x) && PyArray_Check(y)) { 362 return evaluateTwoDimXY(self->model, (PyArrayObject*)x, (PyArrayObject*)y); 363 } else if (PyArray_Check(x) || PyArray_Check(y)) { 364 return NULL; 365 } else { 366 qx_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,0)); 367 qy_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,1)); 368 return Py_BuildValue("d",(*(self->model))(qx_value,qy_value)); 369 } 240 370 241 371 } else { 242 243 // We have a scalar q, we will evaluate I(q) 244 qx_value = CSphereModel_readDouble(pars); 372 if (PyArray_Check(pars)) { 373 return evaluateOneDim(self->model, (PyArrayObject*)pars); 374 } else { 375 // We have a scalar q, we will evaluate I(q) 376 qx_value = CSphereModel_readDouble(pars); 245 377 246 return Py_BuildValue("d",(*(self->model))(qx_value)); 378 return Py_BuildValue("d",(*(self->model))(qx_value)); 379 } 247 380 } 248 381 } … … 340 473 341 474 342 static PyMethodDef module_methods[] = {343 {NULL}344 };345 346 475 /** 347 476 * Function used to add the model class to a module -
sansmodels/src/sans/models/c_models/c_models.cpp
r770e4c9 r812b901 7 7 #include <Python.h> 8 8 #include <parameters.hh> 9 #define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans 10 #include "arrayobject.h" 11 9 12 10 13 void addCCylinderModel(PyObject *module); … … 117 120 double *values; 118 121 double *weights; 119 int i;122 //int i; 120 123 121 124 if (!PyArg_ParseTuple(args, "OOO", &disp, &val_obj, &wei_obj)) return NULL; … … 162 165 m = Py_InitModule3("c_models", module_methods, 163 166 "C extension module for SANS scattering models."); 167 import_array(); 164 168 165 169 addCCylinderModel(m); -
sansmodels/src/sans/models/c_models/classTemplate.txt
raf03ddd r812b901 23 23 */ 24 24 25 #define NO_IMPORT_ARRAY 26 #define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans 27 25 28 extern "C" { 26 29 #include <Python.h> 30 #include <arrayobject.h> 27 31 #include "structmember.h" 28 32 #include <stdio.h> … … 116 120 } 117 121 } 118 119 122 /** 123 * Function to call to evaluate model 124 * @param args: input numpy array q[] 125 * @return: numpy array object 126 */ 127 128 static PyObject *evaluateOneDim([CMODEL]* model, PyArrayObject *q){ 129 PyArrayObject *result; 130 131 // Check validity of array q , q must be of dimension 1, an array of double 132 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE) 133 { 134 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 135 //PyErr_SetString(PyExc_ValueError , message); 136 return NULL; 137 } 138 result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), 139 PyArray_DOUBLE); 140 if (result == NULL) { 141 const char * message= "Could not create result "; 142 PyErr_SetString(PyExc_RuntimeError , message); 143 return NULL; 144 } 145 for (int i = 0; i < q->dimensions[0]; i++){ 146 double q_value = *(double *)(q->data + i*q->strides[0]); 147 double *result_value = (double *)(result->data + i*result->strides[0]); 148 *result_value =(*model)(q_value); 149 } 150 return PyArray_Return(result); 151 } 152 /** 153 * Function to call to evaluate model 154 * @param args: input numpy array [q[],phi[]] 155 * @return: numpy array object 156 */ 157 static PyObject * evaluateTwoDim( [CMODEL]* model, 158 PyArrayObject *q, PyArrayObject *phi) 159 { 160 PyArrayObject *result; 161 //check validity of input vectors 162 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 163 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 164 || phi->dimensions[0] != q->dimensions[0]){ 165 166 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 167 //PyErr_SetString(PyExc_ValueError , message); 168 return NULL; 169 } 170 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 171 172 if (result == NULL){ 173 const char * message= "Could not create result "; 174 PyErr_SetString(PyExc_RuntimeError , message); 175 return NULL; 176 } 177 178 for (int i = 0; i < q->dimensions[0]; i++) { 179 double q_value = *(double *)(q->data + i*q->strides[0]); 180 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 181 double *result_value = (double *)(result->data + i*result->strides[0]); 182 if (q_value == 0) 183 *result_value = 0.0; 184 else 185 *result_value = model->evaluate_rphi(q_value, phi_value); 186 } 187 return PyArray_Return(result); 188 } 189 190 /** 191 * Function to call to evaluate model 192 * @param args: input numpy array [x[],y[]] 193 * @return: numpy array object 194 */ 195 static PyObject * evaluateTwoDimXY( [CMODEL]* model, 196 PyArrayObject *x, PyArrayObject *y) 197 { 198 PyArrayObject *result; 199 //check validity of input vectors 200 if (x->nd != 1 || x->descr->type_num != PyArray_DOUBLE 201 || y->nd != 1 || y->descr->type_num != PyArray_DOUBLE 202 || y->dimensions[0] != x->dimensions[0]){ 203 204 //const char * message= "Invalid array: x->nd=%d,type_num=%d\n",x->nd,x->descr->type_num; 205 //PyErr_SetString(PyExc_ValueError , message); 206 return NULL; 207 } 208 result= (PyArrayObject *)PyArray_FromDims(x->nd,(int*)(x->dimensions), PyArray_DOUBLE); 209 210 if (result == NULL){ 211 const char * message= "Could not create result "; 212 PyErr_SetString(PyExc_RuntimeError , message); 213 return NULL; 214 } 215 216 for (int i = 0; i < x->dimensions[0]; i++) { 217 double x_value = *(double *)(x->data + i*x->strides[0]); 218 double y_value = *(double *)(y->data + i*y->strides[0]); 219 double *result_value = (double *)(result->data + i*result->strides[0]); 220 *result_value = (*model)(x_value, y_value); 221 } 222 return PyArray_Return(result); 223 } 224 120 225 /** 121 226 * Function to call to evaluate model … … 149 254 return NULL; 150 255 } 256 151 257 // We have a vector q, get the q and phi values at which 152 258 // to evaluate I(q,phi) 153 q_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0)); 154 phi_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1)); 155 // Skip zero 156 if (q_value==0) { 157 return Py_BuildValue("d",0.0); 158 } 159 return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value)); 160 259 PyObject *q, *phi; 260 q = PyList_GET_ITEM(pars,0); 261 phi = PyList_GET_ITEM(pars,1); 262 263 if (PyArray_Check(q) && PyArray_Check(phi)) { 264 return evaluateTwoDim(self->model, (PyArrayObject*)q, (PyArrayObject*)phi); 265 } else if (PyArray_Check(q) || PyArray_Check(phi)) { 266 return NULL; 267 } else { 268 q_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0)); 269 phi_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1)); 270 // Skip zero 271 if (q_value==0) { 272 return Py_BuildValue("d",0.0); 273 } 274 return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value)); 275 } 161 276 } else { 162 163 // We have a scalar q, we will evaluate I(q) 277 if (PyArray_Check(pars)) { 278 return evaluateOneDim(self->model, (PyArrayObject*)pars); 279 } else { 280 // We have a scalar q, we will evaluate I(q) 164 281 q_value = [PYTHONCLASS]_readDouble(pars); 165 166 return Py_BuildValue("d",(*(self->model))(q_value));167 } 282 return Py_BuildValue("d",(*(self->model))(q_value)); 283 } 284 } 168 285 } 169 286 … … 201 318 // We have a vector q, get the qx and qy values at which 202 319 // to evaluate I(qx,qy) 203 qx_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0)); 204 qy_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1)); 205 return Py_BuildValue("d",(*(self->model))(qx_value,qy_value)); 320 PyObject *x, *y; 321 x = PyList_GET_ITEM(pars,0); 322 y = PyList_GET_ITEM(pars,1); 323 324 if (PyArray_Check(x) && PyArray_Check(y)) { 325 326 return evaluateTwoDimXY(self->model, (PyArrayObject*)x, (PyArrayObject*)y); 327 } else if (PyArray_Check(x) || PyArray_Check(y)) { 328 return NULL; 329 } else { 330 qx_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0)); 331 qy_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1)); 332 return Py_BuildValue("d",(*(self->model))(qx_value,qy_value)); 333 } 206 334 207 335 } else { 208 209 // We have a scalar q, we will evaluate I(q) 210 qx_value = [PYTHONCLASS]_readDouble(pars); 336 if (PyArray_Check(pars)) { 337 return evaluateOneDim(self->model, (PyArrayObject*)pars); 338 } else { 339 // We have a scalar q, we will evaluate I(q) 340 qx_value = [PYTHONCLASS]_readDouble(pars); 211 341 212 return Py_BuildValue("d",(*(self->model))(qx_value)); 342 return Py_BuildValue("d",(*(self->model))(qx_value)); 343 } 213 344 } 214 345 } … … 302 433 303 434 304 static PyMethodDef module_methods[] = {305 {NULL}306 };307 308 435 /** 309 436 * Function used to add the model class to a module -
sansmodels/src/setup.py
r3d25331f r812b901 12 12 import sys 13 13 14 15 numpy_incl_path = os.path.join(sys.prefix, "Lib", "site-packages", "numpy", "core", "include", "numpy") 14 16 15 17 … … 205 207 srcdir+"/CLorentzian.c" 206 208 ], 207 include_dirs=[igordir,srcdir,"sans/models/c_models" ])])209 include_dirs=[igordir,srcdir,"sans/models/c_models",numpy_incl_path])]) 208 210
Note: See TracChangeset
for help on using the changeset viewer.