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

Class test_evaluate

numexpr3/tests/test_numexpr.py:306–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304 self.ssize = ssize
305
306class test_evaluate(unittest.TestCase):
307
308 def setUp(self, N_threads=1, ssize=SMALL_SIZE):
309 logger.info( "**Run evaluate() tests with {} thread(s) over {} element arrays**".format(N_threads, ssize) )
310 ne3.set_nthreads(N_threads)
311 self.ssize = ssize
312
313 def test_eval_versus_run(self):
314 logger.info( 'Compare evaluate and .run' )
315 a = np.arange(100.0).reshape(10, 10)[::2]
316 b = np.arange(10.0)
317 expr = ne3.NumExpr('2*a+3*b')
318 npt.assert_array_almost_equal(expr(a=a, b=b), expr.run(a=a, b=b))
319
320 def test_prealloc(self):
321 logger.info( 'Test pre-allocated output evaluate' )
322 a = np.array([1., 2., 3.])
323 b = np.array([4., 5., 6.])
324 c = np.array([7., 8., 9.])
325 y = 2*a + 3*b*c
326 x = np.empty_like(y)
327 ne3.evaluate('x=2*a + 3*b*c')
328 npt.assert_array_equal(x, y)
329
330 def test_magic(self):
331 logger.info( 'Test magic output evaluate' )
332 a = np.array([1., 2., 3.])
333 b = np.array([4., 5., 6.])
334 c = np.array([7., 8., 9.])
335 y = 2*a + 3*b*c
336 ne3.evaluate('x_magic=2*a + 3*b*c')
337 # For some reason, only in unittest, does y_magic not appear in the
338 # scope unless explicitely looked for in locals. This works in normal
339 # scripts however.
340 npt.assert_array_equal( locals()['x_magic'], y)
341
342 def test_copy(self):
343 logger.info( 'Test copy evaluate with preallocated output' )
344 x = np.arange(SMALL_SIZE)
345 y = np.zeros_like(x)
346 ne3.evaluate('y=x')
347 npt.assert_array_equal(x, y)
348
349 def test_copy_magic(self):
350 logger.info( 'Test copy evaluate with magic output' )
351 x = np.arange(self.ssize)
352 ne3.evaluate('y_magic=x')
353 npt.assert_array_equal(x, locals()['y_magic'] )
354
355 def test_rational(self):
356 logger.info( 'Test rational evaluation' )
357 a = np.arange(1e5)
358 b = np.arange(1e5) * 0.1
359 x = (a + 2 * b) / (1 + a + 4 * b * b)
360 ne3.evaluate('y=(a + 2*b) / (1 + a + 4*b*b)')
361 npt.assert_array_almost_equal(x, locals()['y'] )
362
363class test_reductions(unittest.TestCase):

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…