diff --git a/pyopencl/array.py b/pyopencl/array.py index 13bb24f36e455ba62aabdfb7feb4e2dea3320c91..4107feac0b056caf7bbfe61f6b0fe06c1c0e4e9d 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -1065,7 +1065,6 @@ class Array(object): def __rdiv__(self, other): """Divides an array by a scalar or an array, i.e. ``other / self``. """ - if isinstance(other, Array): result = self._new_like_me( _get_common_dtype(self, other, self.queue)) @@ -1081,11 +1080,11 @@ class Array(object): __rtruediv__ = __rdiv__ - def __itruediv__(self, other): common_dtype = _get_common_dtype(self, other, self.queue) if common_dtype is not self.dtype: - raise TypeError("Cannot cast division output from {!r} to {!r}".format(self.dtype, common_dtype)) + raise TypeError("Cannot cast division output from {!r} to {!r}" + .format(self.dtype, common_dtype)) if isinstance(other, Array): self.add_event( @@ -1096,10 +1095,11 @@ class Array(object): else: # cast 1/other to float32, as float64 might not be available... self.add_event( - self._axpbz(self, np.float32(1/other), self, common_dtype.type(0))) + self._axpbz(self, np.float32(1/other), + self, common_dtype.type(0))) return self - + def __and__(self, other): common_dtype = _get_common_dtype(self, other, self.queue) diff --git a/test/test_array.py b/test/test_array.py index 34497363a2b4b66f95a01a22164879ff0ff0237c..e4eaf201905237c716a6e56a76cdf1725de4f143 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -499,13 +499,15 @@ def test_divide_array(ctx_factory): a_divide = (b_gpu / a_gpu).get() assert (np.abs(b / a - a_divide) < 1e-3).all() + def test_divide_inplace_scalar(ctx_factory): """Test inplace division of arrays and a scalar.""" context = ctx_factory() queue = cl.CommandQueue(context) - for dtype in (np.uint8, np.int8, np.uint16, np.int16, np.uint32, np.int32, np.float32): + for dtype in (np.uint8, np.int8, np.uint16, np.int16, + np.uint32, np.int32, np.float32): #test data a = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90, 100]).astype(dtype) s = 40 @@ -515,13 +517,15 @@ def test_divide_inplace_scalar(ctx_factory): a_divide = a_gpu.get() assert (np.abs((a / s).astype(dtype) - a_divide) < 1e-3).all() + def test_divide_inplace_array(ctx_factory): """Test inplace division of arrays.""" context = ctx_factory() queue = cl.CommandQueue(context) - for dtype in (np.uint8, np.int8, np.uint16, np.int16, np.uint32, np.int32, np.float32): + for dtype in (np.uint8, np.int8, np.uint16, np.int16, + np.uint32, np.int32, np.float32): #test data a = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90, 100]).astype(dtype) b = np.array([10, 10, 10, 10, 10, 10, 10, 10, 10, 10]).astype(dtype) @@ -533,7 +537,7 @@ def test_divide_inplace_array(ctx_factory): a_divide = a_gpu.get() assert (np.abs(a / b - a_divide) < 1e-3).all() - + def test_bitwise(ctx_factory): if _PYPY: pytest.xfail("numpypy: missing bitwise ops")