def test_check_device_fail(shape, device, compare_device_spec): dtype = 'float32' a = chainerx.empty(shape, dtype, device=device) with chainerx.using_device('native:1'): with pytest.raises(AssertionError): array_utils.check_device(a, compare_device_spec)
def test_empty_like_with_device(device): t = chainerx.empty((2,), 'float32') a = chainerx.empty_like(t, device) b = chainerx.empty_like(t) array_utils.check_device(a, device) assert a.dtype == b.dtype assert a.shape == b.shape
def test_check_device_device_spec(shape, device_spec): dtype = 'float32' a = chainerx.empty(shape, dtype, device=device_spec) device = chainerx.get_device(device_spec) array_utils.check_device(a, device_spec) array_utils.check_device(a, device)
def test_check_device_device_spec(shape, device_spec): dtype = 'float32' a = chainerx.empty(shape, dtype, device=device_spec) device = chainerx.get_device(device_spec) array_utils.check_device(a, device_spec) array_utils.check_device(a, device)
def test_frombuffer_with_device(device): obj = array_utils.create_dummy_ndarray( numpy, (2, 3), 'int32', padding=False) a = chainerx.frombuffer(obj, obj.dtype, device=device) b = chainerx.frombuffer(obj, obj.dtype) chainerx.testing.assert_array_equal_ex(a, b) array_utils.check_device(a, device)
def test_check_device_fail(shape, device, compare_device_spec): dtype = 'float32' a = chainerx.empty(shape, dtype, device=device) with chainerx.using_device('native:1'): with pytest.raises(AssertionError): array_utils.check_device(a, compare_device_spec)
def test_frombuffer_with_device(device): obj = array_utils.create_dummy_ndarray( numpy, (2, 3), 'int32', padding=False) a = chainerx.frombuffer(obj, obj.dtype, device=device) b = chainerx.frombuffer(obj, obj.dtype) chainerx.testing.assert_array_equal_ex(a, b) array_utils.check_device(a, device)
def test_empty_like_with_device(device): t = chainerx.empty((2,), 'float32') a = chainerx.empty_like(t, device) b = chainerx.empty_like(t) array_utils.check_device(a, device) assert a.dtype == b.dtype assert a.shape == b.shape
def _check_array_from_numpy_array(a_chx, a_np, device=None): assert a_chx.offset == 0 array_utils.check_device(a_chx, device) # recovered data should be equal a_np_recovered = chainerx.to_numpy(a_chx) chainerx.testing.assert_array_equal_ex( a_chx, a_np_recovered, strides_check=False)
def test_ascontiguousarray_with_device(device, shape, padding, dtype): obj = array_utils.create_dummy_ndarray( chainerx, shape, dtype, padding=padding) a = chainerx.ascontiguousarray(obj, device=device) b = chainerx.ascontiguousarray(obj) array_utils.check_device(a, device) assert a.is_contiguous chainerx.testing.assert_array_equal_ex(a, b)
def _check_array_from_numpy_array(a_chx, a_np, device=None): assert a_chx.offset == 0 array_utils.check_device(a_chx, device) # recovered data should be equal a_np_recovered = chainerx.to_numpy(a_chx) chainerx.testing.assert_array_equal_ex( a_chx, a_np_recovered, strides_check=False)
def test_ascontiguousarray_with_device(device, shape, padding, dtype): obj = array_utils.create_dummy_ndarray( chainerx, shape, dtype, padding=padding) a = chainerx.ascontiguousarray(obj, device=device) b = chainerx.ascontiguousarray(obj) array_utils.check_device(a, device) assert a.is_contiguous chainerx.testing.assert_array_equal_ex(a, b)
def _check_array( array, expected_dtype, expected_shape, expected_data_list=None, device=None): expected_dtype = chainerx.dtype(expected_dtype) assert isinstance(array.dtype, chainerx.dtype) assert isinstance(array.shape, tuple) assert array.dtype == expected_dtype assert array.shape == expected_shape assert array.itemsize == expected_dtype.itemsize assert array.size == array_utils.total_size(expected_shape) assert array.nbytes == expected_dtype.itemsize * \ array_utils.total_size(expected_shape) if expected_data_list is not None: assert array._debug_flat_data == expected_data_list assert array.is_contiguous array_utils.check_device(array, device)
def _check_array( array, expected_dtype, expected_shape, expected_data_list=None, device=None): expected_dtype = chainerx.dtype(expected_dtype) assert isinstance(array.dtype, chainerx.dtype) assert isinstance(array.shape, tuple) assert array.dtype == expected_dtype assert array.shape == expected_shape assert array.itemsize == expected_dtype.itemsize assert array.size == array_utils.total_size(expected_shape) assert array.nbytes == expected_dtype.itemsize * \ array_utils.total_size(expected_shape) if expected_data_list is not None: assert array._debug_flat_data == expected_data_list assert array.is_contiguous array_utils.check_device(array, device)
def test_linspace_with_device(device): a = chainerx.linspace(3, 5, 10, dtype='float32', device=device) b = chainerx.linspace(3, 5, 10, dtype='float32') array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_eye_with_device(device): a = chainerx.eye(1, 2, 1, 'float32', device) b = chainerx.eye(1, 2, 1, 'float32') array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_asanyarray_with_device(device): a = chainerx.asanyarray([0, 1], 'float32', device) b = chainerx.asanyarray([0, 1], 'float32') chainerx.testing.assert_array_equal_ex(a, b) array_utils.check_device(a, device)
def check(*args, **kwargs): a = chainerx.arange(*args, device=device, **kwargs) b = chainerx.arange(*args, **kwargs) array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_full_with_device(device): a = chainerx.full((2,), 1, 'float32', device) b = chainerx.full((2,), 1, 'float32') array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_zeros_with_device(device): a = chainerx.zeros((2,), 'float32', device) b = chainerx.zeros((2,), 'float32') chainerx.testing.assert_array_equal_ex(a, b) array_utils.check_device(a, device)
def test_zeros_with_device(device): a = chainerx.zeros((2,), 'float32', device) b = chainerx.zeros((2,), 'float32') chainerx.testing.assert_array_equal_ex(a, b) array_utils.check_device(a, device)
def test_check_device(shape, device): dtype = 'float32' a = chainerx.empty(shape, dtype, device=device) array_utils.check_device(a, device.name) array_utils.check_device(a, device)
def test_asanyarray_with_device(device): a = chainerx.asanyarray([0, 1], 'float32', device) b = chainerx.asanyarray([0, 1], 'float32') chainerx.testing.assert_array_equal_ex(a, b) array_utils.check_device(a, device)
def test_array_from_numpy_array_with_device(shape, device): orig = array_utils.create_dummy_ndarray(numpy, (2, ), 'float32') a = chainerx.array(orig, device=device) b = chainerx.array(orig) chainerx.testing.assert_array_equal_ex(a, b) array_utils.check_device(a, device)
def test_identity_with_device(device): a = chainerx.identity(3, 'float32', device) b = chainerx.identity(3, 'float32') array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_eye_with_device(device): a = chainerx.eye(1, 2, 1, 'float32', device) b = chainerx.eye(1, 2, 1, 'float32') array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_ones_like_with_device(shape, device): t = chainerx.empty((2,), 'float32') a = chainerx.ones_like(t, device) b = chainerx.ones_like(t) array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_array_from_numpy_array_with_device(shape, device): orig = array_utils.create_dummy_ndarray(numpy, (2, ), 'float32') a = chainerx.array(orig, device=device) b = chainerx.array(orig) chainerx.testing.assert_array_equal_ex(a, b) array_utils.check_device(a, device)
def test_ones_like_with_device(shape, device): t = chainerx.empty((2,), 'float32') a = chainerx.ones_like(t, device) b = chainerx.ones_like(t) array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_full_with_device(device): a = chainerx.full((2,), 1, 'float32', device) b = chainerx.full((2,), 1, 'float32') array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_full_like_with_device(device): t = chainerx.empty((2,), 'float32') a = chainerx.full_like(t, 1, device) b = chainerx.full_like(t, 1) array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_full_like_with_device(device): t = chainerx.empty((2,), 'float32') a = chainerx.full_like(t, 1, device) b = chainerx.full_like(t, 1) array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_array_from_python_tuple_or_list_with_device(obj, device): a = chainerx.array(obj, 'float32', device=device) b = chainerx.array(obj, 'float32') chainerx.testing.assert_array_equal_ex(a, b) array_utils.check_device(a, device)
def check(*args, **kwargs): a = chainerx.arange(*args, device=device, **kwargs) b = chainerx.arange(*args, **kwargs) array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_identity_with_device(device): a = chainerx.identity(3, 'float32', device) b = chainerx.identity(3, 'float32') array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_array_from_python_tuple_or_list_with_device(obj, device): a = chainerx.array(obj, 'float32', device=device) b = chainerx.array(obj, 'float32') chainerx.testing.assert_array_equal_ex(a, b) array_utils.check_device(a, device)
def test_linspace_with_device(device): a = chainerx.linspace(3, 5, 10, dtype='float32', device=device) b = chainerx.linspace(3, 5, 10, dtype='float32') array_utils.check_device(a, device) chainerx.testing.assert_array_equal_ex(a, b)
def test_check_device(shape, device): dtype = 'float32' a = chainerx.empty(shape, dtype, device=device) array_utils.check_device(a, device.name) array_utils.check_device(a, device)