Commits

Justin Peel committed 0b020cb

Changed size and ndim on FloatWrapper to not use exceptions. Instead, size and ndim are -1 on such types.

Comments (0)

Files changed (1)

pypy/module/micronumpy/interp_numarray.py

         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,
         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):
         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
         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)
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.