Changeset b966a96 in sasmodels
- Timestamp:
- Jul 21, 2016 5:12:18 PM (8 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 6a0d6aa
- Parents:
- 32e3c9b
- Location:
- sasmodels
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/generate.py
r32e3c9b rb966a96 540 540 541 541 # Define the parameter table 542 # TODO: plug in current line number 543 source.append('#line 542 "sasmodels/generate.py"') 542 544 source.append("#define PARAMETER_TABLE \\") 543 545 source.append("\\\n".join(p.as_definition() … … 580 582 581 583 source.append("#if defined(USE_OPENCL)") 582 source.extend(_add_kernels(ocl_code [0], call_iq, call_iqxy, model_info.name))584 source.extend(_add_kernels(ocl_code, call_iq, call_iqxy, model_info.name)) 583 585 source.append("#else /* !USE_OPENCL */") 584 source.extend(_add_kernels(dll_code [0], call_iq, call_iqxy, model_info.name))586 source.extend(_add_kernels(dll_code, call_iq, call_iqxy, model_info.name)) 585 587 source.append("#endif /* !USE_OPENCL */") 586 588 return '\n'.join(source) 587 589 588 590 589 def _add_kernels(kernel_code, call_iq, call_iqxy, name): 590 # type: (str, str, str, str) -> List[str] 591 def _add_kernels(kernel, call_iq, call_iqxy, name): 592 # type: ([str,str], str, str, str) -> List[str] 593 code = kernel[0] 594 path = kernel[1].replace('\\', '\\\\') 591 595 source = [ 592 596 # define the Iq kernel 593 597 "#define KERNEL_NAME %s_Iq" % name, 594 598 call_iq, 595 kernel_code, 599 '#line 1 "%s-Iq"' % path, 600 code, 596 601 "#undef CALL_IQ", 597 602 "#undef KERNEL_NAME", … … 600 605 "#define KERNEL_NAME %s_Iqxy" % name, 601 606 call_iqxy, 602 kernel_code, 607 '#line 1 "%s-Iqxy"' % path, 608 code, 603 609 "#undef CALL_IQ", 604 610 "#undef KERNEL_NAME", … … 608 614 "#define MAGNETIC 1", 609 615 call_iqxy, 610 kernel_code, 616 '#line 1 "%s-Imagnetic"' % path, 617 code, 611 618 "#undef MAGNETIC", 612 619 "#undef CALL_IQ", -
sasmodels/kernel_header.c
rba32cdd rb966a96 8 8 // Note: if using a C++ compiler, then define kernel as extern "C" 9 9 #ifndef USE_OPENCL 10 // Use SAS_DOUBLE to force the use of double even for float kernels 11 # define SAS_DOUBLE dou ## ble 10 12 # ifdef __cplusplus 11 13 #include <cstdio> … … 16 18 #include <float.h> 17 19 #define kernel extern "C" __declspec( dllexport ) 18 static double trunc(double x) { return x>=0?floor(x):-floor(-x); } 19 static double fmin(double x, double y) { return x>y ? y : x; } 20 static double fmax(double x, double y) { return x<y ? y : x; } 21 static double isnan(double x) { return _isnan(x); } 20 inline double trunc(double x) { return x>=0?floor(x):-floor(-x); } 21 inline double fmin(double x, double y) { return x>y ? y : x; } 22 inline double fmax(double x, double y) { return x<y ? y : x; } 23 #define isnan(x) _isnan(x) 24 #define isinf(x) (!_finite(x)) 25 #define isfinite(x) _finite(x) 22 26 #define NAN (std::numeric_limits<double>::quiet_NaN()) // non-signalling NaN 23 static double cephes_expm1(double x) { 24 // Adapted from the cephes math library. 25 // Copyright 1984 - 1992 by Stephen L. Moshier 26 if (x != x || x == 0.0) { 27 return x; // NaN and +/- 0 28 } else if (x < -0.5 || x > 0.5) { 29 return exp(x) - 1.0; 30 } else { 31 const double xsq = x*x; 32 const double p = ((( 33 +1.2617719307481059087798E-4)*xsq 34 +3.0299440770744196129956E-2)*xsq 35 +9.9999999999999999991025E-1); 36 const double q = (((( 37 +3.0019850513866445504159E-6)*xsq 38 +2.5244834034968410419224E-3)*xsq 39 +2.2726554820815502876593E-1)*xsq 40 +2.0000000000000000000897E0); 41 double r = x * p; 42 r = r / (q - r); 43 return r+r; 44 } 45 } 46 #define expm1 cephes_expm1 47 typedef __int32 int32_t 27 #define INFINITY (std::numeric_limits<double>::infinity()) 28 #define NEED_EXPM1 29 #define NEED_TGAMMA 48 30 #else 49 31 #define kernel extern "C" 50 32 #include <cstdint> 51 33 #endif 52 staticvoid SINCOS(double angle, double &svar, double &cvar) { svar=sin(angle); cvar=cos(angle); }34 inline void SINCOS(double angle, double &svar, double &cvar) { svar=sin(angle); cvar=cos(angle); } 53 35 # else 54 36 #include <inttypes.h> // C99 guarantees that int32_t types is here 55 37 #include <stdio.h> 56 #include <tgmath.h> // C99 type-generic math, so sin(float) => sinf 38 #if defined(__TINYC__) 39 typedef int int32_t; 40 #include <math.h> 41 // TODO: test isnan 42 inline double _isnan(double x) { return x != x; } // hope this doesn't optimize away! 43 #undef isnan 44 #define isnan(x) _isnan(x) 45 // Defeat the double->float conversion since we don't have tgmath 46 inline SAS_DOUBLE trunc(SAS_DOUBLE x) { return x>=0?floor(x):-floor(-x); } 47 inline SAS_DOUBLE fmin(SAS_DOUBLE x, SAS_DOUBLE y) { return x>y ? y : x; } 48 inline SAS_DOUBLE fmax(SAS_DOUBLE x, SAS_DOUBLE y) { return x<y ? y : x; } 49 #define NEED_EXPM1 50 #define NEED_TGAMMA 51 #else 52 #include <tgmath.h> // C99 type-generic math, so sin(float) => sinf 53 #endif 57 54 // MSVC doesn't support C99, so no need for dllexport on C99 branch 58 55 #define kernel … … 73 70 # define SINCOS(angle,svar,cvar) do {const double _t_=angle; svar=sin(_t_);cvar=cos(_t_);} while (0) 74 71 # endif 72 #endif 73 74 #if defined(NEED_EXPM1) 75 static SAS_DOUBLE expm1(SAS_DOUBLE x_in) { 76 double x = (double)x_in; // go back to float for single precision kernels 77 // Adapted from the cephes math library. 78 // Copyright 1984 - 1992 by Stephen L. Moshier 79 if (x != x || x == 0.0) { 80 return x; // NaN and +/- 0 81 } else if (x < -0.5 || x > 0.5) { 82 return exp(x) - 1.0; 83 } else { 84 const double xsq = x*x; 85 const double p = ((( 86 +1.2617719307481059087798E-4)*xsq 87 +3.0299440770744196129956E-2)*xsq 88 +9.9999999999999999991025E-1); 89 const double q = (((( 90 +3.0019850513866445504159E-6)*xsq 91 +2.5244834034968410419224E-3)*xsq 92 +2.2726554820815502876593E-1)*xsq 93 +2.0000000000000000000897E0); 94 double r = x * p; 95 r = r / (q - r); 96 return r+r; 97 } 98 } 75 99 #endif 76 100 … … 103 127 # define M_4PI_3 4.18879020478639 104 128 #endif 105 staticdouble square(double x) { return x*x; }106 staticdouble cube(double x) { return x*x*x; }107 staticdouble sinc(double x) { return x==0 ? 1.0 : sin(x)/x; }129 inline double square(double x) { return x*x; } 130 inline double cube(double x) { return x*x*x; } 131 inline double sinc(double x) { return x==0 ? 1.0 : sin(x)/x; } 108 132 -
sasmodels/kernel_iq.c
r32e3c9b rb966a96 29 29 30 30 typedef struct { 31 PARAMETER_TABLE ;31 PARAMETER_TABLE 32 32 } ParameterBlock; 33 33 #endif … … 41 41 static double clip(double value, double low, double high) 42 42 { 43 43 return (value < low ? low : (value > high ? high : value)); 44 44 } 45 45 … … 53 53 double *uu, double *dd, double *ud, double *du) 54 54 { 55 56 57 58 59 60 55 in_spin = clip(in_spin, 0.0, 1.0); 56 out_spin = clip(out_spin, 0.0, 1.0); 57 *uu = sqrt(sqrt(in_spin * out_spin)); 58 *dd = sqrt(sqrt((1.0-in_spin) * (1.0-out_spin))); 59 *ud = sqrt(sqrt(in_spin * (1.0-out_spin))); 60 *du = sqrt(sqrt((1.0-in_spin) * out_spin)); 61 61 } 62 62 63 63 // Convert polar to rectangular coordinates. 64 64 static void polrec(double r, double theta, double phi, 65 65 double *x, double *y, double *z) 66 66 { 67 68 69 70 71 72 67 double cos_theta, sin_theta, cos_phi, sin_phi; 68 SINCOS(theta*M_PI_180, sin_theta, cos_theta); 69 SINCOS(phi*M_PI_180, sin_phi, cos_phi); 70 *x = r * cos_theta * cos_phi; 71 *y = r * sin_theta; 72 *z = -r * cos_theta * sin_phi; 73 73 } 74 74 #endif -
sasmodels/kerneldll.py
r32e3c9b rb966a96 292 292 if self._dll is None: 293 293 self._load_dll() 294 kernel = [self._Iqxy, self._Imagnetic] if q_input.is_2d else self._Iq294 kernel = [self._Iqxy, self._Imagnetic] if q_input.is_2d else [self._Iq]*2 295 295 return DllKernel(kernel, self.info, q_input) 296 296
Note: See TracChangeset
for help on using the changeset viewer.