diff --git a/pycuda/gpuarray.py b/pycuda/gpuarray.py index e6238231c26f2b2243c3fcfeebbd5318b07ee43f..c9cacc4b034c8014404bd4e4230c8687679bbc6d 100644 --- a/pycuda/gpuarray.py +++ b/pycuda/gpuarray.py @@ -584,6 +584,9 @@ class GPUArray: else: return self._axpbz(1, -other, self) + def __pos__(self): + return self + def __neg__(self): result = self._new_like_me() return self._axpbz(-1, 0, result) diff --git a/test/test_gpuarray.py b/test/test_gpuarray.py index ddd8b2f6eb0fac4a47795336eec35affdd4a0699..0246fc271b4d2aebd26b16e79287a87297e47b8a 100644 --- a/test/test_gpuarray.py +++ b/test/test_gpuarray.py @@ -127,6 +127,15 @@ class TestGPUArray: assert (a * a == a_squared).all() + @mark_cuda_test + def test_unit_multiply_array(self): + + a = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).astype(np.float32) + + a_gpu = gpuarray.to_gpu(a) + np.testing.assert_allclose(+a_gpu.get(), +a, rtol=1e-6) + np.testing.assert_allclose(-a_gpu.get(), -a, rtol=1e-6) + @mark_cuda_test def test_addition_array(self): """Test the addition of two arrays."""