From a0e460a2274aac8fa7c80418a8d2ed9428ffe711 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sat, 26 Jan 2019 03:51:43 +0100 Subject: [PATCH 1/2] Remove deprecated usage of np.asscalar in pyopencl.array (closes #11) Also rename "s" to "size" for clarity. --- pyopencl/array.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pyopencl/array.py b/pyopencl/array.py index a4a5f4cf..98dd091c 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -425,13 +425,13 @@ class Array(object): # invariant here: allocator, queue set - # {{{ determine shape and strides + # {{{ determine shape, size, and strides dtype = np.dtype(dtype) try: - s = 1 + size = 1 for dim in shape: - s *= dim + size *= dim except TypeError: import sys if sys.version_info >= (3,): @@ -442,12 +442,12 @@ class Array(object): if not isinstance(shape, admissible_types): raise TypeError("shape must either be iterable or " "castable to an integer") - s = shape + size = shape shape = (shape,) - if isinstance(s, np.integer): + if isinstance(size, np.integer): # bombs if s is a Python integer - s = np.asscalar(s) + size = size.item() if strides is None: strides = _make_strides(dtype.itemsize, shape, order) @@ -475,7 +475,7 @@ class Array(object): else: self.events = events - self.size = s + self.size = size alloc_nbytes = self.nbytes = self.dtype.itemsize * self.size self.allocator = allocator -- GitLab From ff33c74a78fbecfde1f5ebcca9eda81c62b39057 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sat, 26 Jan 2019 03:53:20 +0100 Subject: [PATCH 2/2] Remove a now-obvious comment --- pyopencl/array.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyopencl/array.py b/pyopencl/array.py index 98dd091c..429affba 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -446,7 +446,6 @@ class Array(object): shape = (shape,) if isinstance(size, np.integer): - # bombs if s is a Python integer size = size.item() if strides is None: -- GitLab