Changeset 5edfe12 in sasmodels
- Timestamp:
- Nov 24, 2015 6:13:15 PM (9 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:
- 7f7f99f
- Parents:
- 92da231
- Location:
- sasmodels
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
rb514adf r5edfe12 233 233 model_definition = core.load_model_definition(name) 234 234 235 view = 'linear' if '-linear' in opts else 'log' if '-log' in opts else 'q4' if '-q4' in opts else 'log' 235 view = ('linear' if '-linear' in opts 236 else 'log' if '-log' in opts 237 else 'q4' if '-q4' in opts 238 else 'log') 236 239 237 240 opt_values = dict(split … … 239 242 if len(split) == 2) 240 243 # Sort out data 241 qmax = 10.0 if '-exq' in opts else 1.0 if '-highq' in opts else 0.2 if '-midq' in opts else 0.05 244 qmax = (10.0 if '-exq' in opts 245 else 1.0 if '-highq' in opts 246 else 0.2 if '-midq' in opts 247 else 0.05) 242 248 Nq = int(opt_values.get('-Nq', '128')) 243 249 res = float(opt_values.get('-res', '0')) … … 248 254 249 255 # modelling accuracy is determined by dtype and cutoff 250 dtype = 'double' if '-double' in opts else 'single' 256 dtype = ('longdouble' if '-longdouble' in opts 257 else 'double' if '-double' in opts 258 else 'single') 251 259 cutoff = float(opt_values.get('-cutoff','1e-5')) 252 260 … … 371 379 372 380 -plot*/-noplot plots or suppress the plot of the model 373 -single*/-double uses double precision for comparison381 -single*/-double/-longdouble uses double precision for comparison 374 382 -lowq*/-midq/-highq/-exq use q values up to 0.05, 0.2, 1.0, 10.0 375 383 -Nq=128 sets the number of Q points in the data set … … 395 403 NAME_OPTIONS = set([ 396 404 'plot','noplot', 397 'single','double', 405 'single','double','longdouble', 398 406 'lowq','midq','highq','exq', 399 407 '2d','1d', -
sasmodels/generate.py
rcd3dba0 r5edfe12 197 197 # TODO: identify model files which have changed since loading and reload them. 198 198 199 __all__ = ["make", "doc", "sources", "use_single" ]199 __all__ = ["make", "doc", "sources", "use_single", "use_long_double"] 200 200 201 201 import sys … … 206 206 C_KERNEL_TEMPLATE_PATH = joinpath(dirname(__file__), 'kernel_template.c') 207 207 208 F128 = np.dtype('float128') 208 209 F64 = np.dtype('float64') 209 210 F32 = np.dtype('float32') … … 322 323 source = re.sub(r'[^a-zA-Z_](\d*[.]\d+|\d+[.]\d*)([eE][+-]?\d+)?', 323 324 r'\g<0>f', source) 325 return source 326 327 def use_long_double(source): 328 """ 329 Convert code from double precision to long double precision. 330 """ 331 # Convert double keyword to float. Accept an 'n' parameter for vector 332 # values, where n is 2, 4, 8 or 16. Assume complex numbers are represented 333 # as cdouble which is typedef'd to double2. 334 source = re.sub(r'(^|[^a-zA-Z0-9_]c?)double(([248]|16)?($|[^a-zA-Z0-9_]))', 335 r'\1long double\2', source) 336 # Convert floating point constants to single by adding 'f' to the end. 337 # OS/X driver complains if you don't do this. 338 source = re.sub(r'[^a-zA-Z_](\d*[.]\d+|\d+[.]\d*)([eE][+-]?\d+)?', 339 r'\g<0>L', source) 324 340 return source 325 341 -
sasmodels/kerneldll.py
r92da231 r5edfe12 49 49 import tempfile 50 50 import ctypes as ct 51 from ctypes import c_void_p, c_int, c_ double, c_float51 from ctypes import c_void_p, c_int, c_longdouble, c_double, c_float 52 52 53 53 import numpy as np … … 96 96 if np.dtype(dtype) == generate.F32: 97 97 basename += "32" 98 elif np.dtype(dtype) == generate.F64: 99 basename += "64" 100 else: 101 basename += "128" 98 102 return joinpath(DLL_PATH, basename+'.so') 99 103 … … 118 122 models are allowed as DLLs. 119 123 """ 120 if not ALLOW_SINGLE_PRECISION_DLLS: dtype = "double" # Force 64-bit dll121 124 dtype = np.dtype(dtype) 125 if dtype == generate.F32 and not ALLOW_SINGLE_PRECISION_DLLS: 126 dtype = generate.F64 # Force 64-bit dll 122 127 123 128 if callable(info.get('Iq',None)): … … 127 132 source = generate.use_single(source) 128 133 tempfile_prefix = 'sas_'+info['name']+'32_' 134 elif dtype == generate.F64: 135 tempfile_prefix = 'sas_'+info['name']+'64_' 129 136 else: 130 tempfile_prefix = 'sas_'+info['name']+'_' 137 source = generate.use_long_double(source) 138 tempfile_prefix = 'sas_'+info['name']+'128_' 131 139 132 140 source_files = generate.sources(info) + [info['filename']] … … 196 204 raise 197 205 198 fp = c_float if self.dtype == generate.F32 else c_double 206 fp = (c_float if self.dtype == generate.F32 207 else c_double if self.dtype == generate.F64 208 else c_longdouble) 199 209 pd_args_1d = [c_void_p, fp] + [c_int]*Npd1d if Npd1d else [] 200 210 pd_args_2d= [c_void_p, fp] + [c_int]*Npd2d if Npd2d else [] … … 265 275 266 276 def __call__(self, fixed_pars, pd_pars, cutoff): 267 real = np.float32 if self.q_input.dtype == generate.F32 else np.float64 277 real = (np.float32 if self.q_input.dtype == generate.F32 278 else np.float64 if self.q_input.dtype == generate.F64 279 else np.float128) 268 280 269 281 nq = c_int(self.q_input.nq)
Note: See TracChangeset
for help on using the changeset viewer.