Esempio n. 1
0
    def test_ufunc_out(self):
        from _numpypy import array, negative, zeros, sin
        from math import sin as msin
        a = array([[1, 2], [3, 4]])
        c = zeros((2, 2, 2))
        b = negative(a + a, out=c[1])
        #test for view, and also test that forcing out also forces b
        assert (c[:, :, 1] == [[0, 0], [-4, -8]]).all()
        assert (b == [[-2, -4], [-6, -8]]).all()
        #Test broadcast, type promotion
        b = negative(3, out=a)
        assert (a == -3).all()
        c = zeros((2, 2), dtype=float)
        b = negative(3, out=c)
        assert b.dtype.kind == c.dtype.kind
        assert b.shape == c.shape
        a = array([1, 2])
        b = sin(a, out=c)
        assert (c == [[msin(1), msin(2)]] * 2).all()
        b = sin(a, out=c + c)
        assert (c == b).all()

        #Test shape agreement
        a = zeros((3, 4))
        b = zeros((3, 5))
        raises(ValueError, 'negative(a, out=b)')
        b = zeros((1, 4))
        raises(ValueError, 'negative(a, out=b)')
Esempio n. 2
0
    def test_ufunc_out(self):
        from _numpypy import array, negative, zeros, sin
        from math import sin as msin
        a = array([[1, 2], [3, 4]])
        c = zeros((2,2,2))
        b = negative(a + a, out=c[1])
        #test for view, and also test that forcing out also forces b
        assert (c[:, :, 1] == [[0, 0], [-4, -8]]).all()
        assert (b == [[-2, -4], [-6, -8]]).all()
        #Test broadcast, type promotion
        b = negative(3, out=a)
        assert (a == -3).all()
        c = zeros((2, 2), dtype=float)
        b = negative(3, out=c)
        assert b.dtype.kind == c.dtype.kind
        assert b.shape == c.shape
        a = array([1, 2])
        b = sin(a, out=c)
        assert(c == [[msin(1), msin(2)]] * 2).all()
        b = sin(a, out=c+c)
        assert (c == b).all()

        #Test shape agreement
        a = zeros((3,4))
        b = zeros((3,5))
        raises(ValueError, 'negative(a, out=b)')
        b = zeros((1,4))
        raises(ValueError, 'negative(a, out=b)')
Esempio n. 3
0
    def test_sin(self):
        import math
        from _numpypy import array, sin

        a = array([0, 1, 2, 3, math.pi, math.pi*1.5, math.pi*2])
        b = sin(a)
        for i in range(len(a)):
            assert b[i] == math.sin(a[i])

        a = sin(array([True, False], dtype=bool))
        assert abs(a[0] - sin(1)) < 1e-7  # a[0] will be less precise
        assert a[1] == 0.0
Esempio n. 4
0
    def test_sin(self):
        import math
        from _numpypy import array, sin

        a = array([0, 1, 2, 3, math.pi, math.pi * 1.5, math.pi * 2])
        b = sin(a)
        for i in range(len(a)):
            assert b[i] == math.sin(a[i])

        a = sin(array([True, False], dtype=bool))
        assert abs(a[0] - sin(1)) < 1e-7  # a[0] will be less precise
        assert a[1] == 0.0
Esempio n. 5
0
    def test_debug_repr(self):
        from _numpypy import zeros, sin
        from _numpypy.pypy import debug_repr
        a = zeros(1)
        assert debug_repr(a) == 'Array'
        assert debug_repr(a + a) == 'Call2(add, Array, Array)'
        assert debug_repr(a[::2]) == 'Slice'
        assert debug_repr(a + 2) == 'Call2(add, Array, Scalar)'
        assert debug_repr(a + a.flat) == 'Call2(add, Array, Slice)'
        assert debug_repr(sin(a)) == 'Call1(sin, Array)'

        b = a + a
        b[0] = 3
        assert debug_repr(b) == 'Array'
Esempio n. 6
0
    def test_debug_repr(self):
        from _numpypy import zeros, sin
        from _numpypy.pypy import debug_repr
        a = zeros(1)
        assert debug_repr(a) == 'Array'
        assert debug_repr(a + a) == 'Call2(add, Array, Array)'
        assert debug_repr(a[::2]) == 'Slice'
        assert debug_repr(a + 2) == 'Call2(add, Array, Scalar)'
        assert debug_repr(a + a.flat) == 'Call2(add, Array, Slice)'
        assert debug_repr(sin(a)) == 'Call1(sin, Array)'

        b = a + a
        b[0] = 3
        assert debug_repr(b) == 'Array'