[pypy-commit] pypy numpy-ndim-size: Changed size and ndim on FloatWrapper to not use exceptions. Instead, size and ndim are -1 on such types.
justinpeel
noreply at buildbot.pypy.org
Mon Jul 18 08:06:45 CEST 2011
Author: Justin Peel <notmuchtotell at gmail.com>
Branch: numpy-ndim-size
Changeset: r45706:0b020cb8d109
Date: 2011-07-18 00:06 -0600
http://bitbucket.org/pypy/pypy/changeset/0b020cb8d109/
Log: Changed size and ndim on FloatWrapper to not use exceptions.
Instead, size and ndim are -1 on such types.
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
@@ -88,18 +88,12 @@
signature = Signature()
def impl(self, space, w_other):
w_other = convert_to_array(space, w_other)
- try:
- w_other_size = w_other.find_size()
- self_size = self.find_size()
- except ValueError:
- # this will be raised if one of the arrays is a scalar.
- pass
- else:
+ w_other_size = w_other.find_size()
+ if w_other_size != -1 and w_other_size != self.find_size():
# Need a better dimension check here for N-dim arrays
- if w_other_size != self_size:
- raise OperationError(space.w_ValueError,
- space.wrap("Cannot %s arrays of unequal dimensions" \
- % function.__name__))
+ raise OperationError(space.w_ValueError,
+ space.wrap("Cannot %s arrays of unequal dimensions" \
+ % function.__name__))
new_sig = self.signature.transition(signature)
res = Call2(
function,
@@ -257,6 +251,8 @@
return self.get_concrete().descr_len(space)
def descr_get_size(self, space):
+ # for arrays generated by things like arr[arr>0] we will need
+ # to have find_size force them to be concrete
return space.wrap(self.find_size())
def descr_get_ndim(self, space):
@@ -303,10 +299,10 @@
self.float_value = float_value
def find_size(self):
- raise ValueError
+ return -1
def find_ndim(self):
- raise ValueError
+ return -1
def eval(self, i):
return self.float_value
@@ -401,18 +397,16 @@
self.right = None
def _find_size(self):
- try:
- return self.left.find_size()
- except ValueError:
- pass
- return self.right.find_size()
+ size = self.left.find_size()
+ if size == -1:
+ return self.right.find_size()
+ return size
def _find_ndim(self):
- try:
- return self.left.find_ndim()
- except ValueError:
- pass
- return self.right.find_ndim()
+ ndim = self.left.find_ndim()
+ if ndim == -1:
+ return self.right.find_ndim()
+ return ndim
def _eval(self, i):
lhs, rhs = self.left.eval(i), self.right.eval(i)
More information about the pypy-commit
mailing list