Changeset 13ed84c in sasmodels for sasmodels/model_test.py


Ignore:
Timestamp:
Feb 4, 2016 7:31:28 PM (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:
199d40d
Parents:
5054e80
Message:

set single=False on all models that fail the single precision tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/model_test.py

    r5c962df r13ed84c  
    100100                test_name = "Model: %s, Kernel: OpenCL"%model_name 
    101101                test_method_name = "test_%s_opencl" % model_name 
     102                # Using dtype=None so that the models that are only 
     103                # correct for double precision are not tested using 
     104                # single precision.  The choice is determined by the 
     105                # presence of *single=False* in the model file. 
    102106                test = ModelTestCase(test_name, model_definition, 
    103107                                     test_method_name, 
    104                                      platform="ocl", dtype='single') 
     108                                     platform="ocl", dtype=None) 
    105109                #print("defining", test_name) 
    106110                suite.addTest(test) 
     
    157161                    ## values an error.  Only do so for the "dll" tests 
    158162                    ## to reduce noise from both opencl and dll, and because 
    159                     ## python kernels us 
     163                    ## python kernels use platform="dll". 
    160164                    #raise Exception("No test cases provided") 
    161165                    pass 
     
    198202                                    'invalid f(%s): %s' % (xi, actual_yi)) 
    199203                else: 
    200                     err = abs(yi - actual_yi) 
    201                     nrm = abs(yi) 
    202                     self.assertLess(err * 10**5, nrm, 
     204                    self.assertTrue(is_near(yi, actual_yi, 5), 
    203205                                    'f(%s); expected:%s; actual:%s' 
    204206                                    % (xi, yi, actual_yi)) 
     
    206208    return ModelTestCase 
    207209 
    208  
     210def is_near(target, actual, digits=5): 
     211    """ 
     212    Returns true if *actual* is within *digits* significant digits of *target*. 
     213    """ 
     214    import math 
     215    shift = 10**math.ceil(math.log10(abs(target))) 
     216    return abs(target-actual)/shift < 1.5*10**-digits 
    209217 
    210218def main(): 
     
    217225 
    218226    models = sys.argv[1:] 
     227    if models and models[0] == '-v': 
     228        verbosity = 2 
     229        models = models[1:] 
     230    else: 
     231        verbosity = 1 
    219232    if models and models[0] == 'opencl': 
    220233        if not HAVE_OPENCL: 
     
    235248        print("""\ 
    236249usage: 
    237   python -m sasmodels.model_test [opencl|dll|opencl_and_dll] model1 model2 ... 
     250  python -m sasmodels.model_test [-v] [opencl|dll] model1 model2 ... 
     251 
     252If -v is included on the 
     253If neither opencl nor dll is specified, then models will be tested with 
     254both opencl and dll; the compute target is ignored for pure python models. 
    238255 
    239256If model1 is 'all', then all except the remaining models will be tested. 
    240 If no compute target is specified, then models will be tested with both opencl 
    241 and dll; the compute target is ignored for pure python models.""") 
     257 
     258""") 
    242259 
    243260        return 1 
    244261 
    245262    #runner = unittest.TextTestRunner() 
    246     runner = xmlrunner.XMLTestRunner(output='logs') 
     263    runner = xmlrunner.XMLTestRunner(output='logs', verbosity=verbosity) 
    247264    result = runner.run(make_suite(loaders, models)) 
    248265    return 1 if result.failures or result.errors else 0 
Note: See TracChangeset for help on using the changeset viewer.