From 3155b96a56a3a597365cafa29285df9b6294fff0 Mon Sep 17 00:00:00 2001
From: Matt Wala <wala1@illinois.edu>
Date: Tue, 12 Dec 2017 18:11:49 -0600
Subject: [PATCH] Array: Fix bitwise self assignment to return self.

Closes #6 on gitlab.
---
 pyopencl/array.py  | 6 ++++++
 test/test_array.py | 7 +++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/pyopencl/array.py b/pyopencl/array.py
index 001c63bd..4d5334be 100644
--- a/pyopencl/array.py
+++ b/pyopencl/array.py
@@ -1138,6 +1138,8 @@ class Array(object):
             self.add_event(
                     self._scalar_binop(self, self, other, op="&"))
 
+        return self
+
     def __ior__(self, other):
         common_dtype = _get_common_dtype(self, other, self.queue)
 
@@ -1150,6 +1152,8 @@ class Array(object):
             self.add_event(
                     self._scalar_binop(self, self, other, op="|"))
 
+        return self
+
     def __ixor__(self, other):
         common_dtype = _get_common_dtype(self, other, self.queue)
 
@@ -1162,6 +1166,8 @@ class Array(object):
             self.add_event(
                     self._scalar_binop(self, self, other, op="^"))
 
+        return self
+
     def _zero_fill(self, queue=None, wait_for=None):
         queue = queue or self.queue
 
diff --git a/test/test_array.py b/test/test_array.py
index d5710085..a9c17170 100644
--- a/test/test_array.py
+++ b/test/test_array.py
@@ -552,14 +552,17 @@ def test_bitwise(ctx_factory):
 
         for op in [o.iand, o.ior, o.ixor]:
             res_dev = a_dev.copy()
-            op(res_dev, b_dev)
+            op_res = op(res_dev, b_dev)
+            assert op_res is res_dev
+
             res = a.copy()
             op(res, b)
 
             assert (res_dev.get() == res).all()
 
             res_dev = a_dev.copy()
-            op(res_dev, s)
+            op_res = op(res_dev, s)
+            assert op_res is res_dev
             res = a.copy()
             op(res, s)
 
-- 
GitLab