[pypy-commit] pypy default: put all the numpy constants in one place
alex_gaynor
noreply at buildbot.pypy.org
Thu Feb 9 03:09:47 CET 2012
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r52261:b15db1836bfa
Date: 2012-02-08 21:07 -0500
http://bitbucket.org/pypy/pypy/changeset/b15db1836bfa/
Log: put all the numpy constants in one place
diff --git a/lib_pypy/numpypy/core/numeric.py b/lib_pypy/numpypy/core/numeric.py
--- a/lib_pypy/numpypy/core/numeric.py
+++ b/lib_pypy/numpypy/core/numeric.py
@@ -1,6 +1,7 @@
from _numpypy import array, ndarray, int_, float_, bool_ #, complex_# , longlong
from _numpypy import concatenate
+import math
import sys
import _numpypy as multiarray # ARGH
from numpypy.core.arrayprint import array2string
@@ -311,6 +312,11 @@
little_endian = (sys.byteorder == 'little')
Inf = inf = infty = Infinity = PINF = float('inf')
+NINF = float('-inf')
+PZERO = 0.0
+NZERO = -0.0
nan = NaN = NAN = float('nan')
False_ = bool_(False)
True_ = bool_(True)
+e = math.e
+pi = math.pi
\ No newline at end of file
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,7 +31,7 @@
'concatenate': 'interp_numarray.concatenate',
'set_string_function': 'appbridge.set_string_function',
-
+
'count_reduce_items': 'interp_numarray.count_reduce_items',
'True_': 'types.Bool.True',
@@ -111,8 +111,5 @@
'min': 'app_numpy.min',
'identity': 'app_numpy.identity',
'max': 'app_numpy.max',
- 'inf': 'app_numpy.inf',
- 'e': 'app_numpy.e',
- 'pi': 'app_numpy.pi',
'arange': 'app_numpy.arange',
}
diff --git a/pypy/module/micronumpy/app_numpy.py b/pypy/module/micronumpy/app_numpy.py
--- a/pypy/module/micronumpy/app_numpy.py
+++ b/pypy/module/micronumpy/app_numpy.py
@@ -3,11 +3,6 @@
import _numpypy
-inf = float("inf")
-e = math.e
-pi = math.pi
-
-
def average(a):
# This implements a weighted average, for now we don't implement the
# weighting, just the average part!
@@ -59,7 +54,7 @@
if not hasattr(a, "max"):
a = _numpypy.array(a)
return a.max(axis)
-
+
def arange(start, stop=None, step=1, dtype=None):
'''arange([start], stop[, step], dtype=None)
Generate values in the half-interval [start, stop).
diff --git a/pypy/module/micronumpy/test/test_module.py b/pypy/module/micronumpy/test/test_module.py
--- a/pypy/module/micronumpy/test/test_module.py
+++ b/pypy/module/micronumpy/test/test_module.py
@@ -21,13 +21,3 @@
from _numpypy import array, max
assert max(range(10)) == 9
assert max(array(range(10))) == 9
-
- def test_constants(self):
- import math
- from _numpypy import inf, e, pi
- assert type(inf) is float
- assert inf == float("inf")
- assert e == math.e
- assert type(e) is float
- assert pi == math.pi
- assert type(pi) is float
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -579,7 +579,7 @@
def test_div(self):
from math import isnan
- from _numpypy import array, dtype, inf
+ from _numpypy import array, dtype
a = array(range(1, 6))
b = a / a
@@ -600,15 +600,15 @@
a = array([-1.0, 0.0, 1.0])
b = array([0.0, 0.0, 0.0])
c = a / b
- assert c[0] == -inf
+ assert c[0] == float('-inf')
assert isnan(c[1])
- assert c[2] == inf
+ assert c[2] == float('inf')
b = array([-0.0, -0.0, -0.0])
c = a / b
- assert c[0] == inf
+ assert c[0] == float('inf')
assert isnan(c[1])
- assert c[2] == -inf
+ assert c[2] == float('-inf')
def test_div_other(self):
from _numpypy import array
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
@@ -312,9 +312,9 @@
def test_arcsinh(self):
import math
- from _numpypy import arcsinh, inf
+ from _numpypy import arcsinh
- for v in [inf, -inf, 1.0, math.e]:
+ for v in [float('inf'), float('-inf'), 1.0, math.e]:
assert math.asinh(v) == arcsinh(v)
assert math.isnan(arcsinh(float("nan")))
@@ -367,7 +367,7 @@
b = add.reduce(a, 0, keepdims=True)
assert b.shape == (1, 4)
assert (add.reduce(a, 0, keepdims=True) == [12, 15, 18, 21]).all()
-
+
def test_bitwise(self):
from _numpypy import bitwise_and, bitwise_or, arange, array
@@ -416,7 +416,7 @@
assert count_reduce_items(a) == 24
assert count_reduce_items(a, 1) == 3
assert count_reduce_items(a, (1, 2)) == 3 * 4
-
+
def test_true_divide(self):
from _numpypy import arange, array, true_divide
assert (true_divide(arange(3), array([2, 2, 2])) == array([0, 0.5, 1])).all()
More information about the pypy-commit
mailing list