def test_cumsum(backend): check_import(backend) # Given a = array.ones(100, dtype=int, backend=backend) # When b = array.cumsum(a) # Then a.pull() b.pull() assert np.all(b.data == np.cumsum(a.data))
def test_diff(backend, dtype): check_import(backend) if dtype == np.float64: get_config().use_double = True dev_array = array.ones(1, dtype=dtype, backend=backend) with pytest.raises(ValueError): y = array.diff(dev_array, 1) y = array.diff(dev_array, 0) assert(y[0] == dev_array[0]) dev_array = array.ones(2, dtype=dtype, backend=backend) with pytest.raises(ValueError): y = array.diff(dev_array, -1) y = array.diff(dev_array, 1) assert(len(y) == 1) assert(y[0] == 0) dev_array = np.linspace(0, 10, 11, dtype=dtype)**2 yt = np.diff(dev_array, 2) dev_array = wrap_array(dev_array, backend=backend) y = array.diff(dev_array, 2) for i in range(8): assert(y[i] == yt[i])
def test_binary_op(backend): check_import(backend) # Given x = array.ones(10, dtype=np.float32, backend=backend) y = array.ones_like(x) x_np = np.ones(10, dtype=np.float32) # When out_add = x + y out_sub = x - y # Then assert np.all(out_add.get() == x_np + x_np) assert np.all(out_sub.get() == np.zeros_like(x_np))
def test_cumsum(backend): check_import(backend) # Given a = array.ones(100, dtype=int, backend=backend) # When b = array.cumsum(a) # Then a.pull() b.pull() assert np.all(b.data == np.cumsum(a.data)) # Test cumsum with an out argument # Given out = array.zeros(100, dtype=int, backend=backend) # When b = array.cumsum(a, out=out) # Then out.pull() assert np.all(out.data == np.cumsum(a.data))