Changeset d04ac05 in sasview for src/sas/sascalc
- Timestamp:
- Sep 23, 2017 1:47:05 AM (7 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 9e308a3
- Parents:
- 7b50f14
- Location:
- src/sas/sascalc
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/calculator/c_extensions/sld2i_module.cpp
rb523c0e rd04ac05 5 5 #include <stdio.h> 6 6 #include <sld2i.hh> 7 8 #if PY_MAJOR_VERSION < 3 9 typedef void (*PyCapsule_Destructor)(PyObject *); 10 typedef void (*PyCObject_Destructor)(void *); 11 #define PyCapsule_New(pointer, name, destructor) (PyCObject_FromVoidPtr(pointer, (PyCObject_Destructor)destructor)) 12 #define PyCapsule_GetPointer(capsule, name) (PyCObject_AsVoidPtr(capsule)) 13 #endif 14 7 15 8 16 // Utilities … … 25 33 * Delete a GenI object 26 34 */ 27 void del_sld2i(void *ptr){ 28 GenI* sld2i = static_cast<GenI *>(ptr); 35 void 36 del_sld2i(PyObject *obj){ 37 GenI* sld2i = static_cast<GenI *>(PyCapsule_GetPointer(obj, "GenI")); 29 38 delete sld2i; 30 39 return; … … 71 80 OUTVECTOR(vol_pix_obj, vol_pix, n_x); 72 81 GenI* sld2i = new GenI(n_pix,x_val,y_val,z_val,sldn_val,mx_val,my_val,mz_val,vol_pix,inspin,outspin,stheta); 73 return PyC Object_FromVoidPtr(sld2i, del_sld2i);82 return PyCapsule_New(sld2i, "GenI", del_sld2i); 74 83 } 75 84 … … 97 106 98 107 // Set the array pointers 99 void *temp = PyC Object_AsVoidPtr(gen_obj);108 void *temp = PyCapsule_GetPointer(gen_obj, "GenI"); 100 109 GenI* s = static_cast<GenI *>(temp); 101 110 … … 125 134 126 135 // Set the array pointers 127 void *temp = PyC Object_AsVoidPtr(gen_obj);136 void *temp = PyCapsule_GetPointer(gen_obj, "GenI"); 128 137 GenI* s = static_cast<GenI *>(temp); 129 138 … … 146 155 }; 147 156 148 149 #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ 150 #define PyMODINIT_FUNC void 157 #define MODULE_DOC "Sld2i C Library" 158 #define MODULE_NAME "sld2i" 159 #define MODULE_INIT2 initsld2i 160 #define MODULE_INIT3 PyInit_reflmodule 161 #define MODULE_METHODS module_methods 162 163 /* ==== boilerplate python 2/3 interface bootstrap ==== */ 164 165 166 #if defined(WIN32) && !defined(__MINGW32__) 167 #define DLL_EXPORT __declspec(dllexport) 168 #else 169 #define DLL_EXPORT 151 170 #endif 152 PyMODINIT_FUNC 153 initsld2i(void) 154 { 155 Py_InitModule3("sld2i", module_methods, "Sld2i module"); 156 } 171 172 #if PY_MAJOR_VERSION >= 3 173 174 DLL_EXPORT PyMODINIT_FUNC MODULE_INIT3(void) 175 { 176 static struct PyModuleDef moduledef = { 177 PyModuleDef_HEAD_INIT, 178 MODULE_NAME, /* m_name */ 179 MODULE_DOC, /* m_doc */ 180 -1, /* m_size */ 181 MODULE_METHODS, /* m_methods */ 182 NULL, /* m_reload */ 183 NULL, /* m_traverse */ 184 NULL, /* m_clear */ 185 NULL, /* m_free */ 186 }; 187 return PyModule_Create(&moduledef); 188 } 189 190 #else /* !PY_MAJOR_VERSION >= 3 */ 191 192 DLL_EXPORT PyMODINIT_FUNC MODULE_INIT2(void) 193 { 194 Py_InitModule4(MODULE_NAME, 195 MODULE_METHODS, 196 MODULE_DOC, 197 0, 198 PYTHON_API_VERSION 199 ); 200 } 201 202 #endif /* !PY_MAJOR_VERSION >= 3 */ -
src/sas/sascalc/file_converter/c_ext/bsl_loader.c
r2ab9c432 rd04ac05 1 1 #include <Python.h> 2 //#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION2 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 3 3 #include <numpy/arrayobject.h> 4 4 #include <stdio.h> … … 44 44 static void CLoader_dealloc(CLoader *self) { 45 45 free(self->params.filename); 46 self->ob_type->tp_free((PyObject *)self);46 Py_TYPE(self)->tp_free((PyObject *)self); 47 47 } 48 48 … … 237 237 238 238 static PyTypeObject CLoaderType = { 239 PyObject_HEAD_INIT(NULL) 240 0, /*ob_size*/ 239 //PyObject_HEAD_INIT(NULL) 240 //0, /*ob_size*/ 241 PyVarObject_HEAD_INIT(NULL, 0) 241 242 "CLoader", /*tp_name*/ 242 243 sizeof(CLoader), /*tp_basicsize*/ … … 278 279 }; 279 280 280 PyMODINIT_FUNC 281 initbsl_loader(void) 282 { 283 PyObject *module; 284 module = Py_InitModule("bsl_loader", NULL); 285 import_array(); 286 281 static PyMethodDef module_methods[] = { 282 {NULL} 283 }; 284 285 /** 286 * Function used to add the model class to a module 287 * @param module: module to add the class to 288 */ 289 void addCLoader(PyObject *module) { 287 290 if (PyType_Ready(&CLoaderType) < 0) 288 291 return; 289 292 290 293 Py_INCREF(&CLoaderType); 291 PyModule_AddObject(module, "CLoader", (PyObject *)&CLoaderType); 292 } 294 PyModule_AddObject(module, "bsl_loader", (PyObject *)&CLoaderType); 295 } 296 297 298 #define MODULE_DOC "C module for loading bsl." 299 #define MODULE_NAME "bsl_loader" 300 #define MODULE_INIT2 initbsl_loader 301 #define MODULE_INIT3 PyInit_bsl_loader 302 #define MODULE_METHODS module_methods 303 304 /* ==== boilerplate python 2/3 interface bootstrap ==== */ 305 306 307 #if defined(WIN32) && !defined(__MINGW32__) 308 #define DLL_EXPORT __declspec(dllexport) 309 #else 310 #define DLL_EXPORT 311 #endif 312 313 #if PY_MAJOR_VERSION >= 3 314 315 DLL_EXPORT PyMODINIT_FUNC MODULE_INIT3(void) 316 { 317 static struct PyModuleDef moduledef = { 318 PyModuleDef_HEAD_INIT, 319 MODULE_NAME, /* m_name */ 320 MODULE_DOC, /* m_doc */ 321 -1, /* m_size */ 322 MODULE_METHODS, /* m_methods */ 323 NULL, /* m_reload */ 324 NULL, /* m_traverse */ 325 NULL, /* m_clear */ 326 NULL, /* m_free */ 327 }; 328 PyObject* m = PyModule_Create(&moduledef); 329 addCLoader(m); 330 return m; 331 } 332 333 #else /* !PY_MAJOR_VERSION >= 3 */ 334 335 DLL_EXPORT PyMODINIT_FUNC MODULE_INIT2(void) 336 { 337 PyObject* m = Py_InitModule4(MODULE_NAME, 338 MODULE_METHODS, 339 MODULE_DOC, 340 0, 341 PYTHON_API_VERSION 342 ); 343 addCLoader(m); 344 } 345 346 #endif /* !PY_MAJOR_VERSION >= 3 */ -
src/sas/sascalc/pr/c_extensions/Cinvertor.c
rcb62bd5 rd04ac05 52 52 invertor_dealloc(&(self->params)); 53 53 54 self->ob_type->tp_free((PyObject*)self);54 Py_TYPE(self)->tp_free((PyObject*)self); 55 55 56 56 } … … 1054 1054 1055 1055 static PyTypeObject CinvertorType = { 1056 PyObject_HEAD_INIT(NULL) 1057 0, /*ob_size*/ 1056 //PyObject_HEAD_INIT(NULL) 1057 //0, /*ob_size*/ 1058 PyVarObject_HEAD_INIT(NULL, 0) 1058 1059 "Cinvertor", /*tp_name*/ 1059 1060 sizeof(Cinvertor), /*tp_basicsize*/ … … 1119 1120 1120 1121 1121 #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ 1122 #define PyMODINIT_FUNC void 1122 #define MODULE_DOC "C extension module for inversion to P(r)." 1123 #define MODULE_NAME "pr_inversion" 1124 #define MODULE_INIT2 initpr_inversion 1125 #define MODULE_INIT3 PyInit_pr_inversion 1126 #define MODULE_METHODS module_methods 1127 1128 /* ==== boilerplate python 2/3 interface bootstrap ==== */ 1129 1130 1131 #if defined(WIN32) && !defined(__MINGW32__) 1132 #define DLL_EXPORT __declspec(dllexport) 1133 #else 1134 #define DLL_EXPORT 1123 1135 #endif 1124 PyMODINIT_FUNC 1125 initpr_inversion(void) 1126 { 1127 PyObject* m; 1128 1129 m = Py_InitModule3("pr_inversion", module_methods, 1130 "C extension module for inversion to P(r)."); 1131 1132 addCinvertor(m); 1133 } 1136 1137 #if PY_MAJOR_VERSION >= 3 1138 1139 DLL_EXPORT PyMODINIT_FUNC MODULE_INIT3(void) 1140 { 1141 static struct PyModuleDef moduledef = { 1142 PyModuleDef_HEAD_INIT, 1143 MODULE_NAME, /* m_name */ 1144 MODULE_DOC, /* m_doc */ 1145 -1, /* m_size */ 1146 MODULE_METHODS, /* m_methods */ 1147 NULL, /* m_reload */ 1148 NULL, /* m_traverse */ 1149 NULL, /* m_clear */ 1150 NULL, /* m_free */ 1151 }; 1152 PyObject* m = PyModule_Create(&moduledef); 1153 addCinvertor(m); 1154 return m; 1155 } 1156 1157 #else /* !PY_MAJOR_VERSION >= 3 */ 1158 1159 DLL_EXPORT PyMODINIT_FUNC MODULE_INIT2(void) 1160 { 1161 PyObject* m = Py_InitModule4(MODULE_NAME, 1162 MODULE_METHODS, 1163 MODULE_DOC, 1164 0, 1165 PYTHON_API_VERSION 1166 ); 1167 addCinvertor(m); 1168 } 1169 1170 #endif /* !PY_MAJOR_VERSION >= 3 */ -
src/sas/sascalc/pr/invertor.py
r574adc7 rd04ac05 472 472 try: 473 473 self._get_matrix(nfunc, nq, a, b) 474 except :475 raise RuntimeError("Invertor: could not invert I(Q)\n %s" % s ys.exc_value)474 except Exception as exc: 475 raise RuntimeError("Invertor: could not invert I(Q)\n %s" % str(exc)) 476 476 477 477 # Perform the inversion (least square fit)
Note: See TracChangeset
for help on using the changeset viewer.