Changes in sasmodels/compare.py [72a081d:af92b73] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r72a081d raf92b73  
    369369            model = MultiplicationModel(P, S) 
    370370        else: 
    371             raise ValueError("sasview mixture models not supported by compare") 
     371            raise ValueError("mixture models not handled yet") 
    372372    else: 
    373373        model = get_model(model_info['oldname']) 
     
    424424    Return a model calculator using the OpenCL calculation engine. 
    425425    """ 
    426     try: 
    427         model = core.build_model(model_info, dtype=dtype, platform="ocl") 
    428     except Exception as exc: 
    429         print(exc) 
    430         print("... trying again with single precision") 
    431         model = core.build_model(model_info, dtype='single', platform="ocl") 
     426    def builder(model_info): 
     427        try: 
     428            return core.build_model(model_info, dtype=dtype, platform="ocl") 
     429        except Exception as exc: 
     430            print(exc) 
     431            print("... trying again with single precision") 
     432            return core.build_model(model_info, dtype='single', platform="ocl") 
     433    if model_info['composition']: 
     434        composition_type, parts = model_info['composition'] 
     435        if composition_type == 'product': 
     436            P, S = [builder(p) for p in parts] 
     437            model = product.ProductModel(P, S) 
     438        else: 
     439            raise ValueError("mixture models not handled yet") 
     440    else: 
     441        model = builder(model_info) 
    432442    calculator = DirectModel(data, model, cutoff=cutoff) 
    433443    calculator.engine = "OCL%s"%DTYPE_MAP[dtype] 
     
    440450    if dtype == 'quad': 
    441451        dtype = 'longdouble' 
    442     model = core.build_model(model_info, dtype=dtype, platform="dll") 
     452    def builder(model_info): 
     453        return core.build_model(model_info, dtype=dtype, platform="dll") 
     454 
     455    if model_info['composition']: 
     456        composition_type, parts = model_info['composition'] 
     457        if composition_type == 'product': 
     458            P, S = [builder(p) for p in parts] 
     459            model = product.ProductModel(P, S) 
     460        else: 
     461            raise ValueError("mixture models not handled yet") 
     462    else: 
     463        model = builder(model_info) 
    443464    calculator = DirectModel(data, model, cutoff=cutoff) 
    444465    calculator.engine = "OMP%s"%DTYPE_MAP[dtype] 
     
    694715        print("expected parameters: model N1 N2") 
    695716 
     717    def _get_info(name): 
     718        try: 
     719            model_info = core.load_model_info(name) 
     720        except ImportError, exc: 
     721            print(str(exc)) 
     722            print("Use one of:\n    " + models) 
     723            sys.exit(1) 
     724        return model_info 
     725 
    696726    name = args[0] 
    697     try: 
    698         model_info = core.load_model_info(name) 
    699     except ImportError, exc: 
    700         print(str(exc)) 
    701         print("Could not find model; use one of:\n    " + models) 
    702         sys.exit(1) 
     727    if '*' in name: 
     728        parts = [_get_info(k) for k in name.split('*')] 
     729        model_info = product.make_product_info(*parts) 
     730    else: 
     731        model_info = _get_info(name) 
    703732 
    704733    invalid = [o[1:] for o in flags 
     
    720749        'res'       : 0.0, 
    721750        'accuracy'  : 'Low', 
    722         'cutoff'    : 0.0, 
     751        'cutoff'    : 1e-5, 
    723752        'seed'      : -1,  # default to preset 
    724753        'mono'      : False, 
Note: See TracChangeset for help on using the changeset viewer.