MCPcopy Create free account
hub / github.com/pydata/numexpr / test_numexpr

Class test_numexpr

numexpr3/tests/test_numexpr.py:37–293  ·  view source on GitHub ↗

Testing with 1 thread for serial operation

Source from the content-addressed store, hash-verified

35LARGE_SIZE = 80000.0
36
37class test_numexpr(unittest.TestCase):
38 '''Testing with 1 thread for serial operation'''
39
40 def setUp(self, N_threads=1, ssize=SMALL_SIZE):
41 logger.info( "**Run NumExpr() tests with {} thread(s) over {} element arrays**".format(N_threads, ssize) )
42 ne3.set_nthreads(N_threads)
43 self.ssize = ssize
44
45 def test_scalars(self):
46 logger.info( 'Test scalars' )
47 a = np.array([1., 2, 3])
48 b = np.array([4., 5, 6])
49 c = np.array([7., 8, 9])
50 out = ne3.NumExpr( '2.0 * a + 3.0 * b * c' )()
51 npt.assert_array_almost_equal( out, np.array([86., 124., 168.]))
52
53 def test_changing_array_size(self):
54 logger.info('Test input with keywords, changing input array size')
55 a = np.array([1., 2., 3.])
56 b = np.array([4., 5., 6.])
57 a2 = np.arange(self.ssize).astype(a.dtype)
58 b2 = np.arange(3.0, self.ssize+3.0).astype(b.dtype)
59 out = ne3.NumExpr( 'a*b' )(a=a2, b=b2)
60 npt.assert_array_almost_equal( out, a2*b2 )
61
62 def test_changing_array_shape(self):
63 logger.info('Test changing input array shape')
64 a = np.array([1., 2., 3.])
65 b = np.array([4., 5., 6.])
66 a2 = np.arange(self.ssize).astype(a.dtype).reshape( int(self.ssize/20), 4, 5)
67 b2 = np.arange(3.0, self.ssize+3.0).astype(b.dtype).reshape( int(self.ssize/20), 4, 5)
68 out = ne3.NumExpr( 'a*b' )(a=a2, b=b2)
69 npt.assert_array_almost_equal( out, a2*b2 )
70
71 def test_verify_input(self):
72 logger.info('Test input with verify=True')
73 a = np.array([1., 2., 3.])
74 b = np.array([4., 5., 6.])
75 func = ne3.NumExpr( 'a*b' )
76 a = np.arange(self.ssize).astype(a.dtype)
77 b = np.arange(3.0, self.ssize+3.0).astype(b.dtype)
78 out = func(verify=True)
79 npt.assert_array_almost_equal( out, a*b )
80
81 def test_weakref_expiry(self):
82 # I have no idea how to turn on gc in unittest. I can't find anything
83 # in unittest that does that:
84 # https://github.com/python/cpython/tree/master/Lib/unittest
85 # This script works fine when run independantly.
86 '''
87 import gc
88 gc.enable()
89 logger.warning('Test expiry of weak reference')
90 x = np.arange(self.ssize)
91 func = ne3.NumExpr( 'x+x' )
92 logging.warning( 'x is tracked: ' + str(gc.is_tracked(x) ) )
93 del x # kill original array, should expire weak ref in func.registers
94 gc.collect(generation=2)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…