Author: Justin Peel <notmuchtot...@gmail.com> Branch: numpy-ufuncs Changeset: r45708:02090c007d03 Date: 2011-07-18 00:51 -0600 http://bitbucket.org/pypy/pypy/changeset/02090c007d03/
Log: added ufuncs add, divide, multiply, subtract 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 @@ -15,14 +15,19 @@ # ufuncs 'abs': 'interp_ufuncs.absolute', 'absolute': 'interp_ufuncs.absolute', + 'add': 'interp_ufuncs.add', 'copysign': 'interp_ufuncs.copysign', + 'divide': 'interp_ufuncs.divide', 'exp': 'interp_ufuncs.exp', + 'fabs': 'interp_ufuncs.fabs', 'floor': 'interp_ufuncs.floor', 'maximum': 'interp_ufuncs.maximum', 'minimum': 'interp_ufuncs.minimum', + 'multiply': 'interp_ufuncs.multiply', 'negative': 'interp_ufuncs.negative', 'reciprocal': 'interp_ufuncs.reciprocal', 'sign': 'interp_ufuncs.sign', + 'subtract': 'interp_ufuncs.subtract', } 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 @@ -37,9 +37,17 @@ return abs(value) @ufunc2 +def add(lvalue, rvalue): + return lvalue + rvalue + +@ufunc2 def copysign(lvalue, rvalue): return rfloat.copysign(lvalue, rvalue) +@ufunc2 +def divide(lvalue, rvalue): + return lvalue / rvalue + @ufunc def exp(value): try: @@ -47,6 +55,10 @@ except OverflowError: return rfloat.INFINITY +@ufunc +def fabs(value): + return math.fabs(value) + @ufunc2 def maximum(lvalue, rvalue): return max(lvalue, rvalue) @@ -55,6 +67,10 @@ def minimum(lvalue, rvalue): return min(lvalue, rvalue) +@ufunc2 +def multiply(lvalue, rvalue): + return lvalue * rvalue + @ufunc def negative(value): return -value @@ -65,6 +81,10 @@ return rfloat.copysign(rfloat.INFINITY, value) return 1.0 / value +@ufunc2 +def subtract(lvalue, rvalue): + return lvalue - rvalue + @ufunc def floor(value): return math.floor(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 @@ -65,6 +65,33 @@ for i in range(3): assert b[i] == abs(a[i]) + def test_add(self): + from numpy import array, add + + a = array([-5.0, -0.0, 1.0]) + b = array([ 3.0, -2.0,-3.0]) + c = add(a, b) + for i in range(3): + assert c[i] == a[i] + b[i] + + def test_divide(self): + from numpy import array, divide + + a = array([-5.0, -0.0, 1.0]) + b = array([ 3.0, -2.0,-3.0]) + c = divide(a, b) + for i in range(3): + assert c[i] == a[i] / b[i] + + def test_fabs(self): + from numpy import array, fabs + from math import fabs as math_fabs + + a = array([-5.0, -0.0, 1.0]) + b = fabs(a) + for i in range(3): + assert b[i] == math_fabs(a[i]) + def test_minimum(self): from numpy import array, minimum @@ -83,6 +110,15 @@ for i in range(3): assert c[i] == max(a[i], b[i]) + def test_multiply(self): + from numpy import array, multiply + + a = array([-5.0, -0.0, 1.0]) + b = array([ 3.0, -2.0,-3.0]) + c = multiply(a, b) + for i in range(3): + assert c[i] == a[i] * b[i] + def test_sign(self): from numpy import array, sign @@ -101,6 +137,15 @@ for i in range(4): assert b[i] == reference[i] + def test_subtract(self): + from numpy import array, subtract + + a = array([-5.0, -0.0, 1.0]) + b = array([ 3.0, -2.0,-3.0]) + c = subtract(a, b) + for i in range(3): + assert c[i] == a[i] - b[i] + def test_floor(self): from numpy import array, floor _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit