- Timestamp:
- Oct 11, 2018 9:49:59 PM (6 years ago)
- Branches:
- master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249
- Children:
- 3e6829d
- Parents:
- 952ea1f
- Location:
- src/sas/sascalc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/calculator/c_extensions/sld2i_module.c
r952ea1f r7ba6470 16 16 #endif 17 17 18 19 // Utilities 20 #define INVECTOR(obj,buf,len) \ 21 do { \ 22 int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \ 23 if (err < 0) return NULL; \ 24 len /= sizeof(*buf); \ 25 } while (0) 26 27 #define OUTVECTOR(obj,buf,len) \ 28 do { \ 29 int err = PyObject_AsWriteBuffer(obj, (void **)(&buf), &len); \ 30 if (err < 0) return NULL; \ 31 len /= sizeof(*buf); \ 32 } while (0) 33 18 // Vector binding glue 19 #if (PY_VERSION_HEX > 0x03000000) && !defined(Py_LIMITED_API) 20 // Assuming that a view into a writable vector points to a 21 // non-changing pointer for the duration of the C call, capture 22 // the view pointer and immediately free the view. 23 #define VECTOR(VEC_obj, VEC_buf, VEC_len) do { \ 24 Py_buffer VEC_view; \ 25 int VEC_err = PyObject_GetBuffer(VEC_obj, &VEC_view, PyBUF_WRITABLE|PyBUF_FORMAT); \ 26 if (VEC_err < 0 || sizeof(*VEC_buf) != VEC_view.itemsize) return NULL; \ 27 VEC_buf = (typeof(VEC_buf))VEC_view.buf; \ 28 VEC_len = VEC_view.len/sizeof(*VEC_buf); \ 29 PyBuffer_Release(&VEC_view); \ 30 } while (0) 31 #else 32 #define VECTOR(VEC_obj, VEC_buf, VEC_len) do { \ 33 int VEC_err = PyObject_AsWriteBuffer(VEC_obj, (void **)(&VEC_buf), &VEC_len); \ 34 if (VEC_err < 0) return NULL; \ 35 VEC_len /= sizeof(*VEC_buf); \ 36 } while (0) 37 #endif 34 38 35 39 /** … … 76 80 //printf("new GenI\n"); 77 81 if (!PyArg_ParseTuple(args, "iOOOOOOOOddd", &is_avg, &x_val_obj, &y_val_obj, &z_val_obj, &sldn_val_obj, &mx_val_obj, &my_val_obj, &mz_val_obj, &vol_pix_obj, &inspin, &outspin, &stheta)) return NULL; 78 INVECTOR(x_val_obj, x_val, n_x);79 INVECTOR(y_val_obj, y_val, n_y);80 INVECTOR(z_val_obj, z_val, n_z);81 INVECTOR(sldn_val_obj, sldn_val, n_sld);82 INVECTOR(mx_val_obj, mx_val, n_mx);83 INVECTOR(my_val_obj, my_val, n_my);84 INVECTOR(mz_val_obj, mz_val, n_mz);85 INVECTOR(vol_pix_obj, vol_pix, n_vol_pix);82 VECTOR(x_val_obj, x_val, n_x); 83 VECTOR(y_val_obj, y_val, n_y); 84 VECTOR(z_val_obj, z_val, n_z); 85 VECTOR(sldn_val_obj, sldn_val, n_sld); 86 VECTOR(mx_val_obj, mx_val, n_mx); 87 VECTOR(my_val_obj, my_val, n_my); 88 VECTOR(mz_val_obj, mz_val, n_mz); 89 VECTOR(vol_pix_obj, vol_pix, n_vol_pix); 86 90 sld2i = PyMem_Malloc(sizeof(GenI)); 87 91 //printf("sldi:%p\n", sld2i); … … 111 115 if (!PyArg_ParseTuple(args, "OOOO", &gen_obj, &qx_obj, &qy_obj, &I_out_obj)) return NULL; 112 116 sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 113 INVECTOR(qx_obj, qx, n_qx);114 INVECTOR(qy_obj, qy, n_qy);115 OUTVECTOR(I_out_obj, I_out, n_out);117 VECTOR(qx_obj, qx, n_qx); 118 VECTOR(qy_obj, qy, n_qy); 119 VECTOR(I_out_obj, I_out, n_out); 116 120 //printf("qx, qy, I_out: %d %d %d, %d %d %d\n", qx, qy, I_out, n_qx, n_qy, n_out); 117 121 … … 139 143 if (!PyArg_ParseTuple(args, "OOO", &gen_obj, &q_obj, &I_out_obj)) return NULL; 140 144 sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 141 INVECTOR(q_obj, q, n_q);142 OUTVECTOR(I_out_obj, I_out, n_out);145 VECTOR(q_obj, q, n_q); 146 VECTOR(I_out_obj, I_out, n_out); 143 147 144 148 // Sanity check -
src/sas/sascalc/pr/c_extensions/Cinvertor.c
r952ea1f r7ba6470 14 14 #include <structmember.h> 15 15 16 // Vector binding glue 17 #if (PY_VERSION_HEX > 0x03000000) && !defined(Py_LIMITED_API) 18 // Assuming that a view into a writable vector points to a 19 // non-changing pointer for the duration of the C call, capture 20 // the view pointer and immediately free the view. 21 #define VECTOR(VEC_obj, VEC_buf, VEC_len) do { \ 22 Py_buffer VEC_view; \ 23 int VEC_err = PyObject_GetBuffer(VEC_obj, &VEC_view, PyBUF_WRITABLE|PyBUF_FORMAT); \ 24 if (VEC_err < 0 || sizeof(*VEC_buf) != VEC_view.itemsize) return NULL; \ 25 VEC_buf = (typeof(VEC_buf))VEC_view.buf; \ 26 VEC_len = VEC_view.len/sizeof(*VEC_buf); \ 27 PyBuffer_Release(&VEC_view); \ 28 } while (0) 29 #else 30 #define VECTOR(VEC_obj, VEC_buf, VEC_len) do { \ 31 int VEC_err = PyObject_AsWriteBuffer(VEC_obj, (void **)(&VEC_buf), &VEC_len); \ 32 if (VEC_err < 0) return NULL; \ 33 VEC_len /= sizeof(*VEC_buf); \ 34 } while (0) 35 #endif 36 16 37 #include "invertor.h" 17 38 18 39 /// Error object for raised exceptions 19 40 PyObject * CinvertorError; 20 21 #define INVECTOR(obj,buf,len) \22 do { \23 int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \24 if (err < 0) return NULL; \25 len /= sizeof(*buf); \26 } while (0)27 28 #define OUTVECTOR(obj,buf,len) \29 do { \30 int err = PyObject_AsWriteBuffer(obj, (void **)(&buf), &len); \31 if (err < 0) return NULL; \32 len /= sizeof(*buf); \33 } while (0)34 35 41 36 42 // Class definition … … 100 106 101 107 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 102 OUTVECTOR(data_obj,data,ndata);108 VECTOR(data_obj,data,ndata); 103 109 104 110 free(self->params.x); … … 132 138 133 139 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 134 OUTVECTOR(data_obj, data, ndata);140 VECTOR(data_obj, data, ndata); 135 141 136 142 // Check that the input array is large enough … … 165 171 166 172 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 167 OUTVECTOR(data_obj,data,ndata);173 VECTOR(data_obj,data,ndata); 168 174 169 175 free(self->params.y); … … 197 203 198 204 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 199 OUTVECTOR(data_obj, data, ndata);205 VECTOR(data_obj, data, ndata); 200 206 201 207 // Check that the input array is large enough … … 230 236 231 237 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 232 OUTVECTOR(data_obj,data,ndata);238 VECTOR(data_obj,data,ndata); 233 239 234 240 free(self->params.err); … … 262 268 263 269 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 264 OUTVECTOR(data_obj, data, ndata);270 VECTOR(data_obj, data, ndata); 265 271 266 272 // Check that the input array is large enough … … 518 524 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 519 525 520 OUTVECTOR(data_obj,pars,npars);526 VECTOR(data_obj,pars,npars); 521 527 522 528 // PyList of residuals … … 569 575 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 570 576 571 OUTVECTOR(data_obj,pars,npars);577 VECTOR(data_obj,pars,npars); 572 578 573 579 // Should create this list only once and refill it … … 610 616 611 617 if (!PyArg_ParseTuple(args, "Od", &data_obj, &q)) return NULL; 612 OUTVECTOR(data_obj,pars,npars);618 VECTOR(data_obj,pars,npars); 613 619 614 620 iq_value = iq(pars, self->params.d_max, (int)npars, q); … … 635 641 636 642 if (!PyArg_ParseTuple(args, "Od", &data_obj, &q)) return NULL; 637 OUTVECTOR(data_obj,pars,npars);643 VECTOR(data_obj,pars,npars); 638 644 639 645 iq_value = iq_smeared(pars, self->params.d_max, (int)npars, … … 660 666 661 667 if (!PyArg_ParseTuple(args, "Od", &data_obj, &r)) return NULL; 662 OUTVECTOR(data_obj,pars,npars);668 VECTOR(data_obj,pars,npars); 663 669 664 670 pr_value = pr(pars, self->params.d_max, (int)npars, r); … … 687 693 688 694 if (!PyArg_ParseTuple(args, "OOd", &data_obj, &err_obj, &r)) return NULL; 689 OUTVECTOR(data_obj,pars,npars);695 VECTOR(data_obj,pars,npars); 690 696 691 697 if (err_obj == Py_None) { … … 693 699 pr_err_value = 0.0; 694 700 } else { 695 OUTVECTOR(err_obj,pars_err,npars2);701 VECTOR(err_obj,pars_err,npars2); 696 702 pr_err(pars, pars_err, self->params.d_max, (int)npars, r, &pr_value, &pr_err_value); 697 703 } … … 727 733 728 734 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 729 OUTVECTOR(data_obj,pars,npars);735 VECTOR(data_obj,pars,npars); 730 736 731 737 oscill = reg_term(pars, self->params.d_max, (int)npars, 100); … … 748 754 749 755 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 750 OUTVECTOR(data_obj,pars,npars);756 VECTOR(data_obj,pars,npars); 751 757 752 758 count = npeaks(pars, self->params.d_max, (int)npars, 100); … … 769 775 770 776 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 771 OUTVECTOR(data_obj,pars,npars);777 VECTOR(data_obj,pars,npars); 772 778 773 779 fraction = positive_integral(pars, self->params.d_max, (int)npars, 100); … … 793 799 794 800 if (!PyArg_ParseTuple(args, "OO", &data_obj, &err_obj)) return NULL; 795 OUTVECTOR(data_obj,pars,npars);796 OUTVECTOR(err_obj,pars_err,npars2);801 VECTOR(data_obj,pars,npars); 802 VECTOR(err_obj,pars_err,npars2); 797 803 798 804 fraction = positive_errors(pars, pars_err, self->params.d_max, (int)npars, 51); … … 814 820 815 821 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 816 OUTVECTOR(data_obj,pars,npars);822 VECTOR(data_obj,pars,npars); 817 823 818 824 value = rg(pars, self->params.d_max, (int)npars, 101); … … 834 840 835 841 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 836 OUTVECTOR(data_obj,pars,npars);842 VECTOR(data_obj,pars,npars); 837 843 838 844 value = 4.0*acos(-1.0)*int_pr(pars, self->params.d_max, (int)npars, 101); … … 875 881 876 882 if (!PyArg_ParseTuple(args, "iiOO", &nfunc, &nr, &a_obj, &b_obj)) return NULL; 877 OUTVECTOR(a_obj,a,n_a);878 OUTVECTOR(b_obj,b,n_b);883 VECTOR(a_obj,a,n_a); 884 VECTOR(b_obj,b,n_b); 879 885 880 886 assert(n_b>=nfunc); … … 948 954 949 955 if (!PyArg_ParseTuple(args, "iiOO", &nfunc, &nr, &a_obj, &cov_obj)) return NULL; 950 OUTVECTOR(a_obj,a,n_a);951 OUTVECTOR(cov_obj,inv_cov,n_cov);956 VECTOR(a_obj,a,n_a); 957 VECTOR(cov_obj,inv_cov,n_cov); 952 958 953 959 assert(n_cov>=nfunc*nfunc); … … 982 988 983 989 if (!PyArg_ParseTuple(args, "iiO", &nfunc, &nr, &a_obj)) return NULL; 984 OUTVECTOR(a_obj,a,n_a);990 VECTOR(a_obj,a,n_a); 985 991 986 992 assert(n_a>=nfunc*(nr+self->params.npoints));
Note: See TracChangeset
for help on using the changeset viewer.