Changeset 7ba6470 in sasview for src/sas/sascalc/pr
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.