[pypy-commit] pypy numpy-ufuncs2: Add fmod
taavi_burns
noreply at buildbot.pypy.org
Tue Mar 13 23:16:32 CET 2012
Author: Taavi Burns <taavi.burns at gmail.com>
Branch: numpy-ufuncs2
Changeset: r53498:3174a08c68c1
Date: 2012-03-13 15:01 -0700
http://bitbucket.org/pypy/pypy/changeset/3174a08c68c1/
Log: Add fmod
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
@@ -81,6 +81,7 @@
("exp2", "exp2"),
("expm1", "expm1"),
("fabs", "fabs"),
+ ("fmod", "fmod"),
("floor", "floor"),
("ceil", "ceil"),
("greater", "greater"),
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -428,6 +428,7 @@
("reciprocal", "reciprocal", 1),
("fabs", "fabs", 1, {"promote_to_float": True}),
+ ("fmod", "fmod", 2, {"promote_to_float": True}),
("floor", "floor", 1, {"promote_to_float": True}),
("ceil", "ceil", 1, {"promote_to_float": True}),
("exp", "exp", 1, {"promote_to_float": True}),
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
@@ -125,12 +125,25 @@
def test_fabs(self):
from _numpypy import array, fabs
- from math import fabs as math_fabs
+ from math import fabs as math_fabs, isnan
a = array([-5.0, -0.0, 1.0])
b = fabs(a)
for i in range(3):
assert b[i] == math_fabs(a[i])
+ assert fabs(float('inf')) == float('inf')
+ assert fabs(float('-inf')) == float('inf')
+ assert isnan(fabs(float('nan')))
+
+ def test_fmod(self):
+ from _numpypy import fmod
+ import math
+
+ assert fmod(-1e-100, 1e100) == -1e-100
+ assert fmod(3, float('inf')) == 3
+ assert (fmod([-3, -2, -1, 1, 2, 3], 2) == [-1, 0, -1, 1, 0, 1]).all()
+ for v in [float('inf'), float('-inf'), float('nan'), float('-nan')]:
+ assert math.isnan(fmod(v, 2))
def test_minimum(self):
from _numpypy import array, minimum
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -478,6 +478,13 @@
def fabs(self, v):
return math.fabs(v)
+ @simple_binary_op
+ def fmod(self, v1, v2):
+ try:
+ return math.fmod(v1, v2)
+ except ValueError:
+ return rfloat.NAN
+
@simple_unary_op
def reciprocal(self, v):
if v == 0.0:
More information about the pypy-commit
mailing list