Author: mattip Branch: matrixmath-dot Changeset: r50196:924460a509cd Date: 2011-12-05 17:36 +0200 http://bitbucket.org/pypy/pypy/changeset/924460a509cd/
Log: expose promote_to_largest to reduce functions, fixes sum() prod() bug without ruining mean() diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py --- a/pypy/module/micronumpy/interp_numarray.py +++ b/pypy/module/micronumpy/interp_numarray.py @@ -388,15 +388,17 @@ descr_rpow = _binop_right_impl("power") descr_rmod = _binop_right_impl("mod") - def _reduce_ufunc_impl(ufunc_name): + def _reduce_ufunc_impl(ufunc_name, promote_to_largest): def impl(self, space): - return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space, self, multidim=True) + return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space, + self, multidim=True, promote_to_largest=promote_to_largest) return func_with_new_name(impl, "reduce_%s_impl" % ufunc_name) - descr_sum = _reduce_ufunc_impl("add") - descr_prod = _reduce_ufunc_impl("multiply") - descr_max = _reduce_ufunc_impl("maximum") - descr_min = _reduce_ufunc_impl("minimum") + descr_sum = _reduce_ufunc_impl("add", False) + descr_prod = _reduce_ufunc_impl("multiply", False) + descr_max = _reduce_ufunc_impl("maximum", False) + descr_min = _reduce_ufunc_impl("minimum", False) + descr_sumpromote = _reduce_ufunc_impl("add", True) def _reduce_argmax_argmin_impl(op_name): reduce_driver = jit.JitDriver( @@ -816,7 +818,7 @@ shape[:]) def descr_mean(self, space): - return space.div(self.descr_sum(space), space.wrap(self.find_size())) + return space.div(self.descr_sumpromote(space), space.wrap(self.find_size())) def descr_nonzero(self, space): if self.find_size() > 1: diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py --- a/pypy/module/micronumpy/interp_ufuncs.py +++ b/pypy/module/micronumpy/interp_ufuncs.py @@ -46,9 +46,9 @@ return self.call(space, __args__.arguments_w) def descr_reduce(self, space, w_obj): - return self.reduce(space, w_obj, multidim=False) + return self.reduce(space, w_obj, multidim=False, promote_to_largest=False) - def reduce(self, space, w_obj, multidim): + def reduce(self, space, w_obj, multidim, promote_to_largest): from pypy.module.micronumpy.interp_numarray import convert_to_array, Scalar if self.argcount != 2: raise OperationError(space.w_ValueError, space.wrap("reduce only " @@ -63,7 +63,8 @@ size = obj.find_size() dtype = find_unaryop_result_dtype( space, obj.find_dtype(), - promote_to_largest=True + promote_to_largest = promote_to_largest, + promote_bools = True, ) start = obj.start_iter(obj.shape) shapelen = len(obj.shape) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit