Changeset 0763009 in sasmodels


Ignore:
Timestamp:
Oct 29, 2015 6:08:10 PM (9 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:
381ac85
Parents:
3d5c6f8
Message:

minor code cleanup

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • compare.py

    r3e6aaad r0763009  
    100100    model = sasview_model(name, **pars) 
    101101    smearer = smear_selection(data, model=model) 
     102    value = None  # silence the linter 
    102103    toc = tic() 
    103     for _ in range(Nevals): 
     104    for _ in range(max(Nevals, 1)):  # make sure there is at least one eval 
    104105        if hasattr(data, 'qx_data'): 
    105106            q = np.sqrt(data.qx_data**2 + data.qy_data**2) 
     
    120121    return value, average_time 
    121122 
    122 def eval_opencl(model_definition, pars, data, dtype='single', Nevals=1, cutoff=0): 
     123def eval_opencl(model_definition, pars, data, dtype='single', Nevals=1, cutoff=0.): 
    123124    try: 
    124125        model = core.load_model(model_definition, dtype=dtype, platform="ocl") 
     
    128129        model = core.load_model(model_definition, dtype='single', platform="ocl") 
    129130    problem = Experiment(data, Model(model, **pars), cutoff=cutoff) 
     131    value = None  # silence the linter 
    130132    toc = tic() 
    131     for _ in range(Nevals): 
     133    for _ in range(max(Nevals, 1)):  # force at least one eval 
    132134        #pars['scale'] = np.random.rand() 
    133135        problem.update() 
     
    136138    return value, average_time 
    137139 
    138 def eval_ctypes(model_definition, pars, data, dtype='double', Nevals=1, cutoff=0): 
     140def eval_ctypes(model_definition, pars, data, dtype='double', Nevals=1, cutoff=0.): 
    139141    model = core.load_model(model_definition, dtype=dtype, platform="dll") 
    140142    problem = Experiment(data, Model(model, **pars), cutoff=cutoff) 
     143    value = None  # silence the linter 
    141144    toc = tic() 
    142     for _ in range(Nevals): 
     145    for _ in range(max(Nevals, 1)):  # force at least one eval 
    143146        problem.update() 
    144147        value = problem.theory() 
     
    224227        #bad = (relerr>1e-4) 
    225228        #print relerr[bad],cpu[bad],ocl[bad],data.qx_data[bad],data.qy_data[bad] 
    226         def stats(label,err): 
    227             sorted_err = np.sort(abs(err)) 
    228             p50 = int((len(err)-1)*0.50) 
    229             p98 = int((len(err)-1)*0.98) 
    230             data = [ 
    231                 "max:%.3e"%sorted_err[-1], 
    232                 "median:%.3e"%sorted_err[p50], 
    233                 "98%%:%.3e"%sorted_err[p98], 
    234                 "rms:%.3e"%np.sqrt(np.mean(err**2)), 
    235                 "zero-offset:%+.3e"%np.mean(err), 
    236                 ] 
    237             print label,"  ".join(data) 
    238         stats("|ocl-%s|"%comp+(" "*(3+len(comp))), resid) 
    239         stats("|(ocl-%s)/%s|"%(comp,comp), relerr) 
     229        _print_stats("|ocl-%s|"%comp+(" "*(3+len(comp))), resid) 
     230        _print_stats("|(ocl-%s)/%s|"%(comp,comp), relerr) 
    240231 
    241232    # Plot if requested 
     
    277268    plt.show() 
    278269 
     270def _print_stats(label, err): 
     271    sorted_err = np.sort(abs(err)) 
     272    p50 = int((len(err)-1)*0.50) 
     273    p98 = int((len(err)-1)*0.98) 
     274    data = [ 
     275        "max:%.3e"%sorted_err[-1], 
     276        "median:%.3e"%sorted_err[p50], 
     277        "98%%:%.3e"%sorted_err[p98], 
     278        "rms:%.3e"%np.sqrt(np.mean(err**2)), 
     279        "zero-offset:%+.3e"%np.mean(err), 
     280        ] 
     281    print label,"  ".join(data) 
     282 
     283 
     284 
    279285# =========================================================================== 
    280286# 
  • sasmodels/exception.py

    r9e430d0 r0763009  
    22Utility to add annotations to python exceptions. 
    33""" 
     4 
     5# Platform cruft: WindowsError is only defined on Windows. 
     6try: 
     7    WindowsError 
     8except NameError: 
     9    class WindowsError(Exception): 
     10        pass 
    411 
    512def annotate_exception(exc, msg): 
     
    1926        KeyError: "hello while accessing 'D'" 
    2027    """ 
     28    # Can't extend WindowsError exceptions; instead raise a new exception. 
     29    # TODO: try to incorporate current stack trace in the raised exception 
     30    if isinstance(exc, WindowsError): 
     31        raise OSError(str(exc)+msg) 
     32 
    2133    args = exc.args 
    2234    if not args: 
     
    2840        except: 
    2941            exc.args = (" ".join((str(exc),msg)),) 
    30  
  • sasmodels/kernelcl.py

    raf1d68c r0763009  
    3939 
    4040from . import generate 
    41 from .kernelpy import PyModel 
    4241 
    4342F64_DEFS = """\ 
  • sasmodels/kerneldll.py

    rf3f46cd r0763009  
    148148        try: 
    149149            self.dll = ct.CDLL(self.dllpath) 
    150         except WindowsError, exc: 
    151             # TODO: update annotate_exception so it can handle WindowsError 
    152             raise RuntimeError(str(exc)+" while loading "+self.dllpath) 
    153150        except Exception, exc: 
    154151            annotate_exception(exc, "while loading "+self.dllpath) 
Note: See TracChangeset for help on using the changeset viewer.