[pypy-commit] pypy numpy-comparison: Add ufuncs to appleveldefs
snus_mumrik
noreply at buildbot.pypy.org
Fri Sep 2 14:46:04 CEST 2011
Author: Ilya Osadchiy <osadchiy.ilya at gmail.com>
Branch: numpy-comparison
Changeset: r47018:da8ca4cb9579
Date: 2011-09-02 14:13 +0300
http://bitbucket.org/pypy/pypy/changeset/da8ca4cb9579/
Log: Add ufuncs to appleveldefs
diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -38,7 +38,13 @@
("sin", "sin"),
("subtract", "subtract"),
("tan", "tan"),
- ("equal", "equal")
+ ("equal", "equal"),
+ ("equal", "equal"),
+ ("not_equal", "not_equal"),
+ ("less", "less"),
+ ("less_equal", "less_equal"),
+ ("greater", "greater"),
+ ("greater_equal", "greater_equal"),
]:
interpleveldefs[exposed] = "interp_ufuncs.get(space).%s" % impl
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -561,6 +561,7 @@
from numpy import array, dtype
a = array(range(5))
b = array(range(5), dtype=float)
+ c = array(reversed(range(5)))
for func in [
lambda x, y: x == y,
lambda x, y: x != y,
@@ -585,6 +586,14 @@
assert _3b.dtype is dtype(bool)
for i in xrange(5):
assert _3b[i] == (True if func(3, b[i]) else False)
+ _ac = func (a, c)
+ assert _ac.dtype is dtype(bool)
+ for i in xrange(5):
+ assert _ac[i] == (True if func(a[i], c[i]) else False)
+ _bc = func (b, c)
+ assert _bc.dtype is dtype(bool)
+ for i in xrange(5):
+ assert _bc[i] == (True if func(b[i], c[i]) else False)
class AppTestSupport(object):
def setup_class(cls):
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -299,13 +299,35 @@
assert math.isnan(b[0])
def test_comparison(self):
- from numpy import array, dtype, equal
- assert equal(3, 3) is True
- assert equal(3, 4) is False
- assert equal(3.0, 3.0) is True
- assert equal(3.0, 3.5) is False
- assert equal(3.0, 3) is True
- assert equal(3.0, 4) is False
+ from numpy import (
+ equal,
+ not_equal,
+ less,
+ less_equal,
+ greater,
+ greater_equal,
+ )
+ for (ufunc, func) in [
+ (equal, lambda x, y: x == y),
+ (not_equal, lambda x, y: x != y),
+ (less, lambda x, y: x < y),
+ (less_equal, lambda x, y: x <= y),
+ (greater, lambda x, y: x > y),
+ (greater_equal, lambda x, y: x >= y),
+ ]:
+ for a, b in [
+ (3, 3),
+ (3, 4),
+ (4, 3),
+ (3.0, 3.0),
+ (3.0, 3.5),
+ (3.5, 3.0),
+ (3.0, 3),
+ (3, 3.0),
+ (3.5, 3),
+ (3, 3.5),
+ ]:
+ assert ufunc(a, b) is (True if func(a, b) else False)
def test_reduce_errors(self):
from numpy import sin, add
More information about the pypy-commit
mailing list