[pypy-commit] pypy remove-numpypy: port test_{arrayops, complex, sorting, ufuncs}
bdkearns
noreply at buildbot.pypy.org
Tue Oct 29 21:50:47 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch: remove-numpypy
Changeset: r67706:fb907eaa46f8
Date: 2013-10-29 16:38 -0400
http://bitbucket.org/pypy/pypy/changeset/fb907eaa46f8/
Log: port test_{arrayops,complex,sorting,ufuncs}
diff --git a/pypy/module/micronumpy/test/dummy_module.py b/pypy/module/micronumpy/test/dummy_module.py
--- a/pypy/module/micronumpy/test/dummy_module.py
+++ b/pypy/module/micronumpy/test/dummy_module.py
@@ -1,2 +1,4 @@
from _numpypy.multiarray import *
from _numpypy.umath import *
+
+ufunc = type(sin)
diff --git a/pypy/module/micronumpy/test/test_arrayops.py b/pypy/module/micronumpy/test/test_arrayops.py
--- a/pypy/module/micronumpy/test/test_arrayops.py
+++ b/pypy/module/micronumpy/test/test_arrayops.py
@@ -85,12 +85,10 @@
assert c == 12.0
def test_choose_basic(self):
- from numpypy import array, choose
+ from numpypy import array
a, b, c = array([1, 2, 3]), array([4, 5, 6]), array([7, 8, 9])
r = array([2, 1, 0]).choose([a, b, c])
assert (r == [7, 5, 3]).all()
- r = choose(array([2, 1, 0]), [a, b, c])
- assert (r == [7, 5, 3]).all()
def test_choose_broadcast(self):
from numpypy import array
diff --git a/pypy/module/micronumpy/test/test_complex.py b/pypy/module/micronumpy/test/test_complex.py
--- a/pypy/module/micronumpy/test/test_complex.py
+++ b/pypy/module/micronumpy/test/test_complex.py
@@ -130,9 +130,9 @@
cls.w_c_pow = cls.space.wrap(interp2app(cls_c_pow))
def test_fabs(self):
- from numpypy import fabs, complex128
+ from numpypy import fabs, dtype
- a = complex128(complex(-5., 5.))
+ a = dtype('complex128').type(complex(-5., 5.))
raises(TypeError, fabs, a)
def test_fmax(self):
@@ -194,7 +194,7 @@
raises(TypeError, signbit, complex(1,1))
def test_reciprocal(self):
- from numpypy import array, reciprocal, complex64, complex128, clongdouble
+ from numpypy import array, reciprocal
inf = float('inf')
nan = float('nan')
#complex
@@ -209,7 +209,7 @@
complex(-r, i),
-0j, 0j, cnan,
cnan, cnan, cnan]
- for c, rel_err in ((complex64, 2e-7), (complex128, 2e-15), (clongdouble, 2e-15)):
+ for c, rel_err in (('complex64', 2e-7), ('complex128', 2e-15), ('clongdouble', 2e-15)):
actual = reciprocal(array([orig], dtype=c))
for b, a, e in zip(orig, actual, expected):
assert (a[0].real - e.real) < rel_err
@@ -223,18 +223,19 @@
raises(TypeError, trunc, a)
def test_copysign(self):
- from numpypy import copysign, complex128
+ from numpypy import copysign, dtype
+ complex128 = dtype('complex128').type
a = complex128(complex(-5., 5.))
b = complex128(complex(0., 0.))
raises(TypeError, copysign, a, b)
def test_exp2(self):
- from numpypy import array, exp2, complex128, complex64, clongdouble
+ from numpypy import array, exp2
inf = float('inf')
ninf = -float('inf')
nan = float('nan')
cmpl = complex
- for c, rel_err in ((complex64, 2e-7), (complex128, 2e-15), (clongdouble, 2e-15)):
+ for c, rel_err in (('complex64', 2e-7), ('complex128', 2e-15), ('clongdouble', 2e-15)):
a = [cmpl(-5., 0), cmpl(-5., -5.), cmpl(-5., 5.),
cmpl(0., -5.), cmpl(0., 0.), cmpl(0., 5.),
cmpl(-0., -5.), cmpl(-0., 0.), cmpl(-0., 5.),
@@ -265,12 +266,12 @@
def test_expm1(self):
import math, cmath
- from numpypy import array, expm1, complex128, complex64, clongdouble
+ from numpypy import array, expm1
inf = float('inf')
ninf = -float('inf')
nan = float('nan')
cmpl = complex
- for c, rel_err in ((complex64, 2e-7), (complex128, 2e-15), (clongdouble, 2e-15)):
+ for c, rel_err in (('complex64', 2e-7), ('complex128', 2e-15), ('clongdouble', 2e-15)):
a = [cmpl(-5., 0), cmpl(-5., -5.), cmpl(-5., 5.),
cmpl(0., -5.), cmpl(0., 0.), cmpl(0., 5.),
cmpl(-0., -5.), cmpl(-0., 0.), cmpl(-0., 5.),
@@ -305,14 +306,12 @@
def test_not_complex(self):
from numpypy import (radians, deg2rad, degrees, rad2deg,
- isneginf, isposinf, logaddexp, logaddexp2, fmod,
+ logaddexp, logaddexp2, fmod,
arctan2)
raises(TypeError, radians, complex(90,90))
raises(TypeError, deg2rad, complex(90,90))
raises(TypeError, degrees, complex(90,90))
raises(TypeError, rad2deg, complex(90,90))
- raises(TypeError, isneginf, complex(1, 1))
- raises(TypeError, isposinf, complex(1, 1))
raises(TypeError, logaddexp, complex(1, 1), complex(3, 3))
raises(TypeError, logaddexp2, complex(1, 1), complex(3, 3))
raises(TypeError, arctan2, complex(1, 1), complex(3, 3))
@@ -341,12 +340,12 @@
nan = float('nan')
cmpl = complex
from math import copysign
- from numpypy import power, array, complex128, complex64
+ from numpypy import power, array
# note: in some settings (namely a x86-32 build without the JIT),
# gcc optimizes the code in rlib.rcomplex.c_pow() to not truncate
# the 10-byte values down to 8-byte values. It ends up with more
# imprecision than usual (hence 2e-13 instead of 2e-15).
- for c,rel_err in ((complex128, 2e-13), (complex64, 4e-7)):
+ for c,rel_err in (('complex128', 2e-13), ('complex64', 4e-7)):
a = array([cmpl(-5., 0), cmpl(-5., -5.), cmpl(-5., 5.),
cmpl(0., -5.), cmpl(0., 0.), cmpl(0., 5.),
cmpl(-0., -5.), cmpl(-0., 0.), cmpl(-0., 5.),
@@ -378,11 +377,11 @@
self.rAlmostEqual(t1, t2, rel_err=rel_err, msg=msg)
def test_conjugate(self):
- from numpypy import conj, conjugate, complex128, complex64
+ from numpypy import conj, conjugate, dtype
import numpypy as np
- c0 = complex128(complex(2.5, 0))
- c1 = complex64(complex(1, 2))
+ c0 = dtype('complex128').type(complex(2.5, 0))
+ c1 = dtype('complex64').type(complex(1, 2))
assert conj is conjugate
assert conj(c0) == c0
@@ -395,7 +394,8 @@
assert np.conjugate(1+2j) == 1-2j
- x = np.eye(2) + 1j * np.eye(2)
+ eye2 = np.array([[1, 0], [0, 1]])
+ x = eye2 + 1j * eye2
for a, b in zip(np.conjugate(x), np.array([[ 1.-1.j, 0.-0.j], [ 0.-0.j, 1.-1.j]])):
assert a[0] == b[0]
assert a[1] == b[1]
@@ -403,7 +403,7 @@
def test_logn(self):
import math, cmath
# log and log10 are tested in math (1:1 from rcomplex)
- from numpypy import log2, array, complex128, complex64, log1p
+ from numpypy import log2, array, log1p
inf = float('inf')
ninf = -float('inf')
nan = float('nan')
@@ -418,7 +418,7 @@
cmpl(ninf, ninf), cmpl(5., inf), cmpl(5., ninf),
cmpl(nan, 5.), cmpl(5., nan), cmpl(nan, nan),
]
- for c,rel_err in ((complex128, 2e-15), (complex64, 1e-7)):
+ for c,rel_err in (('complex128', 2e-15), ('complex64', 1e-7)):
b = log2(array(a,dtype=c))
for i in range(len(a)):
try:
@@ -438,7 +438,7 @@
t1 = float(res.imag)
t2 = float(b[i].imag)
self.rAlmostEqual(t1, t2, rel_err=rel_err, msg=msg)
- for c,rel_err in ((complex128, 2e-15), (complex64, 1e-7)):
+ for c,rel_err in (('complex128', 2e-15), ('complex64', 1e-7)):
b = log1p(array(a,dtype=c))
for i in range(len(a)):
try:
@@ -492,9 +492,9 @@
assert c[i] == max(a[i], b[i])
def test_basic(self):
- from numpypy import (complex128, complex64, add, array, dtype,
+ from numpypy import (dtype, add, array, dtype,
subtract as sub, multiply, divide, negative, absolute as abs,
- floor_divide, real, imag, sign, clongdouble)
+ floor_divide, real, imag, sign)
from numpypy import (equal, not_equal, greater, greater_equal, less,
less_equal, isnan)
assert real(4.0) == 4.0
@@ -525,7 +525,8 @@
assert str(a.real) == 'abc'
# numpy imag for flexible types returns self
assert str(a.imag) == 'abc'
- for complex_ in complex64, complex128, clongdouble:
+ for t in 'complex64', 'complex128', 'clongdouble':
+ complex_ = dtype(t).type
O = complex(0, 0)
c0 = complex_(complex(2.5, 0))
c1 = complex_(complex(1, 2))
@@ -614,10 +615,11 @@
import numpypy as np
rAlmostEqual = self.rAlmostEqual
- for complex_, testcases in (
- (np.complex128, self.testcases128),
- #(np.complex64, self.testcases64),
+ for t, testcases in (
+ ('complex128', self.testcases128),
+ #('complex64', self.testcases64),
):
+ complex_ = np.dtype(t).type
for id, fn, ar, ai, er, ei, flags in testcases:
arg = complex_(complex(ar, ai))
expected = (er, ei)
@@ -665,6 +667,6 @@
sys.stderr.write('\n')
def test_complexbox_to_pycomplex(self):
- from numpypy import complex128
- x = complex128(3.4j)
+ from numpypy import dtype
+ x = dtype('complex128').type(3.4j)
assert complex(x) == 3.4j
diff --git a/pypy/module/micronumpy/test/test_sorting.py b/pypy/module/micronumpy/test/test_sorting.py
--- a/pypy/module/micronumpy/test/test_sorting.py
+++ b/pypy/module/micronumpy/test/test_sorting.py
@@ -90,8 +90,9 @@
# test doubles and complex doubles as the logic is the same.
# check doubles
- from numpypy import array, nan, zeros, complex128, arange
+ from numpypy import array, zeros, arange
from math import isnan
+ nan = float('nan')
a = array([nan, 1, 0])
b = a.copy()
b.sort()
@@ -102,7 +103,7 @@
assert (b == [2, 1, 0]).all()
# check complex
- a = zeros(9, dtype=complex128)
+ a = zeros(9, dtype='complex128')
a.real += [nan, nan, nan, 1, 0, 1, 1, 0, 0]
a.imag += [nan, 1, 0, nan, nan, 1, 0, 1, 0]
b = a.copy()
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
@@ -239,7 +239,7 @@
assert math.isnan(true_divide(0, 0))
def test_fabs(self):
- from numpypy import array, fabs, complex128
+ from numpypy import array, fabs
from math import fabs as math_fabs, isnan
a = array([-5.0, -0.0, 1.0])
@@ -332,7 +332,7 @@
assert(multiply.reduce(a) == array([0, 3640, 12320])).all()
def test_rint(self):
- from numpypy import array, complex, rint, isnan
+ from numpypy import array, dtype, rint, isnan
import sys
nnan, nan, inf, ninf = float('-nan'), float('nan'), float('inf'), float('-inf')
@@ -384,7 +384,7 @@
[False, True, True]).all()
def test_reciprocal(self):
- from numpypy import array, reciprocal, complex64, complex128
+ from numpypy import array, reciprocal
inf = float('inf')
nan = float('nan')
@@ -417,7 +417,7 @@
assert c[i] == a[i] - b[i]
def test_floorceiltrunc(self):
- from numpypy import array, floor, ceil, trunc, complex128
+ from numpypy import array, floor, ceil, trunc
import math
ninf, inf = float("-inf"), float("inf")
a = array([ninf, -1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5, inf])
@@ -782,10 +782,11 @@
assert invert(False) == True
def test_shift(self):
- from numpypy import left_shift, right_shift, bool
+ from numpypy import left_shift, right_shift, dtype
assert (left_shift([5, 1], [2, 13]) == [20, 2**13]).all()
assert (right_shift(10, range(5)) == [10, 5, 2, 1, 0]).all()
+ bool_ = dtype('bool').type
assert left_shift(bool(1), 3) == left_shift(1, 3)
assert right_shift(bool(1), 3) == right_shift(1, 3)
@@ -832,11 +833,11 @@
assert (true_divide(arange(3), array([2, 2, 2])) == array([0, 0.5, 1])).all()
def test_isnan_isinf(self):
- from numpypy import isnan, isinf, float64, array
+ from numpypy import isnan, isinf, array, dtype
assert isnan(float('nan'))
assert not isnan(3)
assert not isinf(3)
- assert isnan(float64(float('nan')))
+ assert isnan(dtype('float64').type(float('nan')))
assert not isnan(3)
assert isinf(float('inf'))
assert not isnan(3.5)
@@ -847,39 +848,6 @@
assert (isinf(array([0.2, float('inf'), float('nan')])) == [False, True, False]).all()
assert isinf(array([0.2])).dtype.kind == 'b'
- def test_isposinf_isneginf(self):
- from numpypy import isneginf, isposinf
- assert isposinf(float('inf'))
- assert not isposinf(3)
- assert not isneginf(3)
- assert not isposinf(float('-inf'))
- assert not isposinf(float('nan'))
- assert not isposinf(0)
- assert not isposinf(0.0)
- assert isneginf(float('-inf'))
- assert not isneginf(float('inf'))
- assert not isneginf(float('nan'))
- assert not isneginf(0)
- assert not isneginf(0.0)
-
- def test_isfinite(self):
- from numpypy import isfinite
- inf = float('inf')
- ninf = -float('inf')
- nan = float('nan')
- assert (isfinite([0, 0.0, 1e50, -1e-50]) ==
- [True, True, True, True]).all()
- assert (isfinite([ninf, inf, -nan, nan]) ==
- [False, False, False, False]).all()
- assert (isfinite([1, 2, 3]) == [True, True, True]).all()
-
- a = [complex(0, 0), complex(1e50, -1e-50), complex(inf, 0),
- complex(inf, inf), complex(inf, ninf), complex(0, inf),
- complex(ninf, ninf), complex(nan, 0), complex(0, nan),
- complex(nan, nan)]
- assert (isfinite(a) == [True, True, False, False, False,
- False, False, False, False, False]).all()
-
def test_logical_ops(self):
from numpypy import logical_and, logical_or, logical_xor, logical_not
More information about the pypy-commit
mailing list