def test_list_tuple(self): test_data = [[1, 2], [3, 4]] result = ToCupyd(keys="img")({"img": test_data})["img"] cp.testing.assert_allclose(result, cp.asarray(test_data)) test_data = ((1, 2), (3, 4)) result = ToCupyd(keys="img")({"img": test_data})["img"] cp.testing.assert_allclose(result, cp.asarray(test_data))
def test_tensor_input(self): test_data = torch.tensor([[1, 2], [3, 4]]) test_data = test_data.rot90() self.assertFalse(test_data.is_contiguous()) result = ToCupyd(keys="img")({"img": test_data})["img"] self.assertTrue(isinstance(result, cp.ndarray)) self.assertTrue(result.flags["C_CONTIGUOUS"]) cp.testing.assert_allclose(result, test_data.numpy())
def test_numpy_input(self): test_data = np.array([[1, 2], [3, 4]]) test_data = np.rot90(test_data) self.assertFalse(test_data.flags["C_CONTIGUOUS"]) result = ToCupyd(keys="img")({"img": test_data})["img"] self.assertTrue(isinstance(result, cp.ndarray)) self.assertTrue(result.flags["C_CONTIGUOUS"]) cp.testing.assert_allclose(result, test_data)