Changes in sasmodels/core.py [b0de252:d92182f] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    rb0de252 rd92182f  
    6464        * all: all models 
    6565        * py: python models only 
    66         * c: compiled models only 
    67         * single: models which support single precision 
    68         * double: models which require double precision 
    69         * opencl: controls if OpenCL is supperessed 
    70         * 1d: models which are 1D only, or 2D using abs(q) 
    71         * 2d: models which can be 2D 
    72         * magnetic: models with an sld 
    73         * nommagnetic: models without an sld 
     66        * c: c models only 
     67        * single: c models which support single precision 
     68        * double: c models which require double precision 
     69        * opencl: c models which run in opencl 
     70        * dll: c models which do not run in opencl 
     71        * 1d: models without orientation 
     72        * 2d: models with orientation 
     73        * magnetic: models supporting magnetic sld 
     74        * nommagnetic: models without magnetic parameter 
    7475 
    7576    For multiple conditions, combine with plus.  For example, *c+single+2d* 
     
    9596    info = load_model_info(name) 
    9697    pars = info.parameters.kernel_parameters 
    97     if kind == "py" and callable(info.Iq): 
    98         return True 
    99     elif kind == "c" and not callable(info.Iq): 
    100         return True 
    101     elif kind == "double" and not info.single: 
    102         return True 
    103     elif kind == "single" and info.single: 
    104         return True 
    105     elif kind == "opencl" and info.opencl: 
    106         return True 
    107     elif kind == "2d" and any(p.type == 'orientation' for p in pars): 
    108         return True 
    109     elif kind == "1d" and all(p.type != 'orientation' for p in pars): 
    110         return True 
    111     elif kind == "magnetic" and any(p.type == 'sld' for p in pars): 
    112         return True 
    113     elif kind == "nonmagnetic" and any(p.type != 'sld' for p in pars): 
    114         return True 
     98    # TODO: may be adding Fq to the list at some point 
     99    is_pure_py = callable(info.Iq) 
     100    if kind == "py": 
     101        return is_pure_py 
     102    elif kind == "c": 
     103        return not is_pure_py 
     104    elif kind == "double": 
     105        return not info.single and not is_pure_py 
     106    elif kind == "single": 
     107        return info.single and not is_pure_py 
     108    elif kind == "opencl": 
     109        return info.opencl 
     110    elif kind == "dll": 
     111        return not info.opencl and not is_pure_py 
     112    elif kind == "2d": 
     113        return any(p.type == 'orientation' for p in pars) 
     114    elif kind == "1d": 
     115        return all(p.type != 'orientation' for p in pars) 
     116    elif kind == "magnetic": 
     117        return any(p.type == 'sld' for p in pars) 
     118    elif kind == "nonmagnetic": 
     119        return not any(p.type == 'sld' for p in pars) 
    115120    return False 
    116121 
     
    206211 
    207212    numpy_dtype, fast, platform = parse_dtype(model_info, dtype, platform) 
    208  
    209213    source = generate.make_source(model_info) 
    210214    if platform == "dll": 
     
    271275    # Assign default platform, overriding ocl with dll if OpenCL is unavailable 
    272276    # If opencl=False OpenCL is switched off 
    273  
    274277    if platform is None: 
    275278        platform = "ocl" 
     
    318321 
    319322    return numpy_dtype, fast, platform 
    320  
    321 def list_models_main(): 
    322     # type: () -> None 
    323     """ 
    324     Run list_models as a main program.  See :func:`list_models` for the 
    325     kinds of models that can be requested on the command line. 
    326     """ 
    327     import sys 
    328     kind = sys.argv[1] if len(sys.argv) > 1 else "all" 
    329     print("\n".join(list_models(kind))) 
    330323 
    331324def test_composite_order(): 
     
    382375    model = load_model("cylinder@hardsphere*sphere") 
    383376    actual = [p.name for p in model.info.parameters.kernel_parameters] 
    384     target = ("sld sld_solvent radius length theta phi volfraction" 
     377    target = ("sld sld_solvent radius length theta phi" 
     378              " radius_effective volfraction " 
     379              " structure_factor_mode radius_effective_mode" 
    385380              " A_sld A_sld_solvent A_radius").split() 
    386381    assert target == actual, "%s != %s"%(target, actual) 
    387382 
     383def list_models_main(): 
     384    # type: () -> None 
     385    """ 
     386    Run list_models as a main program.  See :func:`list_models` for the 
     387    kinds of models that can be requested on the command line. 
     388    """ 
     389    import sys 
     390    kind = sys.argv[1] if len(sys.argv) > 1 else "all" 
     391    try: 
     392        models = list_models(kind) 
     393    except Exception as exc: 
     394        print(list_models.__doc__) 
     395        return 1 
     396 
     397    print("\n".join(list_models(kind))) 
     398 
    388399if __name__ == "__main__": 
    389400    list_models_main() 
Note: See TracChangeset for help on using the changeset viewer.