예제 #1
0
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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)
예제 #6
0
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
예제 #7
0
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)
예제 #8
0
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