def test_reduce(self): from numpypy import add, maximum assert add.reduce([1, 2, 3]) == 6 assert maximum.reduce([1]) == 1 assert maximum.reduce([1, 2, 3]) == 3 raises(ValueError, maximum.reduce, [])
def test_reduce_1d(self): from numpypy import add, maximum, less assert less.reduce([5, 4, 3, 2, 1]) assert add.reduce([1, 2, 3]) == 6 assert maximum.reduce([1]) == 1 assert maximum.reduce([1, 2, 3]) == 3 raises(ValueError, maximum.reduce, [])
def test_reduce_1d(self): from numpypy import array, add, maximum, less, float16, complex64 assert less.reduce([5, 4, 3, 2, 1]) assert add.reduce([1, 2, 3]) == 6 assert maximum.reduce([1]) == 1 assert maximum.reduce([1, 2, 3]) == 3 raises(ValueError, maximum.reduce, []) assert add.reduce(array([True, False] * 200)) == 200 assert add.reduce(array([True, False] * 200, dtype='int8')) == 200 assert add.reduce(array([True, False] * 200), dtype='int8') == -56 assert type(add.reduce(array([True, False] * 200, dtype='float16'))) is float16 assert type(add.reduce(array([True, False] * 200, dtype='complex64'))) is complex64
def test_reduce_errors(self): from numpypy import sin, add, maximum, zeros raises(ValueError, sin.reduce, [1, 2, 3]) assert add.reduce(1) == 1 assert list(maximum.reduce(zeros((2, 0)), axis=0)) == [] exc = raises(ValueError, maximum.reduce, zeros((2, 0)), axis=None) assert exc.value[0] == ('zero-size array to reduction operation ' 'maximum which has no identity') exc = raises(ValueError, maximum.reduce, zeros((2, 0)), axis=1) assert exc.value[0] == ('zero-size array to reduction operation ' 'maximum which has no identity') a = zeros((2, 2)) + 1 assert (add.reduce(a, axis=1) == [2, 2]).all() assert (add.reduce(a, axis=(1,)) == [2, 2]).all() exc = raises(ValueError, add.reduce, a, axis=2) assert exc.value[0] == "'axis' entry is out of bounds"