[pypy-commit] pypy issue-2148: extract is_scalar_like() from find_shape_and_elems()

rlamy noreply at buildbot.pypy.org
Sun Oct 4 19:18:40 CEST 2015


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: issue-2148
Changeset: r79981:8a2df44b76b7
Date: 2015-10-04 18:06 +0100
http://bitbucket.org/pypy/pypy/changeset/8a2df44b76b7/

Log:	extract is_scalar_like() from find_shape_and_elems()

diff --git a/pypy/module/micronumpy/ctors.py b/pypy/module/micronumpy/ctors.py
--- a/pypy/module/micronumpy/ctors.py
+++ b/pypy/module/micronumpy/ctors.py
@@ -189,17 +189,21 @@
         return w_arr
 
 def find_shape_and_elems(space, w_iterable, dtype):
-    isstr = space.isinstance_w(w_iterable, space.w_str)
-    if not support.issequence_w(space, w_iterable) or isstr:
-        if dtype is None or dtype.char != NPY.CHARLTR:
-            return [], [w_iterable]
-    is_rec_type = dtype is not None and dtype.is_record()
-    if is_rec_type and is_single_elem(space, w_iterable, is_rec_type):
-        return [], [w_iterable]
-    if isinstance(w_iterable, W_NDimArray) and w_iterable.is_scalar():
+    if is_scalar_like(space, w_iterable, dtype):
         return [], [w_iterable]
     return _find_shape_and_elems(space, w_iterable, is_rec_type)
 
+def is_scalar_like(space, w_obj, dtype):
+    isstr = space.isinstance_w(w_obj, space.w_str)
+    if not support.issequence_w(space, w_obj) or isstr:
+        if dtype is None or dtype.char != NPY.CHARLTR:
+            return True
+    is_rec_type = dtype is not None and dtype.is_record()
+    if is_rec_type and is_single_elem(space, w_obj, is_rec_type):
+        return True
+    if isinstance(w_obj, W_NDimArray) and w_obj.is_scalar():
+        return True
+    return False
 
 def _find_shape_and_elems(space, w_iterable, is_rec_type):
     from pypy.objspace.std.bufferobject import W_Buffer


More information about the pypy-commit mailing list