Ejemplo n.º 1
0
 def test_ufunc_cast(self):
     from _numpypy import array, negative, add, sum
     a = array(16, dtype=int)
     c = array(0, dtype=float)
     b = negative(a, out=c)
     assert b == c
     b = add(a, a, out=c)
     assert b == c
     d = array([16, 16], dtype=int)
     b = sum(d, out=c)
     assert b == c
     try:
         from _numpypy import version
         v = version.version.split('.')
     except:
         v = ['1', '6', '0']  # numpypy is api compatable to what version?
     if v[0] < '2':
         b = negative(c, out=a)
         assert b == a
         b = add(c, c, out=a)
         assert b == a
         b = sum(array([16, 16], dtype=float), out=a)
         assert b == a
     else:
         cast_error = raises(TypeError, negative, c, a)
         assert str(cast_error.value) == \
         "Cannot cast ufunc negative output from dtype('float64') to dtype('int64') with casting rule 'same_kind'"
Ejemplo n.º 2
0
 def test_ufunc_cast(self):
     from _numpypy import array, negative, add, sum
     a = array(16, dtype = int)
     c = array(0, dtype = float)
     b = negative(a, out=c)
     assert b == c
     b = add(a, a, out=c)
     assert b == c
     d = array([16, 16], dtype=int)
     b = sum(d, out=c)
     assert b == c
     try:
         from _numpypy import version
         v = version.version.split('.')
     except:
         v = ['1', '6', '0'] # numpypy is api compatable to what version?
     if v[0]<'2':
         b = negative(c, out=a)
         assert b == a
         b = add(c, c, out=a)
         assert b == a
         b = sum(array([16, 16], dtype=float), out=a)
         assert b == a
     else:
         cast_error = raises(TypeError, negative, c, a)
         assert str(cast_error.value) == \
         "Cannot cast ufunc negative output from dtype('float64') to dtype('int64') with casting rule 'same_kind'"
Ejemplo n.º 3
0
    def test_add(self):
        from _numpypy import array, add

        a = array([-5.0, -0.0, 1.0])
        b = array([ 3.0, -2.0,-3.0])
        c = add(a, b)
        for i in range(3):
            assert c[i] == a[i] + b[i]
Ejemplo n.º 4
0
    def test_add(self):
        from _numpypy import array, add

        a = array([-5.0, -0.0, 1.0])
        b = array([3.0, -2.0, -3.0])
        c = add(a, b)
        for i in range(3):
            assert c[i] == a[i] + b[i]
Ejemplo n.º 5
0
 def test_binfunc_out(self):
     from _numpypy import array, add
     a = array([[1, 2], [3, 4]])
     out = array([[1, 2], [3, 4]])
     c = add(a, a, out=out)
     assert (c == out).all()
     assert c.shape == a.shape
     assert c.dtype is a.dtype
     c[0, 0] = 100
     assert out[0, 0] == 100
     out[:] = 100
     raises(ValueError, 'c = add(a, a, out=out[1])')
     c = add(a[0], a[1], out=out[1])
     assert (c == out[1]).all()
     assert (c == [4, 6]).all()
     assert (out[0] == 100).all()
     c = add(a[0], a[1], out=out)
     assert (c == out[1]).all()
     assert (c == out[0]).all()
     out = array(16, dtype=int)
     b = add(10, 10, out=out)
     assert b == out
     assert b.dtype == out.dtype
Ejemplo n.º 6
0
 def test_binfunc_out(self):
     from _numpypy import array, add
     a = array([[1, 2], [3, 4]])
     out = array([[1, 2], [3, 4]])
     c = add(a, a, out=out)
     assert (c == out).all()
     assert c.shape == a.shape
     assert c.dtype is a.dtype
     c[0,0] = 100
     assert out[0, 0] == 100
     out[:] = 100
     raises(ValueError, 'c = add(a, a, out=out[1])')
     c = add(a[0], a[1], out=out[1])
     assert (c == out[1]).all()
     assert (c == [4, 6]).all()
     assert (out[0] == 100).all()
     c = add(a[0], a[1], out=out)
     assert (c == out[1]).all()
     assert (c == out[0]).all()
     out = array(16, dtype=int)
     b = add(10, 10, out=out)
     assert b==out
     assert b.dtype == out.dtype