[Scipy-svn] r2935 - in trunk/Lib/sandbox/numexpr: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Thu Apr 19 15:57:25 EDT 2007


Author: cookedm
Date: 2007-04-19 14:57:23 -0500 (Thu, 19 Apr 2007)
New Revision: 2935

Modified:
   trunk/Lib/sandbox/numexpr/expressions.py
   trunk/Lib/sandbox/numexpr/tests/test_numexpr.py
Log:
[numexpr] fix float/int comparision [ivilata]


Modified: trunk/Lib/sandbox/numexpr/expressions.py
===================================================================
--- trunk/Lib/sandbox/numexpr/expressions.py	2007-04-19 19:49:51 UTC (rev 2934)
+++ trunk/Lib/sandbox/numexpr/expressions.py	2007-04-19 19:57:23 UTC (rev 2935)
@@ -75,12 +75,15 @@
     return type_to_kind[converter]
 
 def binop(opname, reversed=False, kind=None):
+    # Getting the named method from self (after reversal) does not
+    # always work (e.g. int constants do not have a __lt__ method).
+    opfunc = getattr(operator, "__%s__" % opname)
     @ophelper
     def operation(self, other):
         if reversed:
             self, other = other, self
         if allConstantNodes([self, other]):
-            return ConstantNode(getattr(self.value, "__%s__" % opname)(other.value))
+            return ConstantNode(opfunc(self.value, other.value))
         else:
             return OpNode(opname, (self, other), kind=kind)
     return operation

Modified: trunk/Lib/sandbox/numexpr/tests/test_numexpr.py
===================================================================
--- trunk/Lib/sandbox/numexpr/tests/test_numexpr.py	2007-04-19 19:49:51 UTC (rev 2934)
+++ trunk/Lib/sandbox/numexpr/tests/test_numexpr.py	2007-04-19 19:57:23 UTC (rev 2935)
@@ -186,6 +186,7 @@
           'sinh(a)',
           '2*a + (cos(3)+5)*sinh(cos(b))',
           '2*a + arctan2(a, b)',
+          'arcsin(0.5)',
           'where(a, 2, b)',
           'where((a-10).real, a, 2)',
           'cos(1+1)',
@@ -210,6 +211,7 @@
     cmptests.append("a/2+5 %s b" % op)
     cmptests.append("a/2+5 %s 7" % op)
     cmptests.append("7 %s b" % op)
+    cmptests.append("7.0 %s 5" % op)
 tests.append(('COMPARISONS', cmptests))
 
 func1tests = []




More information about the Scipy-svn mailing list