Changeset bb4b509 in sasmodels


Ignore:
Timestamp:
May 16, 2017 12:14:04 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
452b168
Parents:
ba62072
Message:

check parameter names as part of test; PEP8 cleanup

Location:
sasmodels
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/generate.py

    rc4e3215 rbb4b509  
    492492 
    493493def test_tag_float(): 
    494  
    495     cases=""" 
     494    """check that floating point constants are properly identified and tagged with 'f'""" 
     495 
     496    cases = """ 
    496497ZP  : 0. 
    497498ZPF : 0.0,0.01,0.1 
     
    519520""" 
    520521 
    521     output=""" 
     522    output = """ 
    522523ZP  : 0.f 
    523524ZPF : 0.0f,0.01f,0.1f 
     
    611612    # type: (str, List[Parameter]) -> List[str] 
    612613    """ 
    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. 
    614617    """ 
    615618    return [p.as_call_reference(prefix) for p in pars] 
     
    733736        call_iqxy = "#define CALL_IQ(_q,_i,_v) Iq(%s)" % (",".join(pars_sqrt)) 
    734737 
    735     magpars = [k-2 for k,p in enumerate(partable.call_parameters) 
     738    magpars = [k-2 for k, p in enumerate(partable.call_parameters) 
    736739               if p.type == 'sld'] 
    737740 
     
    742745    source.append("#define NUM_MAGNETIC %d" % partable.nmagnetic) 
    743746    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]): 
    745748        source.append("#define MAGNETIC_PAR%d %d"%(k+1, v)) 
    746749 
     
    779782        "#undef CALL_IQ", 
    780783        "#undef KERNEL_NAME", 
    781          ] 
     784    ] 
    782785 
    783786    imagnetic = [ 
     
    872875 
    873876# TODO: need a single source for rst_prolog; it is also in doc/rst_prolog 
    874 RST_PROLOG = """\ 
     877RST_PROLOG = r"""\ 
    875878.. |Ang| unicode:: U+212B 
    876879.. |Ang^-1| replace:: |Ang|\ :sup:`-1` 
  • sasmodels/kernel_header.c

    rb00a646 rbb4b509  
    1414#    define SINCOS(angle,svar,cvar) do {const double _t_=angle; svar=sin(_t_);cvar=cos(_t_);} while (0) 
    1515#  endif 
    16    // Intel CPU on Mac gives strange values for erf(); also on the tested 
     16   // Intel CPU on Mac gives strange values for erf(); on the verified 
    1717   // platforms (intel, nvidia, amd), the cephes erf() is significantly 
    1818   // faster than that available in the native OpenCL. 
     
    5757         typedef int int32_t; 
    5858         #include <math.h> 
    59          // TODO: test isnan 
     59         // TODO: check isnan is correct 
    6060         inline double _isnan(double x) { return x != x; } // hope this doesn't optimize away! 
    6161         #undef isnan 
  • sasmodels/model_test.py

    r3330bb4 rbb4b509  
    8585        skip = [] 
    8686    for model_name in models: 
    87         if model_name in skip: continue 
     87        if model_name in skip: 
     88            continue 
    8889        model_info = load_model_info(model_name) 
    8990 
     
    239240            multiple = [test for test in self.info.tests 
    240241                        if isinstance(test[2], list) 
    241                             and not all(result is None for result in test[2])] 
     242                        and not all(result is None for result in test[2])] 
    242243            tests_has_1D_multiple = any(isinstance(test[1][0], float) 
    243244                                        for test in multiple) 
     
    262263            user_pars, x, y = test 
    263264            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)) 
    264268 
    265269            if not isinstance(y, list): 
     
    305309 
    306310    return ModelTestCase 
     311 
     312def 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 
    307328 
    308329def is_near(target, actual, digits=5): 
  • sasmodels/modelinfo.py

    r9c44b7b rbb4b509  
    101101                limits = (float(low), float(high)) 
    102102            except Exception: 
    103                 raise ValueError("invalid limits for %s: %r"%(name,user_limits)) 
     103                raise ValueError("invalid limits for %s: %r"%(name, user_limits)) 
    104104            if low >= high: 
    105105                raise ValueError("require lower limit < upper limit") 
     
    342342    def as_call_reference(self, prefix=""): 
    343343        # type: (str) -> str 
     344        """ 
     345        Return *prefix* + parameter name.  For struct references, use "v." 
     346        as the prefix. 
     347        """ 
    344348        # Note: if the parameter is a struct type, then we will need to use 
    345349        # &prefix+id.  For scalars and vectors we can just use prefix+id. 
     
    420424        self.npars = sum(p.length for p in self.kernel_parameters) 
    421425        self.nmagnetic = sum(p.length for p in self.kernel_parameters 
    422                              if p.type=='sld') 
     426                             if p.type == 'sld') 
    423427        self.nvalues = 2 + self.npars 
    424428        if self.nmagnetic: 
     
    457461        self.has_2d = any(p.type in ('orientation', 'magnetic') 
    458462                          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) 
    460464                                if p.id.startswith('M0:')] 
    461465 
     
    544548                              'magnetic', 'magnetic amplitude for '+p.description), 
    545549                    Parameter('mtheta:'+p.id, 'degrees', 0., [-90., 90.], 
    546                                'magnetic', 'magnetic latitude for '+p.description), 
     550                              'magnetic', 'magnetic latitude for '+p.description), 
    547551                    Parameter('mphi:'+p.id, 'degrees', 0., [-180., 180.], 
    548                                'magnetic', 'magnetic longitude for '+p.description), 
     552                              'magnetic', 'magnetic longitude for '+p.description), 
    549553                ]) 
    550554        #print("call parameters", full_list) 
     
    683687 
    684688    if (model_info.Iq is None 
    685         and model_info.Iqxy is None 
    686         and model_info.Imagnetic is None 
    687         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): 
    688692        return 
    689693 
     
    843847    #: it to False because they require double precision calculations. 
    844848    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 
    845853    #: True if the model is a structure factor used to model the interaction 
    846854    #: between form factor models.  This will default to False if it is not 
  • sasmodels/models/stacked_disks.py

    r9802ab3 rbb4b509  
    156156qx = q*cos(pi/6.0) 
    157157qy = q*sin(pi/6.0) 
    158 tests = [ 
    159158# Accuracy tests based on content in test/utest_extra_models.py. 
    160159# Added 2 tests with n_stacked = 5 using SasView 3.1.2 - PDB; 
    161160# for which alas q=0.001 values seem closer to n_stacked=1 not 5, 
    162161# 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, 
     162tests = [ 
     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, 
    171171      'theta': 90.0, 
    172172      'phi': 0.0, 
     
    181181      'sld_core': 4.0, 
    182182      'sld_layer': -0.4, 
    183       'solvent_sd': 5.0, 
     183      'sld_solvent': 5.0, 
    184184      'theta': 90.0, 
    185185      'phi': 0.0, 
     
    196196      'sld_core': 4.0, 
    197197      'sld_layer': -0.4, 
    198       'solvent_sd': 5.0, 
     198      'sld_solvent': 5.0, 
    199199      'theta': 90.0, 
    200200      'phi': 20.0, 
    201201      'scale': 0.01, 
    202       'background': 0.001}, 
    203       (qx, qy), 0.0491167089952  ], 
     202      'background': 0.001, 
     203     }, (qx, qy), 0.0491167089952], 
    204204    [{'thick_core': 10.0, 
    205205      'thick_layer': 15.0, 
     
    209209      'sld_core': 4.0, 
    210210      'sld_layer': -0.4, 
    211       'solvent_sd': 5.0, 
     211      'sld_solvent': 5.0, 
    212212      'theta': 90.0, 
    213213      'phi': 0.0, 
     
    225225      'sld_core': 4.0, 
    226226      'sld_layer': -0.4, 
    227       'solvent_sd': 5.0, 
     227      'sld_solvent': 5.0, 
    228228      'theta': 90.0, 
    229229      'phi': 0.0, 
     
    240240      'sld_core': 4.0, 
    241241      'sld_layer': -0.4, 
    242       'solvent_sd': 5.0, 
     242      'sld_solvent': 5.0, 
    243243      'theta': 90.0, 
    244244      'phi': 0.0, 
     
    253253      'sld_core': 4.0, 
    254254      'sld_layer': -0.4, 
    255       'solvent_sd': 5.0, 
     255      'sld_solvent': 5.0, 
    256256      'theta': 90.0, 
    257257      'phi': 20.0, 
    258258      'scale': 0.01, 
    259259      '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, 
     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      'sld_solvent': 5.0, 
    270270      'theta': 90.0, 
    271271      'phi': 0.0, 
     
    275275    ] 
    276276# 11Jan2017   RKH checking unit test agai, note they are all 1D, no 2D 
    277  
  • sasmodels/models/two_power_law.py

    r40a87fa rbb4b509  
    120120     }, 0.150141, 0.125945], 
    121121 
    122     [{'coeffcent_1':    1.0, 
     122    [{'coefficent_1':    1.0, 
    123123      'crossover':  0.04, 
    124124      'power_1':    1.0, 
     
    127127     }, 0.442528, 0.00166884], 
    128128 
    129     [{'coeffcent_1':    1.0, 
     129    [{'coefficent_1':    1.0, 
    130130      'crossover':  0.04, 
    131131      'power_1':    1.0, 
Note: See TracChangeset for help on using the changeset viewer.