[pypy-commit] pypy default: (mattip) merge numpypy-ufuncs, adding ceil
fijal
noreply at buildbot.pypy.org
Thu Jan 19 18:24:24 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r51498:7745b3fcec92
Date: 2012-01-19 19:23 +0200
http://bitbucket.org/pypy/pypy/changeset/7745b3fcec92/
Log: (mattip) merge numpypy-ufuncs, adding ceil
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
@@ -70,6 +70,7 @@
("exp", "exp"),
("fabs", "fabs"),
("floor", "floor"),
+ ("ceil", "ceil"),
("greater", "greater"),
("greater_equal", "greater_equal"),
("less", "less"),
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
@@ -449,6 +449,7 @@
("fabs", "fabs", 1, {"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}),
('sqrt', 'sqrt', 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
@@ -190,14 +190,24 @@
for i in range(3):
assert c[i] == a[i] - b[i]
- def test_floor(self):
- from _numpypy import array, floor
-
- reference = [-2.0, -1.0, 0.0, 1.0, 1.0]
- a = array([-1.4, -1.0, 0.0, 1.0, 1.4])
+ def test_floorceil(self):
+ from _numpypy import array, floor, ceil
+ import math
+ reference = [-2.0, -2.0, -1.0, 0.0, 1.0, 1.0, 0]
+ a = array([-1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5])
b = floor(a)
for i in range(5):
assert b[i] == reference[i]
+ reference = [-1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 1.0]
+ a = array([-1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5])
+ b = ceil(a)
+ assert (reference == b).all()
+ inf = float("inf")
+ data = [1.5, 2.9999, -1.999, inf]
+ results = [math.floor(x) for x in data]
+ assert (floor(data) == results).all()
+ results = [math.ceil(x) for x in data]
+ assert (ceil(data) == results).all()
def test_copysign(self):
from _numpypy import array, copysign
@@ -238,7 +248,7 @@
assert b[i] == math.sin(a[i])
a = sin(array([True, False], dtype=bool))
- assert abs(a[0] - sin(1)) < 1e-7 # a[0] will be less precise
+ assert abs(a[0] - sin(1)) < 1e-7 # a[0] will be less precise
assert a[1] == 0.0
def test_cos(self):
@@ -259,7 +269,6 @@
for i in range(len(a)):
assert b[i] == math.tan(a[i])
-
def test_arcsin(self):
import math
from _numpypy import array, arcsin
@@ -283,7 +292,6 @@
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:
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
@@ -374,6 +374,10 @@
return math.floor(v)
@simple_unary_op
+ def ceil(self, v):
+ return math.ceil(v)
+
+ @simple_unary_op
def exp(self, v):
try:
return math.exp(v)
@@ -436,4 +440,4 @@
class Float64(BaseType, Float):
T = rffi.DOUBLE
BoxType = interp_boxes.W_Float64Box
- format_code = "d"
\ No newline at end of file
+ format_code = "d"
More information about the pypy-commit
mailing list