def test_meshgrid_dtype_errors(): # Doesn't raise meshgrid() meshgrid(asarray([1.], dtype=float32)) meshgrid(asarray([1.], dtype=float32), asarray([1.], dtype=float32)) assert_raises(ValueError, lambda: meshgrid(asarray([1.], dtype=float32), asarray([1.], dtype=float64)))
def test_empty_like_errors(): assert_raises(ValueError, lambda: empty_like(asarray(1), device="cpu")) # numpy's pick assert_raises(ValueError, lambda: empty_like(asarray(1), device="gpu")) assert_raises(ValueError, lambda: empty_like(asarray(1), dtype=int)) assert_raises(ValueError, lambda: empty_like(asarray(1), dtype="i")) empty_like(asarray(1), device=Device()) # on current device
def test_asarray_copy(): a = asarray([1]) b = asarray(a, copy=True) a[0] = 0 assert all(b[0] == 1) assert all(a[0] == 0) # Once copy=False is implemented, replace this with # a = asarray([1]) # b = asarray(a, copy=False) # a[0] = 0 # assert all(b[0] == 0) assert_raises(NotImplementedError, lambda: asarray(a, copy=False))
def test_asarray_errors(): # Test various protections against incorrect usage assert_raises(TypeError, lambda: Array([1])) # assert_raises(TypeError, lambda: asarray(["a"])) # TODO(leofang): fix this? assert_raises(ValueError, lambda: asarray([1.0], dtype=cp.float16)) assert_raises(OverflowError, lambda: asarray(2**100)) # Preferably this would be OverflowError # assert_raises(OverflowError, lambda: asarray([2**100])) # assert_raises(TypeError, lambda: asarray([2**100])) # TODO(leofang): fix this? assert_raises(ValueError, lambda: asarray([1], device="cpu")) # numpy's pick assert_raises(ValueError, lambda: asarray([1], device="gpu")) assert_raises(ValueError, lambda: asarray([1], dtype=int)) assert_raises(ValueError, lambda: asarray([1], dtype="i")) asarray([1], device=Device()) # on current device