MCPcopy Create free account
hub / github.com/numpy/numpy / test_method_args

Method test_method_args

numpy/core/tests/test_regression.py:516–549  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

514 assert_(x['one'] > 1 and x['two'] > 2)
515
516 def test_method_args(self):
517 # Make sure methods and functions have same default axis
518 # keyword and arguments
519 funcs1 = ['argmax', 'argmin', 'sum', 'any', 'all', 'cumsum',
520 'ptp', 'cumprod', 'prod', 'std', 'var', 'mean',
521 'round', 'min', 'max', 'argsort', 'sort']
522 funcs2 = ['compress', 'take', 'repeat']
523
524 for func in funcs1:
525 arr = np.random.rand(8, 7)
526 arr2 = arr.copy()
527 res1 = getattr(arr, func)()
528 res2 = getattr(np, func)(arr2)
529 if res1 is None:
530 res1 = arr
531
532 if res1.dtype.kind in 'uib':
533 assert_((res1 == res2).all(), func)
534 else:
535 assert_(abs(res1-res2).max() < 1e-8, func)
536
537 for func in funcs2:
538 arr1 = np.random.rand(8, 7)
539 arr2 = np.random.rand(8, 7)
540 res1 = None
541 if func == 'compress':
542 arr1 = arr1.ravel()
543 res1 = getattr(arr2, func)(arr1)
544 else:
545 arr2 = (15*arr2).astype(int).ravel()
546 if res1 is None:
547 res1 = getattr(arr1, func)(arr2)
548 res2 = getattr(np, func)(arr1, arr2)
549 assert_(abs(res1-res2).max() < 1e-8, func)
550
551 def test_mem_lexsort_strings(self):
552 # Ticket #298

Callers

nothing calls this directly

Calls 7

assert_Function · 0.90
absFunction · 0.85
astypeMethod · 0.80
copyMethod · 0.45
allMethod · 0.45
maxMethod · 0.45
ravelMethod · 0.45

Tested by

no test coverage detected