[pypy-commit] pypy numpy-ufunc-trig: numpy: Added ufuncs for arcsin, arccos, arctan
cgerum
noreply at buildbot.pypy.org
Fri Jul 29 01:57:03 CEST 2011
Author: Christoph Gerum <christoph at gerum.de>
Branch: numpy-ufunc-trig
Changeset: r46074:cf22222905d0
Date: 2011-07-29 00:28 +0200
http://bitbucket.org/pypy/pypy/changeset/cf22222905d0/
Log: numpy: Added ufuncs for arcsin, arccos, arctan
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
@@ -31,6 +31,9 @@
'sin': 'interp_ufuncs.sin',
'cos': 'interp_ufuncs.cos',
'tan': 'interp_ufuncs.tan',
+ 'arcsin': 'interp_ufuncs.arcsin',
+ 'arccos': 'interp_ufuncs.arccos',
+ 'arctan': 'interp_ufuncs.arctan',
}
appleveldefs = {
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
@@ -120,3 +120,20 @@
@ufunc2
def mod(lvalue, rvalue):
return math.fmod(lvalue, rvalue)
+
+
+ at ufunc
+def arcsin(value):
+ if value < -1.0 or value > 1.0:
+ return rfloat.NAN
+ return math.asin(value)
+
+ at ufunc
+def arccos(value):
+ if value < -1.0 or value > 1.0:
+ return rfloat.NAN
+ return math.acos(value)
+
+ at ufunc
+def arctan(value):
+ return math.atan(value)
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
@@ -205,3 +205,47 @@
b = tan(a)
for i in range(len(a)):
assert b[i] == math.tan(a[i])
+
+
+ def test_arcsin(self):
+ import math
+ from numpy import array, arcsin
+
+ a = array([-1, -0.5, -0.33, 0, 0.33, 0.5, 1])
+ b = arcsin(a)
+ for i in range(len(a)):
+ assert b[i] == math.asin(a[i])
+
+ a = array([-10, -1.5, -1.01, 1.01, 1.5, 10, float('nan'), float('inf'), float('-inf')])
+ b = arcsin(a)
+ for f in b:
+ assert math.isnan(f)
+
+ def test_arccos(self):
+ import math
+ from numpy import array, arccos
+
+ a = array([-1, -0.5, -0.33, 0, 0.33, 0.5, 1])
+ b = arccos(a)
+ for i in range(len(a)):
+ assert b[i] == math.acos(a[i])
+
+
+ a = array([-10, -1.5, -1.01, 1.01, 1.5, 10, float('nan'), float('inf'), float('-inf')])
+ b = arccos(a)
+ for f in b:
+ assert math.isnan(f)
+
+ def test_arctan(self):
+ import math
+ from numpy import array, arctan
+
+ a = array([-3, -2, -1, 0, 1, 2, 3])
+ b = arctan(a)
+ for i in range(len(a)):
+ assert b[i] == math.atan(a[i])
+
+ a = array([float('nan')])
+ b = arctan(a)
+ assert math.isnan(b[0])
+
More information about the pypy-commit
mailing list