Commits

Romain Guillebert committed a9b32d2

Change the way ufuncs work on scalar to make it possible to call __array_prepare__

Comments (0)

Files changed (1)

pypy/module/micronumpy/interp_ufuncs.py

 from pypy.module.micronumpy.strides import shape_agreement
 from pypy.module.micronumpy.base import convert_to_array, W_NDimArray
 from pypy.module.micronumpy.constants import *
+from pypy.module.micronumpy.arrayimpl.scalar import Scalar
 
 def done_if_true(dtype, val):
     return dtype.itemtype.bool(val)
                 w_ldtype = w_rdtype
 
         if (self.int_only and (not w_ldtype.is_int_type() or not w_rdtype.is_int_type()) or
-                not self.allow_bool and (w_ldtype.is_bool_type() or w_rdtype.is_bool_type()) or
-                not self.allow_complex and (w_ldtype.is_complex_type() or w_rdtype.is_complex_type())):
+            not self.allow_bool and (w_ldtype.is_bool_type() or w_rdtype.is_bool_type()) or
+            not self.allow_complex and (w_ldtype.is_complex_type() or w_rdtype.is_complex_type())):
             raise OperationError(space.w_TypeError, space.wrap("Unsupported types"))
 
         calc_dtype = find_binop_result_dtype(space,
                 w_rhs.get_scalar_value().convert_to(space, calc_dtype)
             )
             if isinstance(out, W_NDimArray):
+                # TODO: Call __array_prepare__
                 if out.is_scalar():
                     out.set_scalar_value(arr)
                 else:
                     out.fill(space, arr)
             else:
-                out = arr
+                # TODO: Call __array_prepare__
+                out = W_NDimArray(Scalar(res_dtype, res_dtype.box(0)))
+                out.set_scalar_value(arr)
+
             return out
         new_shape = shape_agreement(space, w_lhs.get_shape(), w_rhs)
         new_shape = shape_agreement(space, new_shape, out, broadcast_down=False)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.