def test_asanyarray_from_numpy_subclass_array(): class Subclass(numpy.ndarray): pass obj = array_utils.create_dummy_ndarray( numpy, (2, 3), 'int32').view(Subclass) a = chainerx.asanyarray(obj, dtype='float32') e = chainerx.array(obj, dtype='float32', copy=False) chainerx.testing.assert_array_equal_ex(e, a) assert e.device is a.device
def test_asanyarray_from_chainerx_array(dtype): obj = array_utils.create_dummy_ndarray(chainerx, (2, 3), 'int32') a = chainerx.asanyarray(obj, dtype=dtype) if a.dtype == obj.dtype: assert a is obj else: assert a is not obj e = chainerx.array(obj, dtype=dtype, copy=False) chainerx.testing.assert_array_equal_ex(e, a) assert e.device is 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_asanyarray_from_python_tuple_or_list(): obj = _array_params_list a = chainerx.asanyarray(obj, dtype='float32') e = chainerx.array(obj, dtype='float32', copy=False) chainerx.testing.assert_array_equal_ex(e, a) assert e.device is a.device