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'"
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'"
def test_applevel(self): from _numpypy import array, sum, max, min a = array([[1, 2], [3, 4]]) out = array([[0, 0], [0, 0]]) c = sum(a, axis=0, out=out[0]) assert (c == [4, 6]).all() assert (c == out[0]).all() assert (c != out[1]).all() c = max(a, axis=1, out=out[0]) assert (c == [2, 4]).all() assert (c == out[0]).all() assert (c != out[1]).all()
def test_sum(self): from _numpypy import array, sum assert sum(range(10)) == 45 assert sum(array(range(10))) == 45