Author: Romain Guillebert <romain...@gmail.com> Branch: Changeset: r61495:602298f4e786 Date: 2013-02-20 15:34 +0100 http://bitbucket.org/pypy/pypy/changeset/602298f4e786/
Log: Return False when comparing two ndarrays which have non-agreeing shapes 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 @@ -250,7 +250,7 @@ ret = self.implementation.get_imag(self) if ret: return W_NDimArray(ret) - raise OperationError(space.w_NotImplementedError, + raise OperationError(space.w_NotImplementedError, space.wrap('imag not implemented for this dtype')) def descr_set_real(self, space, w_value): @@ -261,7 +261,7 @@ def descr_set_imag(self, space, w_value): # if possible, copy (broadcast) values into self if not self.get_dtype().is_complex_type(): - raise OperationError(space.w_TypeError, + raise OperationError(space.w_TypeError, space.wrap('array does not have imaginary part to set')) tmp = self.implementation.get_imag(self) tmp.setslice(space, convert_to_array(space, w_value)) @@ -302,11 +302,11 @@ @unwrap_spec(axis1=int, axis2=int) def descr_swapaxes(self, space, axis1, axis2): """a.swapaxes(axis1, axis2) - + Return a view of the array with `axis1` and `axis2` interchanged. - + Refer to `numpy.swapaxes` for full documentation. - + See Also -------- numpy.swapaxes : equivalent function @@ -439,7 +439,7 @@ ret = impl.base() if ret is None: return space.w_None - return ret + return ret @unwrap_spec(inplace=bool) def descr_byteswap(self, space, inplace=False): @@ -492,7 +492,7 @@ "axis1 and axis2 cannot be the same")) return interp_arrayops.diagonal(space, self.implementation, offset, axis1, axis2) - + def descr_dump(self, space, w_file): raise OperationError(space.w_NotImplementedError, space.wrap( "dump not implemented yet")) @@ -509,7 +509,7 @@ raise OperationError(space.w_NotImplementedError, space.wrap( "setting flags not implemented yet")) - @unwrap_spec(offset=int) + @unwrap_spec(offset=int) def descr_getfield(self, space, w_dtype, offset): raise OperationError(space.w_NotImplementedError, space.wrap( "getfield not implemented yet")) @@ -518,7 +518,7 @@ raise OperationError(space.w_NotImplementedError, space.wrap( "itemset not implemented yet")) - @unwrap_spec(neworder=str) + @unwrap_spec(neworder=str) def descr_newbyteorder(self, space, neworder): raise OperationError(space.w_NotImplementedError, space.wrap( "newbyteorder not implemented yet")) @@ -551,7 +551,7 @@ raise OperationError(space.w_NotImplementedError, space.wrap( "setfield not implemented yet")) - def descr_setflags(self, space, w_write=None, w_align=None, w_uic=None): + def descr_setflags(self, space, w_write=None, w_align=None, w_uic=None): raise OperationError(space.w_NotImplementedError, space.wrap( "setflags not implemented yet")) @@ -572,7 +572,7 @@ "tofile not implemented yet")) def descr_trace(self, space, w_offset=0, w_axis1=0, w_axis2=1, - w_dtype=None, w_out=None): + w_dtype=None, w_out=None): raise OperationError(space.w_NotImplementedError, space.wrap( "trace not implemented yet")) @@ -627,21 +627,23 @@ w_remainder = self.descr_mod(space, w_other) return space.newtuple([w_quotient, w_remainder]) - _descr_eq = _binop_impl("equal") + def _binop_comp_impl(ufunc): + def impl(self, space, w_other, w_out=None): + try: + return ufunc(self, space, w_other, w_out) + except OperationError, e: + if e.match(space, space.w_ValueError): + return space.w_False + raise e - def descr_eq(self, space, w_other): - try: - return self._descr_eq(space, w_other) - except OperationError, e: - if e.match(space, space.w_ValueError): - return space.w_False - raise e + return func_with_new_name(impl, ufunc.func_name) - descr_ne = _binop_impl("not_equal") - descr_lt = _binop_impl("less") - descr_le = _binop_impl("less_equal") - descr_gt = _binop_impl("greater") - descr_ge = _binop_impl("greater_equal") + descr_eq = _binop_comp_impl(_binop_impl("equal")) + descr_ne = _binop_comp_impl(_binop_impl("not_equal")) + descr_lt = _binop_comp_impl(_binop_impl("less")) + descr_le = _binop_comp_impl(_binop_impl("less_equal")) + descr_gt = _binop_comp_impl(_binop_impl("greater")) + descr_ge = _binop_comp_impl(_binop_impl("greater_equal")) def _binop_right_impl(ufunc_name): def impl(self, space, w_other, w_out=None): @@ -707,7 +709,7 @@ if space.is_none(w_out): out = None elif not isinstance(w_out, W_NDimArray): - raise OperationError(space.w_TypeError, space.wrap( + raise OperationError(space.w_TypeError, space.wrap( 'output must be an array')) else: out = w_out @@ -727,7 +729,7 @@ descr_cumsum = _reduce_ufunc_impl('add', cumultative=True) descr_cumprod = _reduce_ufunc_impl('multiply', cumultative=True) - + def descr_mean(self, space, w_axis=None, w_out=None): if space.is_none(w_axis): w_denom = space.wrap(self.get_size()) @@ -872,7 +874,7 @@ swapaxes = interp2app(W_NDimArray.descr_swapaxes), flat = GetSetProperty(W_NDimArray.descr_get_flatiter), item = interp2app(W_NDimArray.descr_item), - real = GetSetProperty(W_NDimArray.descr_get_real, + real = GetSetProperty(W_NDimArray.descr_get_real, W_NDimArray.descr_set_real), imag = GetSetProperty(W_NDimArray.descr_get_imag, W_NDimArray.descr_set_imag), @@ -932,7 +934,7 @@ dtype) #if dtype is interp_dtype.get_dtype_cache(space).w_float64dtype: # break - + if dtype is None: dtype = interp_dtype.get_dtype_cache(space).w_float64dtype if ndmin > len(shape): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit