Changeset 5edfe12 in sasmodels


Ignore:
Timestamp:
Nov 24, 2015 6:13:15 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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
Message:

support long double kernels for precision limited models

Location:
sasmodels
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    rb514adf r5edfe12  
    233233    model_definition = core.load_model_definition(name) 
    234234 
    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') 
    236239 
    237240    opt_values = dict(split 
     
    239242                      if len(split) == 2) 
    240243    # 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) 
    242248    Nq = int(opt_values.get('-Nq', '128')) 
    243249    res = float(opt_values.get('-res', '0')) 
     
    248254 
    249255    # 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') 
    251259    cutoff = float(opt_values.get('-cutoff','1e-5')) 
    252260 
     
    371379 
    372380    -plot*/-noplot plots or suppress the plot of the model 
    373     -single*/-double uses double precision for comparison 
     381    -single*/-double/-longdouble uses double precision for comparison 
    374382    -lowq*/-midq/-highq/-exq use q values up to 0.05, 0.2, 1.0, 10.0 
    375383    -Nq=128 sets the number of Q points in the data set 
     
    395403NAME_OPTIONS = set([ 
    396404    'plot','noplot', 
    397     'single','double', 
     405    'single','double','longdouble', 
    398406    'lowq','midq','highq','exq', 
    399407    '2d','1d', 
  • sasmodels/generate.py

    rcd3dba0 r5edfe12  
    197197# TODO: identify model files which have changed since loading and reload them. 
    198198 
    199 __all__ = ["make", "doc", "sources", "use_single"] 
     199__all__ = ["make", "doc", "sources", "use_single", "use_long_double"] 
    200200 
    201201import sys 
     
    206206C_KERNEL_TEMPLATE_PATH = joinpath(dirname(__file__), 'kernel_template.c') 
    207207 
     208F128 = np.dtype('float128') 
    208209F64 = np.dtype('float64') 
    209210F32 = np.dtype('float32') 
     
    322323    source = re.sub(r'[^a-zA-Z_](\d*[.]\d+|\d+[.]\d*)([eE][+-]?\d+)?', 
    323324                    r'\g<0>f', source) 
     325    return source 
     326 
     327def 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) 
    324340    return source 
    325341 
  • sasmodels/kerneldll.py

    r92da231 r5edfe12  
    4949import tempfile 
    5050import ctypes as ct 
    51 from ctypes import c_void_p, c_int, c_double, c_float 
     51from ctypes import c_void_p, c_int, c_longdouble, c_double, c_float 
    5252 
    5353import numpy as np 
     
    9696    if np.dtype(dtype) == generate.F32: 
    9797        basename += "32" 
     98    elif np.dtype(dtype) == generate.F64: 
     99        basename += "64" 
     100    else: 
     101        basename += "128" 
    98102    return joinpath(DLL_PATH, basename+'.so') 
    99103 
     
    118122    models are allowed as DLLs. 
    119123    """ 
    120     if not ALLOW_SINGLE_PRECISION_DLLS: dtype = "double"   # Force 64-bit dll 
    121124    dtype = np.dtype(dtype) 
     125    if dtype == generate.F32 and not ALLOW_SINGLE_PRECISION_DLLS: 
     126        dtype = generate.F64  # Force 64-bit dll 
    122127 
    123128    if callable(info.get('Iq',None)): 
     
    127132        source = generate.use_single(source) 
    128133        tempfile_prefix = 'sas_'+info['name']+'32_' 
     134    elif dtype == generate.F64: 
     135        tempfile_prefix = 'sas_'+info['name']+'64_' 
    129136    else: 
    130         tempfile_prefix = 'sas_'+info['name']+'_' 
     137        source = generate.use_long_double(source) 
     138        tempfile_prefix = 'sas_'+info['name']+'128_' 
    131139 
    132140    source_files = generate.sources(info) + [info['filename']] 
     
    196204            raise 
    197205 
    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) 
    199209        pd_args_1d = [c_void_p, fp] + [c_int]*Npd1d if Npd1d else [] 
    200210        pd_args_2d= [c_void_p, fp] + [c_int]*Npd2d if Npd2d else [] 
     
    265275 
    266276    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) 
    268280 
    269281        nq = c_int(self.q_input.nq) 
Note: See TracChangeset for help on using the changeset viewer.