From 647a63da9ea32f5d5ca203ba3fc92ac96df32c8c Mon Sep 17 00:00:00 2001 From: Mit Kotak Date: Wed, 27 Jul 2022 21:27:24 -0500 Subject: [PATCH] added pos + test for pos | neg --- pycuda/gpuarray.py | 3 +++ test/test_gpuarray.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/pycuda/gpuarray.py b/pycuda/gpuarray.py index e6238231..c9cacc4b 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 ddd8b2f6..0246fc27 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.""" -- GitLab