Skip to content

Commit

Permalink
Return copies from arithmetic operators, rather than the array itself…
Browse files Browse the repository at this point in the history
…, for more consistent semantics (reported by István Lorentz)
  • Loading branch information
inducer committed Feb 9, 2014
1 parent b85bd39 commit 694c20c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pyopencl/array.py
Expand Up @@ -823,7 +823,7 @@ def __add__(self, other):
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)
Expand All @@ -846,7 +846,7 @@ def __sub__(self, other):
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))
Expand Down Expand Up @@ -927,7 +927,7 @@ def __div__(self, other):
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)
Expand Down Expand Up @@ -1020,9 +1020,9 @@ def reverse(self, queue=None):
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)
Expand Down

0 comments on commit 694c20c

Please sign in to comment.