From 4ef9ac443c56cad98cb35b04a0d7c3ba03e08003 Mon Sep 17 00:00:00 2001 From: Akifumi Imanishi Date: Wed, 4 Mar 2020 11:39:47 +0000 Subject: [PATCH] Add device assertion check --- tests/test_tensor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_tensor.py b/tests/test_tensor.py index fb33757..3a6c4be 100644 --- a/tests/test_tensor.py +++ b/tests/test_tensor.py @@ -59,22 +59,26 @@ def test_astensor_negative_stride(): def test_asarray_empty_cpu(): t = torch.tensor([], dtype=torch.float32) a = tensor.asarray(t) + assert isinstance(a, numpy.ndarray) def test_asarray_empty_gpu(): t = torch.tensor([], dtype=torch.float32, device='cuda') a = tensor.asarray(t) + assert isinstance(a, cupy.ndarray) def test_astensor_empty_cpu(): a = numpy.array([], dtype=numpy.float32) t = tensor.astensor(a) + assert t.device.type == 'cpu' def test_astensor_empty_gpu(): a = cupy.array([], dtype=cupy.float32) t = tensor.astensor(a) assert isinstance(t, torch.Tensor) + assert t.device.type == 'cuda' t += 1 numpy.testing.assert_array_equal(a.get(), t.cpu().numpy())