Author: Ronan Lamy <[email protected]>
Branch: fix-result-types
Changeset: r77672:1ef11fbdb532
Date: 2015-05-29 04:14 +0100
http://bitbucket.org/pypy/pypy/changeset/1ef11fbdb532/

Log:    Move find_dtype_for_seq() to ctors.py

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
@@ -64,8 +64,8 @@
     #print 'create view from 
shape',shape,'dtype',dtype,'descr',w_descr,'data',data_w[0],'rw',rw
     raise oefmt(space.w_NotImplementedError,
                 "creating array from __array_interface__ not supported yet")
-    return 
-    
+    return
+
 
 @unwrap_spec(ndmin=int, copy=bool, subok=bool)
 def array(space, w_object, w_dtype=None, copy=True, w_order=None, subok=False,
@@ -114,9 +114,9 @@
             elif not copy and (subok or type(w_object) is W_NDimArray):
                 return w_object
         if subok and not type(w_object) is W_NDimArray:
-            raise oefmt(space.w_NotImplementedError, 
+            raise oefmt(space.w_NotImplementedError,
                 "array(..., subok=True) only partially implemented")
-        # we have a ndarray, but need to copy or change dtype 
+        # we have a ndarray, but need to copy or change dtype
         if dtype is None:
             dtype = w_object.get_dtype()
         if dtype != w_object.get_dtype():
@@ -126,7 +126,7 @@
             shape = w_object.get_shape()
             w_arr = W_NDimArray.from_shape(space, shape, dtype, order=order)
             if support.product(shape) == 1:
-                w_arr.set_scalar_value(dtype.coerce(space, 
+                w_arr.set_scalar_value(dtype.coerce(space,
                         w_object.implementation.getitem(0)))
             else:
                 loop.setslice(space, shape, w_arr.implementation, 
w_object.implementation)
@@ -137,13 +137,13 @@
             with imp as storage:
                 sz = support.product(w_object.get_shape()) * dtype.elsize
                 return W_NDimArray.from_shape_and_storage(space,
-                    w_object.get_shape(), storage, dtype, storage_bytes=sz, 
+                    w_object.get_shape(), storage, dtype, storage_bytes=sz,
                     w_base=w_base, start=imp.start)
     else:
         # not an array
         shape, elems_w = strides.find_shape_and_elems(space, w_object, dtype)
     if dtype is None or (dtype.is_str_or_unicode() and dtype.elsize < 1):
-        dtype = strides.find_dtype_for_seq(space, elems_w, dtype)
+        dtype = find_dtype_for_seq(space, elems_w, dtype)
         if dtype is None:
             dtype = descriptor.get_dtype_cache(space).w_float64dtype
         elif dtype.is_str_or_unicode() and dtype.elsize < 1:
@@ -170,7 +170,7 @@
         return w_array
 
     shape, elems_w = strides.find_shape_and_elems(space, w_object, None)
-    dtype = strides.find_dtype_for_seq(space, elems_w, None)
+    dtype = find_dtype_for_seq(space, elems_w, None)
     if dtype is None:
         dtype = descriptor.get_dtype_cache(space).w_float64dtype
     elif dtype.is_str_or_unicode() and dtype.elsize < 1:
@@ -184,6 +184,21 @@
         loop.assign(space, w_arr, elems_w)
         return w_arr
 
+def _dtype_guess(space, dtype, w_elem):
+    from .casting import scalar2dtype, find_binop_result_dtype
+    if isinstance(w_elem, W_NDimArray) and w_elem.is_scalar():
+        w_elem = w_elem.get_scalar_value()
+    elem_dtype = scalar2dtype(space, w_elem)
+    return find_binop_result_dtype(space, elem_dtype, dtype)
+
+def find_dtype_for_seq(space, elems_w, dtype):
+    if len(elems_w) == 1:
+        w_elem = elems_w[0]
+        return _dtype_guess(space, dtype, w_elem)
+    for w_elem in elems_w:
+        dtype = _dtype_guess(space, dtype, w_elem)
+    return dtype
+
 
 def _zeros_or_empty(space, w_shape, w_dtype, w_order, zero):
     dtype = space.interp_w(descriptor.W_Dtype,
@@ -359,5 +374,5 @@
         return a
     else:
         writable = not buf.readonly
-    return W_NDimArray.from_shape_and_storage(space, [n], storage, 
storage_bytes=s, 
+    return W_NDimArray.from_shape_and_storage(space, [n], storage, 
storage_bytes=s,
                                 dtype=dtype, w_base=w_buffer, 
writable=writable)
diff --git a/pypy/module/micronumpy/strides.py 
b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -220,24 +220,6 @@
         batch = new_batch
 
 
-def _dtype_guess(space, dtype, w_elem):
-    from .casting import scalar2dtype, find_binop_result_dtype
-    if isinstance(w_elem, W_NDimArray) and w_elem.is_scalar():
-        w_elem = w_elem.get_scalar_value()
-    elem_dtype = scalar2dtype(space, w_elem)
-    return find_binop_result_dtype(space, elem_dtype, dtype)
-
-def find_dtype_for_seq(space, elems_w, dtype):
-    if len(elems_w) == 1:
-        w_elem = elems_w[0]
-        return _dtype_guess(space, dtype, w_elem)
-    return _find_dtype_for_seq(space, elems_w, dtype)
-
-def _find_dtype_for_seq(space, elems_w, dtype):
-    for w_elem in elems_w:
-        dtype = _dtype_guess(space, dtype, w_elem)
-    return dtype
-
 
 @jit.unroll_safe
 def shape_agreement(space, shape1, w_arr2, broadcast_down=True):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to