Changeset 3709366 in sasmodels
 Timestamp:
 Mar 28, 2019 1:53:36 PM (7 weeks ago)
 Branches:
 master, ticket1257vesicleproduct, ticket_1156, ticket_822_more_unit_tests
 Children:
 e5cb3df
 Parents:
 6140894
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

sasmodels/model_test.py
r6140894 r3709366 344 344 345 345 def _check_scalar(self, target, actual, name): 346 if target is None: 347 # smoke test  make sure it runs and produces a value 348 self.assertTrue(not np.isnan(actual), 349 'invalid %s: %s' % (name, actual)) 350 elif np.isnan(target): 351 # make sure nans match 352 self.assertTrue(np.isnan(actual), 353 '%s: expected:%s; actual:%s' 354 % (name, target, actual)) 355 else: 356 # is_near does not work for infinite values, so also test 357 # for exact values. 358 self.assertTrue(target == actual or is_near(target, actual, 5), 359 '%s: expected:%s; actual:%s' 360 % (name, target, actual)) 346 self.assertTrue(is_near(target, actual, 5), 347 '%s: expected:%s; actual:%s' 348 % (name, target, actual)) 361 349 362 350 def _check_vectors(self, x, target, actual, name='I'): … … 368 356 '%s(...) returned wrong length'%name) 369 357 for xi, yi, actual_yi in zip(x, target, actual): 370 if yi is None: 371 # smoke test  make sure it runs and produces a value 372 self.assertTrue(not np.isnan(actual_yi), 373 'invalid %s(%s): %s' % (name, xi, actual_yi)) 374 elif np.isnan(yi): 375 # make sure nans match 376 self.assertTrue(np.isnan(actual_yi), 377 '%s(%s): expected:%s; actual:%s' 378 % (name, xi, yi, actual_yi)) 379 else: 380 # is_near does not work for infinite values, so also test 381 # for exact values. 382 self.assertTrue(yi == actual_yi or is_near(yi, actual_yi, 5), 383 '%s(%s); expected:%s; actual:%s' 384 % (name, xi, yi, actual_yi)) 358 self.assertTrue(is_near(yi, actual_yi, 5), 359 '%s(%s): expected:%s; actual:%s' 360 % (name, xi, target, actual)) 385 361 386 362 return ModelTestCase … … 413 389 """ 414 390 Returns true if *actual* is within *digits* significant digits of *target*. 415 """ 416 import math 417 if target == 0.: 391 392 *taget* zero and inf should match *actual* zero and inf. If you want to 393 accept eps for zero, choose a value such as 1e10, which must match up to 394 +/ 1e15 when *digits* is the default value of 5. 395 396 If *target* is None, then just make sure that *actual* is not NaN. 397 398 If *target* is NaN, make sure *actual* is NaN. 399 """ 400 if target is None: 401 # target is None => actual cannot be NaN 402 return not np.isnan(actual) 403 elif target == 0.: 404 # target is 0. => actual must be 0. 405 # Note: if small values are allowed, then use maybe test zero against eps instead? 418 406 return actual == 0. 419 shift = 10**math.ceil(math.log10(np.abs(target))) 420 return np.abs(targetactual)/shift < 1.5*10**digits 407 elif np.isfinite(target): 408 shift = np.ceil(np.log10(abs(target))) 409 return abs(targetactual) < 1.5*10**(shiftdigits) 410 elif target == actual: 411 # target is inf => actual must be inf of same sign 412 return True 413 else: 414 # target is NaN => actual must be NaN 415 return np.isnan(target) == np.isnan(actual) 421 416 422 417 # CRUFT: old interface; should be deprecated and removed
Note: See TracChangeset
for help on using the changeset viewer.