From 694c20c03156be427509cf82fb7b65ef4cc28e2f Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Sun, 9 Feb 2014 15:01:11 -0600
Subject: [PATCH] =?UTF-8?q?Return=20copies=20from=20arithmetic=20operators?=
 =?UTF-8?q?,=20rather=20than=20the=20array=20itself,=20for=20more=20consis?=
 =?UTF-8?q?tent=20semantics=20(reported=20by=20Istv=C3=A1n=20Lorentz)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pyopencl/array.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/pyopencl/array.py b/pyopencl/array.py
index 2aac16ea..9b28f17b 100644
--- a/pyopencl/array.py
+++ b/pyopencl/array.py
@@ -823,7 +823,7 @@ class Array(object):
         else:
             # add a scalar
             if other == 0:
-                return self
+                return self.copy()
             else:
                 common_dtype = _get_common_dtype(self, other, self.queue)
                 result = self._new_like_me(common_dtype)
@@ -846,7 +846,7 @@ class Array(object):
         else:
             # subtract a scalar
             if other == 0:
-                return self
+                return self.copy()
             else:
                 result = self._new_like_me(
                         _get_common_dtype(self, other, self.queue))
@@ -927,7 +927,7 @@ class Array(object):
             self._div(result, self, other)
         else:
             if other == 1:
-                return self
+                return self.copy()
             else:
                 # create a new array for the result
                 common_dtype = _get_common_dtype(self, other, self.queue)
@@ -1020,9 +1020,9 @@ class Array(object):
         return result
 
     def astype(self, dtype, queue=None):
-        """Return *self*, cast to *dtype*."""
+        """Return a copy of *self*, cast to *dtype*."""
         if dtype == self.dtype:
-            return self
+            return self.copy()
 
         result = self._new_like_me(dtype=dtype)
         self._copy(result, self, queue=queue)
-- 
GitLab