[pypy-commit] pypy numpy-exp: (michaelh) Added copysign and exp ufuncs.

alex_gaynor noreply at buildbot.pypy.org
Tue May 17 02:12:24 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-exp
Changeset: r44226:57ed702c161a
Date: 2011-05-16 19:21 -0500
http://bitbucket.org/pypy/pypy/changeset/57ed702c161a/

Log:	(michaelh) Added copysign and exp ufuncs.

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
@@ -11,6 +11,8 @@
 
         # ufuncs
         'absolute': 'interp_ufuncs.absolute',
+        'copysign': 'interp_ufuncs.copysign',
+        'exp': 'interp_ufuncs.exp',
         'maximum': 'interp_ufuncs.maximum',
         'minimum': 'interp_ufuncs.minimum',
         'negative': 'interp_ufuncs.negative',
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
@@ -1,3 +1,5 @@
+import math
+
 from pypy.interpreter.gateway import unwrap_spec
 from pypy.module.micronumpy.interp_numarray import BaseArray, Call1, Call2, Signature
 from pypy.rlib import rfloat
@@ -29,6 +31,14 @@
     return abs(value)
 
 @ufunc2
+def copysign(lvalue, rvalue):
+    return rfloat.copysign(lvalue, rvalue)
+
+ at ufunc
+def exp(value):
+    return math.exp(value)
+
+ at ufunc2
 def maximum(lvalue, rvalue):
     return max(lvalue, rvalue)
 
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
@@ -57,4 +57,23 @@
         a = array([-5.0, 0.0, -0.0, 0.5])
         b = reciprocal(a)
         for i in range(4):
-            assert b[i] == reference[i]
\ No newline at end of file
+            assert b[i] == reference[i]
+
+    def test_copysign(self):
+        from numpy import array, copysign
+
+        reference = [5.0, -0.0, 0.0, -6.0]
+        a = array([-5.0, 0.0, 0.0, 6.0])
+        b = array([5.0, -0.0, 3.0, -6.0])
+        c = copysign(a, b)
+        for i in range(4):
+            assert c[i] == reference[i]
+
+    def test_exp(self):
+        import math
+        from numpy import array, exp
+
+        a = array([-5.0, -0.0, 0.0, float("inf")])
+        b = exp(a)
+        for i in range(4):
+            assert b[i] == math.exp(a[i])
\ No newline at end of file


More information about the pypy-commit mailing list