Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
def test_frombuffer_from_device_buffer(device):
    dtype = 'int32'

    device_buffer = chainerx.testing._DeviceBuffer(
        [1, 2, 3, 4, 5, 6], (2, 3), dtype)
    a = chainerx.frombuffer(device_buffer, dtype)
    e = chainerx.array([1, 2, 3, 4, 5, 6], dtype)

    chainerx.testing.assert_array_equal_ex(e, a)
    assert a.device is chainerx.get_device(device)
Exemple #4
0
def test_frombuffer_from_device_buffer(device):
    dtype = 'int32'

    device_buffer = chainerx.testing._DeviceBuffer(
        [1, 2, 3, 4, 5, 6], (2, 3), dtype)
    a = chainerx.frombuffer(device_buffer, dtype)
    e = chainerx.array([1, 2, 3, 4, 5, 6], dtype)

    chainerx.testing.assert_array_equal_ex(e, a)
    assert a.device is chainerx.get_device(device)
Exemple #5
0
def test_frombuffer_from_numpy_array(device):
    obj = array_utils.create_dummy_ndarray(
        numpy, (2, 3), 'int32', padding=False)

    a_chx = chainerx.frombuffer(obj, obj.dtype)
    a_np = numpy.frombuffer(obj, obj.dtype)

    chainerx.testing.assert_array_equal_ex(a_np, a_chx)
    assert a_chx.device is chainerx.get_device(device)

    # test buffer is shared
    obj += obj
    chainerx.testing.assert_array_equal_ex(obj.ravel(), a_chx)

    # test possibly freed memory
    obj_copy = obj.copy()
    del obj
    chainerx.testing.assert_array_equal_ex(obj_copy.ravel(), a_chx)
Exemple #6
0
def test_frombuffer_from_numpy_array(device):
    obj = array_utils.create_dummy_ndarray(
        numpy, (2, 3), 'int32', padding=False)

    a_chx = chainerx.frombuffer(obj, obj.dtype)
    a_np = numpy.frombuffer(obj, obj.dtype)

    chainerx.testing.assert_array_equal_ex(a_np, a_chx)
    assert a_chx.device is chainerx.get_device(device)

    # test buffer is shared
    obj += obj
    chainerx.testing.assert_array_equal_ex(obj.ravel(), a_chx)

    # test possibly freed memory
    obj_copy = obj.copy()
    del obj
    chainerx.testing.assert_array_equal_ex(obj_copy.ravel(), a_chx)
Exemple #7
0
def test_frombuffer_from_numpy_array_with_cuda(device):
    obj = array_utils.create_dummy_ndarray(numpy, (2, 3), 'int32')
    with pytest.raises(chainerx.ChainerxError):
        chainerx.frombuffer(obj, obj.dtype)
Exemple #8
0
def test_frombuffer_from_numpy_array_with_cuda(device):
    obj = array_utils.create_dummy_ndarray(numpy, (2, 3), 'int32')
    with pytest.raises(chainerx.ChainerxError):
        chainerx.frombuffer(obj, obj.dtype)