From 70ec9e1d73bb922af267ba3383df645aaf982467 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Mon, 16 Jul 2012 13:22:47 -0400
Subject: [PATCH] Fix 1/array.

---
 pyopencl/array.py  | 11 ++++-------
 test/test_array.py | 25 +++++++++++++++++++++++--
 2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/pyopencl/array.py b/pyopencl/array.py
index 6ccb093f..a4cf9ff5 100644
--- a/pyopencl/array.py
+++ b/pyopencl/array.py
@@ -668,13 +668,10 @@ class Array(object):
             result = self._new_like_me(_get_common_dtype(self, other, self.queue))
             other._div(result, self)
         else:
-            if other == 1:
-                return self
-            else:
-                # create a new array for the result
-                common_dtype = _get_common_dtype(self, other, self.queue)
-                result = self._new_like_me(common_dtype)
-                self._rdiv_scalar(result, self, common_dtype.type(other))
+            # create a new array for the result
+            common_dtype = _get_common_dtype(self, other, self.queue)
+            result = self._new_like_me(common_dtype)
+            self._rdiv_scalar(result, self, common_dtype.type(other))
 
         return result
 
diff --git a/test/test_array.py b/test/test_array.py
index 8e5a56ac..187e0ea3 100644
--- a/test/test_array.py
+++ b/test/test_array.py
@@ -178,6 +178,25 @@ def test_mix_complex(ctx_factory):
 
                     assert correct
 
+@pytools.test.mark_test.opencl
+def test_pow_neg1_vs_inv(ctx_factory):
+    ctx = ctx_factory()
+    queue = cl.CommandQueue(ctx)
+
+    device = ctx.devices[0]
+    if not has_double_support(device):
+        from py.test import skip
+        skip("double precision not supported on %s" % device)
+
+    a_dev = make_random_array(queue, np.complex128, 20000)
+
+    res1 = (a_dev ** (-1)).get()
+    res2 = (1/a_dev).get()
+    ref = 1/a_dev.get()
+
+    assert la.norm(res1-ref, np.inf) / la.norm(ref) < 1e-13
+    assert la.norm(res2-ref, np.inf) / la.norm(ref) < 1e-13
+
 @pytools.test.mark_test.opencl
 def test_len(ctx_factory):
     context = ctx_factory()
@@ -673,8 +692,10 @@ def test_astype(ctx_factory):
 
     from pyopencl.clrandom import rand as clrand
 
-    if not has_double_support(context.devices[0]):
-        return
+    device = context.devices[0]
+    if not has_double_support(device):
+        from py.test import skip
+        skip("double precision not supported on %s" % device)
 
     a_gpu = clrand(queue, (2000,), dtype=np.float32)
 
-- 
GitLab