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

Class test_reductions

numexpr3/tests/test_numexpr.py:363–444  ·  view source on GitHub ↗

def test_reductions_DEPRECATED(self): # Check that they compile OK. assert_equal(disassemble( NumExpr('sum(x**2+2, axis=None)', [('x', double)])), [(b'mul_ddd', b't3', b'r1[x]', b'r1[x]'), (b'add_ddd', b't3', b't3', b'c2[2.0

Source from the content-addressed store, hash-verified

361 npt.assert_array_almost_equal(x, locals()['y'] )
362
363class test_reductions(unittest.TestCase):
364 # NE3 reductions not implemented yet
365 '''
366 def test_reductions_DEPRECATED(self):
367 # Check that they compile OK.
368 assert_equal(disassemble(
369 NumExpr('sum(x**2+2, axis=None)', [('x', double)])),
370 [(b'mul_ddd', b't3', b'r1[x]', b'r1[x]'),
371 (b'add_ddd', b't3', b't3', b'c2[2.0]'),
372 (b'sum_ddn', b'r0', b't3', None)])
373 assert_equal(disassemble(
374 NumExpr('sum(x**2+2, axis=1)', [('x', double)])),
375 [(b'mul_ddd', b't3', b'r1[x]', b'r1[x]'),
376 (b'add_ddd', b't3', b't3', b'c2[2.0]'),
377 (b'sum_ddn', b'r0', b't3', 1)])
378 assert_equal(disassemble(
379 NumExpr('prod(x**2+2, axis=2)', [('x', double)])),
380 [(b'mul_ddd', b't3', b'r1[x]', b'r1[x]'),
381 (b'add_ddd', b't3', b't3', b'c2[2.0]'),
382 (b'prod_ddn', b'r0', b't3', 2)])
383 # Check that full reductions work.
384 x = zeros(1e5) + .01 # checks issue #41
385 assert_allclose(evaluate('sum(x+2,axis=None)'), sum(x + 2, axis=None))
386 assert_allclose(evaluate('sum(x+2,axis=0)'), sum(x + 2, axis=0))
387 assert_allclose(evaluate('prod(x,axis=0)'), prod(x, axis=0))
388
389 x = arange(10.0)
390 assert_allclose(evaluate('sum(x**2+2,axis=0)'), sum(x ** 2 + 2, axis=0))
391 assert_allclose(evaluate('prod(x**2+2,axis=0)'), prod(x ** 2 + 2, axis=0))
392
393 x = arange(100.0)
394 assert_allclose(evaluate('sum(x**2+2,axis=0)'), sum(x ** 2 + 2, axis=0))
395 assert_allclose(evaluate('prod(x-1,axis=0)'), prod(x - 1, axis=0))
396 x = linspace(0.1, 1.0, 2000)
397 assert_allclose(evaluate('sum(x**2+2,axis=0)'), sum(x ** 2 + 2, axis=0))
398 assert_allclose(evaluate('prod(x-1,axis=0)'), prod(x - 1, axis=0))
399
400 # Check that reductions along an axis work
401 y = arange(9.0).reshape(3, 3)
402 assert_allclose(evaluate('sum(y**2, axis=1)'), sum(y ** 2, axis=1))
403 assert_allclose(evaluate('sum(y**2, axis=0)'), sum(y ** 2, axis=0))
404 assert_allclose(evaluate('sum(y**2, axis=None)'), sum(y ** 2, axis=None))
405 assert_allclose(evaluate('prod(y**2, axis=1)'), prod(y ** 2, axis=1))
406 assert_allclose(evaluate('prod(y**2, axis=0)'), prod(y ** 2, axis=0))
407 assert_allclose(evaluate('prod(y**2, axis=None)'), prod(y ** 2, axis=None))
408 # Check integers
409 x = arange(10.)
410 x = x.astype(int)
411 assert_allclose(evaluate('sum(x**2+2,axis=0)'), sum(x ** 2 + 2, axis=0))
412 assert_allclose(evaluate('prod(x**2+2,axis=0)'), prod(x ** 2 + 2, axis=0))
413 # Check longs
414 x = x.astype(long)
415 assert_allclose(evaluate('sum(x**2+2,axis=0)'), sum(x ** 2 + 2, axis=0))
416 assert_allclose(evaluate('prod(x**2+2,axis=0)'), prod(x ** 2 + 2, axis=0))
417 # Check complex
418 x = x + .1j
419 assert_allclose(evaluate('sum(x**2+2,axis=0)'), sum(x ** 2 + 2, axis=0))
420 assert_allclose(evaluate('prod(x-1,axis=0)'), prod(x - 1, axis=0))

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…