From a881feafefbcb45285a25789248cc03309b5e3cd Mon Sep 17 00:00:00 2001
From: Martin Weigert <mweigert@mpi-cbg.de>
Date: Wed, 6 Feb 2019 20:56:19 +0100
Subject: [PATCH] Enables inplace division (__itruediv__) for
 pyopencl.array.Array class. This is similar to already inplace multiplication
 (__imul__).

---
 pyopencl/array.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/pyopencl/array.py b/pyopencl/array.py
index 1bfdc137..0da86e57 100644
--- a/pyopencl/array.py
+++ b/pyopencl/array.py
@@ -1081,6 +1081,21 @@ class Array(object):
 
     __rtruediv__ = __rdiv__
 
+
+    def __itruediv__(self, other):
+        if isinstance(other, Array):
+            self.add_event(
+                    self._div(self, self, other))
+        else:
+            if other == 1:
+                return self.copy()
+            else:
+                common_dtype = _get_common_dtype(self, other, self.queue)
+                self.add_event(
+                    self._axpbz(self, common_dtype.type(1/other), self, self.dtype.type(0)))
+
+        return self
+        
     def __and__(self, other):
         common_dtype = _get_common_dtype(self, other, self.queue)
 
-- 
GitLab