Changeset 4bfd277 in sasmodels for sasmodels/model_test.py


Ignore:
Timestamp:
Apr 8, 2016 10:11:16 AM (8 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:
2afc26d
Parents:
d2fc9a4
Message:

support ER/VR calls with vector parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/model_test.py

    r6d6508e r4bfd277  
    5656from .direct_model import call_kernel, get_weights 
    5757from .exception import annotate_exception 
    58  
    59  
    60 def call_ER(model_info, values): 
     58from .modelinfo import expand_pars 
     59 
     60def call_ER(model_info, pars): 
    6161    """ 
    6262    Call the model ER function using *values*. *model_info* is either 
     
    6767        return 1.0 
    6868    else: 
    69         vol_pars = [get_weights(parameter, values) 
    70                     for parameter in model_info.parameters.call_parameters 
    71                     if parameter.type == 'volume'] 
    72         value, weight = dispersion_mesh(vol_pars) 
     69        value, weight = _vol_pars(model_info, pars) 
    7370        individual_radii = model_info.ER(*value) 
    7471        return np.sum(weight*individual_radii) / np.sum(weight) 
    7572 
    76 def call_VR(model_info, values): 
     73def call_VR(model_info, pars): 
    7774    """ 
    7875    Call the model VR function using *pars*. 
     
    8380        return 1.0 
    8481    else: 
    85         vol_pars = [get_weights(parameter, values) 
    86                     for parameter in model_info.parameters.call_parameters 
    87                     if parameter.type == 'volume'] 
    88         value, weight = dispersion_mesh(vol_pars) 
     82        value, weight = _vol_pars(model_info, pars) 
    8983        whole, part = model_info.VR(*value) 
    9084        return np.sum(weight*part)/np.sum(weight*whole) 
     85 
     86def _vol_pars(model_info, pars): 
     87    vol_pars = [get_weights(p, pars) 
     88                for p in model_info.parameters.call_parameters 
     89                if p.type == 'volume'] 
     90    value, weight = dispersion_mesh(model_info, vol_pars) 
     91    return value, weight 
    9192 
    9293 
     
    175176            self.dtype = dtype 
    176177 
    177             setattr(self, test_method_name, self._runTest) 
     178            setattr(self, test_method_name, self.run_all) 
    178179            unittest.TestCase.__init__(self, test_method_name) 
    179180 
    180         def _runTest(self): 
     181        def run_all(self): 
    181182            smoke_tests = [ 
    182183                [{}, 0.1, None], 
     
    191192                                    platform=self.platform) 
    192193                for test in smoke_tests + tests: 
    193                     self._run_one_test(model, test) 
     194                    self.run_one(model, test) 
    194195 
    195196                if not tests and self.platform == "dll": 
     
    205206                raise 
    206207 
    207         def _run_one_test(self, model, test): 
     208        def run_one(self, model, test): 
    208209            pars, x, y = test 
     210            pars = expand_pars(self.info.parameters, pars) 
    209211 
    210212            if not isinstance(y, list): 
     
    229231                actual = call_kernel(kernel, pars) 
    230232 
    231             self.assertGreater(len(actual), 0) 
     233            self.assertTrue(len(actual) > 0) 
    232234            self.assertEqual(len(y), len(actual)) 
    233235 
     
    311313    tests = make_suite(['opencl', 'dll'], ['all']) 
    312314    for test_i in tests: 
    313         yield test_i._runTest 
     315        yield test_i.run_all 
    314316 
    315317 
Note: See TracChangeset for help on using the changeset viewer.