Ejemplo n.º 1
0
    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, [])
Ejemplo n.º 2
0
    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, [])
Ejemplo n.º 3
0
    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"
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
 def test_reduce_keepdims(self):
     from numpypy import add, arange
     a = arange(12).reshape(3, 4)
     b = add.reduce(a, 0, keepdims=True)
     assert b.shape == (1, 4)
     assert (add.reduce(a, 0, keepdims=True) == [12, 15, 18, 21]).all()
Ejemplo n.º 6
0
 def test_reduceND(self):
     from numpypy import add, arange
     a = arange(12).reshape(3, 4)
     assert (add.reduce(a, 0) == [12, 15, 18, 21]).all()
     assert (add.reduce(a, 1) == [6.0, 22.0, 38.0]).all()
     raises(ValueError, add.reduce, a, 2)
Ejemplo n.º 7
0
    def test_reduce_errors(self):
        from numpypy import sin, add

        raises(ValueError, sin.reduce, [1, 2, 3])
        assert add.reduce(1) == 1