Changes in / [a03fad8:b52e00f] in sasmodels
- Files:
-
- 1 added
- 7 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/guide/gpu/gpu_computations.rst
r8ae8532 r8ae8532 31 31 from available OpenCL platforms. 32 32 33 OpenCL devices can be set from OpenCL options dialog in Fitting menu or as 34 enviromental variables. 35 36 **If you don't want to use OpenCL, you can select "No OpenCL" option from** 37 **GUI dialog or set *SAS_OPENCL=None* in your environment settings** 38 **This will only use normal programs.** 39 33 40 SasView prefers AMD or NVIDIA drivers for GPU, and prefers Intel or 34 41 Apple drivers for CPU. Both GPU and CPU are included on the assumption that CPU … … 39 46 chose to run the model. 40 47 41 **If you don't want to use OpenCL, you can set** *SAS_OPENCL=None* 42 **in your environment settings, and it will only use normal programs.** 43 44 If you want to use one of the other devices, you can run the following 45 from the python console in SasView:: 48 If you want to use one of the other devices, you can select it from OpenCL 49 options dialog (accessible from Fitting menu) or run the following from 50 the python console in SasView:: 46 51 47 52 import pyopencl as cl -
sasmodels/generate.py
rc4e3215 rbb4b509 492 492 493 493 def test_tag_float(): 494 495 cases=""" 494 """check that floating point constants are properly identified and tagged with 'f'""" 495 496 cases = """ 496 497 ZP : 0. 497 498 ZPF : 0.0,0.01,0.1 … … 519 520 """ 520 521 521 output ="""522 output = """ 522 523 ZP : 0.f 523 524 ZPF : 0.0f,0.01f,0.1f … … 611 612 # type: (str, List[Parameter]) -> List[str] 612 613 """ 613 Return a list of *prefix.parameter* from parameter items. 614 Return a list of *prefix+parameter* from parameter items. 615 616 *prefix* should be "v." if v is a struct. 614 617 """ 615 618 return [p.as_call_reference(prefix) for p in pars] … … 733 736 call_iqxy = "#define CALL_IQ(_q,_i,_v) Iq(%s)" % (",".join(pars_sqrt)) 734 737 735 magpars = [k-2 for k, p in enumerate(partable.call_parameters)738 magpars = [k-2 for k, p in enumerate(partable.call_parameters) 736 739 if p.type == 'sld'] 737 740 … … 742 745 source.append("#define NUM_MAGNETIC %d" % partable.nmagnetic) 743 746 source.append("#define MAGNETIC_PARS %s"%",".join(str(k) for k in magpars)) 744 for k, v in enumerate(magpars[:3]):747 for k, v in enumerate(magpars[:3]): 745 748 source.append("#define MAGNETIC_PAR%d %d"%(k+1, v)) 746 749 … … 779 782 "#undef CALL_IQ", 780 783 "#undef KERNEL_NAME", 781 784 ] 782 785 783 786 imagnetic = [ … … 872 875 873 876 # TODO: need a single source for rst_prolog; it is also in doc/rst_prolog 874 RST_PROLOG = """\877 RST_PROLOG = r"""\ 875 878 .. |Ang| unicode:: U+212B 876 879 .. |Ang^-1| replace:: |Ang|\ :sup:`-1` -
sasmodels/kernel_header.c
rb00a646 rbb4b509 14 14 # define SINCOS(angle,svar,cvar) do {const double _t_=angle; svar=sin(_t_);cvar=cos(_t_);} while (0) 15 15 # endif 16 // Intel CPU on Mac gives strange values for erf(); also on the tested16 // Intel CPU on Mac gives strange values for erf(); on the verified 17 17 // platforms (intel, nvidia, amd), the cephes erf() is significantly 18 18 // faster than that available in the native OpenCL. … … 57 57 typedef int int32_t; 58 58 #include <math.h> 59 // TODO: test isnan59 // TODO: check isnan is correct 60 60 inline double _isnan(double x) { return x != x; } // hope this doesn't optimize away! 61 61 #undef isnan -
sasmodels/kernelcl.py
rb8ddf2e rc1114bf 578 578 # Free buffers 579 579 for v in (details_b, values_b): 580 if v is not None: v.release() 580 if v is not None: 581 v.release() 581 582 582 583 pd_norm = self.result[self.q_input.nq] 583 scale = values[0]/(pd_norm if pd_norm !=0.0 else 1.0)584 scale = values[0]/(pd_norm if pd_norm != 0.0 else 1.0) 584 585 background = values[1] 585 586 #print("scale",scale,values[0],self.result[self.q_input.nq],background) -
sasmodels/model_test.py
r3330bb4 rbb4b509 85 85 skip = [] 86 86 for model_name in models: 87 if model_name in skip: continue 87 if model_name in skip: 88 continue 88 89 model_info = load_model_info(model_name) 89 90 … … 239 240 multiple = [test for test in self.info.tests 240 241 if isinstance(test[2], list) 241 242 and not all(result is None for result in test[2])] 242 243 tests_has_1D_multiple = any(isinstance(test[1][0], float) 243 244 for test in multiple) … … 262 263 user_pars, x, y = test 263 264 pars = expand_pars(self.info.parameters, user_pars) 265 invalid = invalid_pars(self.info.parameters, pars) 266 if invalid: 267 raise ValueError("Unknown parameters in test: " + ", ".join(invalid)) 264 268 265 269 if not isinstance(y, list): … … 305 309 306 310 return ModelTestCase 311 312 def invalid_pars(partable, pars): 313 # type: (ParameterTable, Dict[str, float]) 314 """ 315 Return a list of parameter names that are not part of the model. 316 """ 317 names = set(p.id for p in partable.call_parameters) 318 invalid = [] 319 for par in sorted(pars.keys()): 320 parts = par.split('_pd') 321 if len(parts) > 1 and parts[1] not in ("", "_n", "nsigma", "type"): 322 invalid.append(par) 323 continue 324 if parts[0] not in names: 325 invalid.append(par) 326 return invalid 327 307 328 308 329 def is_near(target, actual, digits=5): -
sasmodels/modelinfo.py
rf88e248 rbb4b509 101 101 limits = (float(low), float(high)) 102 102 except Exception: 103 raise ValueError("invalid limits for %s: %r"%(name, user_limits))103 raise ValueError("invalid limits for %s: %r"%(name, user_limits)) 104 104 if low >= high: 105 105 raise ValueError("require lower limit < upper limit") … … 342 342 def as_call_reference(self, prefix=""): 343 343 # type: (str) -> str 344 """ 345 Return *prefix* + parameter name. For struct references, use "v." 346 as the prefix. 347 """ 344 348 # Note: if the parameter is a struct type, then we will need to use 345 349 # &prefix+id. For scalars and vectors we can just use prefix+id. … … 420 424 self.npars = sum(p.length for p in self.kernel_parameters) 421 425 self.nmagnetic = sum(p.length for p in self.kernel_parameters 422 if p.type =='sld')426 if p.type == 'sld') 423 427 self.nvalues = 2 + self.npars 424 428 if self.nmagnetic: … … 457 461 self.has_2d = any(p.type in ('orientation', 'magnetic') 458 462 for p in self.kernel_parameters) 459 self.magnetism_index = [k for k, p in enumerate(self.call_parameters)463 self.magnetism_index = [k for k, p in enumerate(self.call_parameters) 460 464 if p.id.startswith('M0:')] 461 465 … … 544 548 'magnetic', 'magnetic amplitude for '+p.description), 545 549 Parameter('mtheta:'+p.id, 'degrees', 0., [-90., 90.], 546 550 'magnetic', 'magnetic latitude for '+p.description), 547 551 Parameter('mphi:'+p.id, 'degrees', 0., [-180., 180.], 548 552 'magnetic', 'magnetic longitude for '+p.description), 549 553 ]) 550 554 #print("call parameters", full_list) … … 683 687 684 688 if (model_info.Iq is None 685 and model_info.Iqxy is None686 and model_info.Imagnetic is None687 and model_info.form_volume is None):689 and model_info.Iqxy is None 690 and model_info.Imagnetic is None 691 and model_info.form_volume is None): 688 692 return 689 693 … … 843 847 #: it to False because they require double precision calculations. 844 848 single = None # type: bool 849 #: True if the model can be run as an opencl model. If for some reason 850 #: the model cannot be run in opencl (e.g., because the model passes 851 #: functions by reference), then set this to false. 852 opencl = None # type: bool 845 853 #: True if the model is a structure factor used to model the interaction 846 854 #: between form factor models. This will default to False if it is not -
sasmodels/models/hollow_cylinder.py
r9b79f29 rf102a96 80 80 ["thickness", "Ang", 10.0, [0, inf], "volume", "Cylinder wall thickness"], 81 81 ["length", "Ang", 400.0, [0, inf], "volume", "Cylinder total length"], 82 ["sld", "1 /Ang^2", 6.3, [-inf, inf], "sld", "Cylinder sld"],83 ["sld_solvent", "1 /Ang^2", 1, [-inf, inf], "sld", "Solvent sld"],82 ["sld", "1e-6/Ang^2", 6.3, [-inf, inf], "sld", "Cylinder sld"], 83 ["sld_solvent", "1e-6/Ang^2", 1, [-inf, inf], "sld", "Solvent sld"], 84 84 ["theta", "degrees", 90, [-360, 360], "orientation", "Cylinder axis to beam angle"], 85 85 ["phi", "degrees", 0, [-360, 360], "orientation", "Rotation about beam"], -
sasmodels/models/lib/sas_3j1x_x.c
r473a9f1 reb2946f 46 46 double sas_3j1x_x(double q) 47 47 { 48 if (q < SPH_J1C_CUTOFF) { 48 // 2017-05-18 PAK - support negative q 49 if (fabs(q) < SPH_J1C_CUTOFF) { 49 50 const double q2 = q*q; 50 51 return (1.0 + q2*(-3./30. + q2*(3./840. + q2*(-3./45360.))));// + q2*(3./3991680.))))); -
sasmodels/models/lib/sas_J0.c
rc8902ac reb2946f 236 236 xx = x; 237 237 238 if( x <= 2.0 ) { 238 // 2017-05-18 PAK - support negative x 239 if( xx <= 2.0 ) { 239 240 z = xx * xx; 240 if( x < 1.0e-3 )241 if( xx < 1.0e-3 ) 241 242 return( 1.0 - 0.25*z ); 242 243 … … 245 246 } 246 247 247 q = 1.0/x ;248 q = 1.0/xx; 248 249 w = sqrt(q); 249 250 -
sasmodels/models/lib/sas_J1.c
r473a9f1 r5181ccc 109 109 { 110 110 111 double w, z, p, q, xn;111 double w, z, p, q, abs_x, sign_x; 112 112 113 113 const double Z1 = 1.46819706421238932572E1; 114 114 const double Z2 = 4.92184563216946036703E1; 115 const double THPIO4 = 2.35619449019234492885; 116 const double SQ2OPI = 0.79788456080286535588; 117 118 w = x; 119 if( x < 0 ) 120 w = -x; 121 122 if( w <= 5.0 ) { 123 z = x * x; 115 116 // 2017-05-18 PAK - mathematica and mpmath use J1(-x) = -J1(x) 117 if (x < 0) { 118 abs_x = -x; 119 sign_x = -1.0; 120 } else { 121 abs_x = x; 122 sign_x = 1.0; 123 } 124 125 if( abs_x <= 5.0 ) { 126 z = abs_x * abs_x; 124 127 w = polevl( z, RPJ1, 3 ) / p1evl( z, RQJ1, 8 ); 125 w = w * x * (z - Z1) * (z - Z2);126 return( w );128 w = w * abs_x * (z - Z1) * (z - Z2); 129 return( sign_x * w ); 127 130 } 128 131 129 w = 5.0/ x;132 w = 5.0/abs_x; 130 133 z = w * w; 131 132 134 p = polevl( z, PPJ1, 6)/polevl( z, PQJ1, 6 ); 133 135 q = polevl( z, QPJ1, 7)/p1evl( z, QQJ1, 7 ); 134 136 135 xn = x - THPIO4; 136 137 double sn, cn; 138 SINCOS(xn, sn, cn); 139 p = p * cn - w * q * sn; 140 141 return( p * SQ2OPI / sqrt(x) ); 137 // 2017-05-19 PAK improve accuracy using trig identies 138 // original: 139 // const double THPIO4 = 2.35619449019234492885; 140 // const double SQ2OPI = 0.79788456080286535588; 141 // double sin_xn, cos_xn; 142 // SINCOS(abs_x - THPIO4, sin_xn, cos_xn); 143 // p = p * cos_xn - w * q * sin_xn; 144 // return( sign_x * p * SQ2OPI / sqrt(abs_x) ); 145 // expanding p*cos(a - 3 pi/4) - wq sin(a - 3 pi/4) 146 // [ p(sin(a) - cos(a)) + wq(sin(a) + cos(a)) / sqrt(2) 147 // note that sqrt(1/2) * sqrt(2/pi) = sqrt(1/pi) 148 const double SQRT1_PI = 0.56418958354775628; 149 double sin_x, cos_x; 150 SINCOS(abs_x, sin_x, cos_x); 151 p = p*(sin_x - cos_x) + w*q*(sin_x + cos_x); 152 return( sign_x * p * SQRT1_PI / sqrt(abs_x) ); 142 153 } 143 154 … … 179 190 }; 180 191 181 float cephes_j1f(float x )192 float cephes_j1f(float xx) 182 193 { 183 194 184 float x x, w, z, p, q, xn;195 float x, w, z, p, q, xn; 185 196 186 197 const float Z1 = 1.46819706421238932572E1; 187 const float THPIO4F = 2.35619449019234492885; /* 3*pi/4 */ 188 189 190 x x =x;191 if( x x< 0 )192 x x = -x;193 194 if( x x<= 2.0 ) {195 z = x x * xx;196 p = (z-Z1) * x x* polevl( z, JPJ1, 4 );197 return( p );198 199 200 // 2017-05-18 PAK - mathematica and mpmath use J1(-x) = -J1(x) 201 x = xx; 202 if( x < 0 ) 203 x = -xx; 204 205 if( x <= 2.0 ) { 206 z = x * x; 207 p = (z-Z1) * x * polevl( z, JPJ1, 4 ); 208 return( xx < 0. ? -p : p ); 198 209 } 199 210 … … 203 214 p = w * polevl( q, MO1J1, 7); 204 215 w = q*q; 205 xn = q * polevl( w, PH1J1, 7) - THPIO4F; 206 p = p * cos(xn + xx); 207 208 return(p); 216 // 2017-05-19 PAK improve accuracy using trig identies 217 // original: 218 // const float THPIO4F = 2.35619449019234492885; /* 3*pi/4 */ 219 // xn = q * polevl( w, PH1J1, 7) - THPIO4F; 220 // p = p * cos(xn + x); 221 // return( xx < 0. ? -p : p ); 222 // expanding cos(a + b - 3 pi/4) is 223 // [sin(a)sin(b) + sin(a)cos(b) + cos(a)sin(b)-cos(a)cos(b)] / sqrt(2) 224 xn = q * polevl( w, PH1J1, 7); 225 float cos_xn, sin_xn; 226 float cos_x, sin_x; 227 SINCOS(xn, sin_xn, cos_xn); // about xn and 1 228 SINCOS(x, sin_x, cos_x); 229 p *= M_SQRT1_2*(sin_xn*(sin_x+cos_x) + cos_xn*(sin_x-cos_x)); 230 231 return( xx < 0. ? -p : p ); 209 232 } 210 233 #endif -
sasmodels/models/lib/sas_erf.c
rb3796fa reb2946f 165 165 // the erf function instead and z < 1.0. 166 166 //return (1.0 - cephes_erf(a)); 167 z = x * x; 168 y = x * polevl(z, TD, 4) / p1evl(z, UD, 5); 169 170 return y; 167 // 2017-05-18 PAK - use erf(a) rather than erf(|a|) 168 z = a * a; 169 y = a * polevl(z, TD, 4) / p1evl(z, UD, 5); 170 171 return 1.0 - y; 171 172 } 172 173 … … 279 280 //is explicit here for the case < 1.0 280 281 //return (1.0 - sas_erf(a)); 281 z = x * x; 282 y = x * polevl( z, TF, 6 ); 283 284 return y; 282 // 2017-05-18 PAK - use erf(a) rather than erf(|a|) 283 z = a * a; 284 y = a * polevl( z, TF, 6 ); 285 286 return 1.0 - y; 285 287 } 286 288 -
sasmodels/models/stacked_disks.py
r9802ab3 r9d50a1e 156 156 qx = q*cos(pi/6.0) 157 157 qy = q*sin(pi/6.0) 158 tests = [159 158 # Accuracy tests based on content in test/utest_extra_models.py. 160 159 # Added 2 tests with n_stacked = 5 using SasView 3.1.2 - PDB; 161 160 # for which alas q=0.001 values seem closer to n_stacked=1 not 5, 162 161 # changed assuming my 4.1 code OK, RKH 163 [{'thick_core': 10.0, 164 'thick_layer': 15.0, 165 'radius': 3000.0, 166 'n_stacking': 1.0, 167 'sigma_d': 0.0, 168 'sld_core': 4.0, 169 'sld_layer': -0.4, 170 'solvent_sd': 5.0, 162 tests = [ 163 [{'thick_core': 10.0, 164 'thick_layer': 15.0, 165 'radius': 3000.0, 166 'n_stacking': 1.0, 167 'sigma_d': 0.0, 168 'sld_core': 4.0, 169 'sld_layer': -0.4, 170 'sld_solvent': 5.0, 171 171 'theta': 90.0, 172 172 'phi': 0.0, … … 181 181 'sld_core': 4.0, 182 182 'sld_layer': -0.4, 183 's olvent_sd': 5.0,183 'sld_solvent': 5.0, 184 184 'theta': 90.0, 185 185 'phi': 0.0, … … 196 196 'sld_core': 4.0, 197 197 'sld_layer': -0.4, 198 's olvent_sd': 5.0,198 'sld_solvent': 5.0, 199 199 'theta': 90.0, 200 200 'phi': 20.0, 201 201 'scale': 0.01, 202 'background': 0.001 },203 (qx, qy), 0.0491167089952],202 'background': 0.001, 203 }, (qx, qy), 0.0491167089952], 204 204 [{'thick_core': 10.0, 205 205 'thick_layer': 15.0, … … 209 209 'sld_core': 4.0, 210 210 'sld_layer': -0.4, 211 's olvent_sd': 5.0,211 'sld_solvent': 5.0, 212 212 'theta': 90.0, 213 213 'phi': 0.0, … … 225 225 'sld_core': 4.0, 226 226 'sld_layer': -0.4, 227 's olvent_sd': 5.0,227 'sld_solvent': 5.0, 228 228 'theta': 90.0, 229 229 'phi': 0.0, … … 240 240 'sld_core': 4.0, 241 241 'sld_layer': -0.4, 242 's olvent_sd': 5.0,242 'sld_solvent': 5.0, 243 243 'theta': 90.0, 244 244 'phi': 0.0, … … 246 246 'background': 0.001, 247 247 }, ([0.4, 0.5]), [0.00105074, 0.00121761]], 248 [{'thick_core': 10.0, 249 'thick_layer': 15.0, 250 'radius': 3000.0, 251 'n_stacking': 1.0, 252 'sigma_d': 0.0, 253 'sld_core': 4.0, 254 'sld_layer': -0.4, 255 'solvent_sd': 5.0, 256 'theta': 90.0, 257 'phi': 20.0, 258 'scale': 0.01, 259 'background': 0.001, 260 }, (qx, qy), 0.0341738733124 ], 261 262 [{'thick_core': 10.0, 263 'thick_layer': 15.0, 264 'radius': 3000.0, 265 'n_stacking': 1.0, 266 'sigma_d': 0.0, 267 'sld_core': 4.0, 268 'sld_layer': -0.4, 269 'solvent_sd': 5.0, 248 # [{'thick_core': 10.0, 249 # 'thick_layer': 15.0, 250 # 'radius': 3000.0, 251 # 'n_stacking': 1.0, 252 # 'sigma_d': 0.0, 253 # 'sld_core': 4.0, 254 # 'sld_layer': -0.4, 255 # 'sld_solvent': 5.0, 256 # 'theta': 90.0, 257 # 'phi': 20.0, 258 # 'scale': 0.01, 259 # 'background': 0.001, 260 # 2017-05-18 PAK temporarily suppress output of qx,qy test; j1 is not accurate for large qr 261 # }, (qx, qy), 0.0341738733124], 262 # }, (qx, qy), None], 263 264 [{'thick_core': 10.0, 265 'thick_layer': 15.0, 266 'radius': 3000.0, 267 'n_stacking': 1.0, 268 'sigma_d': 0.0, 269 'sld_core': 4.0, 270 'sld_layer': -0.4, 271 'sld_solvent': 5.0, 270 272 'theta': 90.0, 271 273 'phi': 0.0, … … 274 276 }, ([1.3, 1.57]), [0.0010039, 0.0010038]], 275 277 ] 276 # 11Jan2017 RKH checking unit test agai, note they are all 1D, no 2D 277 278 # 11Jan2017 RKH checking unit test again, note they are all 1D, no 2D -
sasmodels/models/two_power_law.py
r40a87fa rbb4b509 120 120 }, 0.150141, 0.125945], 121 121 122 [{'coeff cent_1': 1.0,122 [{'coefficent_1': 1.0, 123 123 'crossover': 0.04, 124 124 'power_1': 1.0, … … 127 127 }, 0.442528, 0.00166884], 128 128 129 [{'coeff cent_1': 1.0,129 [{'coefficent_1': 1.0, 130 130 'crossover': 0.04, 131 131 'power_1': 1.0,
Note: See TracChangeset
for help on using the changeset viewer.