[pypy-commit] pypy cleanup-numpypy-namespace: update numpypy tests for submodules
bdkearns
noreply at buildbot.pypy.org
Mon Feb 25 14:12:18 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch: cleanup-numpypy-namespace
Changeset: r61757:a3aa452cf995
Date: 2013-02-25 07:29 -0500
http://bitbucket.org/pypy/pypy/changeset/a3aa452cf995/
Log: update numpypy tests for submodules
diff too long, truncating to 2000 out of 3297 lines
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
@@ -3,26 +3,26 @@
class AppTestNumSupport(BaseNumpyAppTest):
def test_where(self):
- from _numpypy import where, ones, zeros, array
+ from numpypy import where, ones, zeros, array
a = [1, 2, 3, 0, -3]
a = where(array(a) > 0, ones(5), zeros(5))
assert (a == [1, 1, 1, 0, 0]).all()
def test_where_differing_dtypes(self):
- from _numpypy import array, ones, zeros, where
+ from numpypy import array, ones, zeros, where
a = [1, 2, 3, 0, -3]
a = where(array(a) > 0, ones(5, dtype=int), zeros(5, dtype=float))
assert (a == [1, 1, 1, 0, 0]).all()
def test_where_broadcast(self):
- from _numpypy import array, where
+ from numpypy import array, where
a = where(array([[1, 2, 3], [4, 5, 6]]) > 3, [1, 1, 1], 2)
assert (a == [[2, 2, 2], [1, 1, 1]]).all()
a = where(True, [1, 1, 1], 2)
assert (a == [1, 1, 1]).all()
def test_where_errors(self):
- from _numpypy import where, array
+ from numpypy import where, array
raises(ValueError, "where([1, 2, 3], [3, 4, 5])")
raises(ValueError, "where([1, 2, 3], [3, 4, 5], [6, 7])")
assert where(True, 1, 2) == array(1)
@@ -35,7 +35,7 @@
# xxx
def test_where_invalidates(self):
- from _numpypy import where, ones, zeros, array
+ from numpypy import where, ones, zeros, array
a = array([1, 2, 3, 0, -3])
b = where(a > 0, ones(5), zeros(5))
a[0] = 0
@@ -43,7 +43,7 @@
def test_dot(self):
- from _numpypy import array, dot, arange
+ from numpypy import array, dot, arange
a = array(range(5))
assert dot(a, a) == 30.0
@@ -74,7 +74,7 @@
assert (dot([[1,2],[3,4]],[5,6]) == [17, 39]).all()
def test_dot_constant(self):
- from _numpypy import array, dot
+ from numpypy import array, dot
a = array(range(5))
b = a.dot(2.5)
for i in xrange(5):
@@ -85,19 +85,19 @@
assert c == 12.0
def test_choose_basic(self):
- from _numpypy import array
+ 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()
def test_choose_broadcast(self):
- from _numpypy import array
+ from numpypy import array
a, b, c = array([1, 2, 3]), [4, 5, 6], 13
r = array([2, 1, 0]).choose([a, b, c])
assert (r == [13, 5, 3]).all()
def test_choose_out(self):
- from _numpypy import array
+ from numpypy import array
a, b, c = array([1, 2, 3]), [4, 5, 6], 13
r = array([2, 1, 0]).choose([a, b, c], out=None)
assert (r == [13, 5, 3]).all()
@@ -107,7 +107,7 @@
assert (a == [13, 5, 3]).all()
def test_choose_modes(self):
- from _numpypy import array
+ from numpypy import array
a, b, c = array([1, 2, 3]), [4, 5, 6], 13
raises(ValueError, "array([3, 1, 0]).choose([a, b, c])")
raises(ValueError, "array([3, 1, 0]).choose([a, b, c], 'raises')")
@@ -119,13 +119,13 @@
assert (r == [4, 5, 3]).all()
def test_choose_dtype(self):
- from _numpypy import array
+ from numpypy import array
a, b, c = array([1.2, 2, 3]), [4, 5, 6], 13
r = array([2, 1, 0]).choose([a, b, c])
assert r.dtype == float
def test_choose_dtype_out(self):
- from _numpypy import array
+ from numpypy import array
a, b, c = array([1, 2, 3]), [4, 5, 6], 13
x = array([0, 0, 0], dtype='i2')
r = array([2, 1, 0]).choose([a, b, c], out=x)
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
@@ -132,13 +132,13 @@
cls.w_c_pow = cls.space.wrap(interp2app(cls_c_pow))
def test_fabs(self):
- from _numpypy import fabs, complex128
+ from numpypy import fabs, complex128
a = complex128(complex(-5., 5.))
raises(TypeError, fabs, a)
def test_fmax(self):
- from _numpypy import fmax, array
+ from numpypy import fmax, array
nnan, nan, inf, ninf = float('-nan'), float('nan'), float('inf'), float('-inf')
a = array((complex(ninf, 10), complex(10, ninf),
complex( inf, 10), complex(10, inf),
@@ -165,7 +165,7 @@
assert (fmax(a, b) == res).all()
def test_fmin(self):
- from _numpypy import fmin, array
+ from numpypy import fmin, array
nnan, nan, inf, ninf = float('-nan'), float('nan'), float('inf'), float('-inf')
a = array((complex(ninf, 10), complex(10, ninf),
complex( inf, 10), complex(10, inf),
@@ -192,14 +192,14 @@
assert (fmin(a, b) == res).all()
def test_signbit(self):
- from _numpypy import signbit
+ from numpypy import signbit
raises(TypeError, signbit, complex(1,1))
def test_reciprocal(self):
- from _numpypy import array, reciprocal, complex64, complex128
+ from numpypy import array, reciprocal, complex64, complex128
c_and_relerr = [(complex64, 2e-7), (complex128, 2e-15)]
try:
- from _numpypy import clongdouble
+ from numpypy import clongdouble
c_and_relerr.append((clongdouble, 2e-30))
except:
pass # no longdouble yet
@@ -224,23 +224,23 @@
assert (a[0].imag - e.imag) < rel_err
def test_floorceiltrunc(self):
- from _numpypy import array, floor, ceil, trunc
+ from numpypy import array, floor, ceil, trunc
a = array([ complex(-1.4, -1.4), complex(-1.5, -1.5)])
raises(TypeError, floor, a)
raises(TypeError, ceil, a)
raises(TypeError, trunc, a)
def test_copysign(self):
- from _numpypy import copysign, complex128
+ from numpypy import copysign, complex128
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
+ from numpypy import array, exp2, complex128, complex64
c_and_relerr = [(complex64, 2e-7), (complex128, 2e-15)]
try:
- from _numpypy import clongdouble
+ from numpypy import clongdouble
c_and_relerr.append((clongdouble, 2e-30))
except:
pass # no longdouble yet
@@ -279,7 +279,7 @@
def test_expm1(self):
import math, cmath
- from _numpypy import array, expm1, complex128, complex64
+ from numpypy import array, expm1, complex128, complex64
inf = float('inf')
ninf = -float('inf')
nan = float('nan')
@@ -318,7 +318,7 @@
self.rAlmostEqual(t1, t2, rel_err=rel_err, msg=msg)
def test_not_complex(self):
- from _numpypy import (radians, deg2rad, degrees, rad2deg,
+ from numpypy import (radians, deg2rad, degrees, rad2deg,
isneginf, isposinf, logaddexp, logaddexp2, fmod,
arctan2)
raises(TypeError, radians, complex(90,90))
@@ -333,7 +333,7 @@
raises (TypeError, fmod, complex(90,90), 3)
def test_isnan_isinf(self):
- from _numpypy import isnan, isinf, array
+ from numpypy import isnan, isinf, array
assert (isnan(array([0.2+2j, complex(float('inf'),0),
complex(0,float('inf')), complex(0,float('nan')),
complex(float('nan'), 0)], dtype=complex)) == \
@@ -346,7 +346,7 @@
def test_square(self):
- from _numpypy import square
+ from numpypy import square
assert square(complex(3, 4)) == complex(3,4) * complex(3, 4)
def test_power_complex(self):
@@ -355,7 +355,7 @@
nan = float('nan')
cmpl = complex
from math import copysign
- from _numpypy import power, array, complex128, complex64
+ from numpypy import power, array, complex128, complex64
# 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
@@ -392,7 +392,7 @@
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, complex128, complex64
import numpypy as np
c0 = complex128(complex(2.5, 0))
@@ -416,7 +416,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, complex128, complex64, log1p
inf = float('inf')
ninf = -float('inf')
nan = float('nan')
@@ -473,7 +473,7 @@
self.rAlmostEqual(t1, t2, rel_err=rel_err, msg=msg)
def test_logical_ops(self):
- from _numpypy import logical_and, logical_or, logical_xor, logical_not
+ from numpypy import logical_and, logical_or, logical_xor, logical_not
c1 = complex(1, 1)
c3 = complex(3, 0)
@@ -487,7 +487,7 @@
assert (logical_not([c1, c0]) == [False, True]).all()
def test_minimum(self):
- from _numpypy import array, minimum
+ from numpypy import array, minimum
a = array([-5.0+5j, -5.0-5j, -0.0-10j, 1.0+10j])
b = array([ 3.0+10.0j, 3.0, -2.0+2.0j, -3.0+4.0j])
@@ -496,7 +496,7 @@
assert c[i] == min(a[i], b[i])
def test_maximum(self):
- from _numpypy import array, maximum
+ from numpypy import array, maximum
a = array([-5.0+5j, -5.0-5j, -0.0-10j, 1.0+10j])
b = array([ 3.0+10.0j, 3.0, -2.0+2.0j, -3.0+4.0j])
@@ -505,14 +505,14 @@
assert c[i] == max(a[i], b[i])
def test_basic(self):
- from _numpypy import (complex128, complex64, add, array, dtype,
+ from numpypy import (complex128, complex64, add, array, dtype,
subtract as sub, multiply, divide, negative, absolute as abs,
floor_divide, real, imag, sign)
- from _numpypy import (equal, not_equal, greater, greater_equal, less,
+ from numpypy import (equal, not_equal, greater, greater_equal, less,
less_equal, isnan)
complex_dtypes = [complex64, complex128]
try:
- from _numpypy import clongfloat
+ from numpypy import clongfloat
complex_dtypes.append(clongfloat)
except:
pass
@@ -588,15 +588,15 @@
inf_c = complex_(complex(float('inf'), 0.))
assert repr(abs(inf_c)) == 'inf'
assert repr(abs(complex(float('nan'), float('nan')))) == 'nan'
- # numpy actually raises an AttributeError,
- # but _numpypy raises a TypeError
+ # numpy actually raises an AttributeError,
+ # but numpypy raises a TypeError
raises((TypeError, AttributeError), 'c2.real = 10.')
raises((TypeError, AttributeError), 'c2.imag = 10.')
assert(real(c2) == 3.0)
assert(imag(c2) == 4.0)
def test_conj(self):
- from _numpypy import array
+ from numpypy import array
a = array([1 + 2j, 1 - 2j])
assert (a.conj() == [1 - 2j, 1 + 2j]).all()
@@ -605,7 +605,7 @@
if self.isWindows:
skip('windows does not support c99 complex')
import sys
- import _numpypy as np
+ import numpypy as np
rAlmostEqual = self.rAlmostEqual
for complex_, abs_err, testcases in (\
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -17,7 +17,7 @@
class AppTestDtypes(BaseAppTestDtypes):
def test_dtype(self):
- from _numpypy import dtype
+ from numpypy import dtype
d = dtype('?')
assert d.num == 0
@@ -36,7 +36,7 @@
raises(KeyError, 'dtype(int)["asdasd"]')
def test_dtype_eq(self):
- from _numpypy import dtype
+ from numpypy import dtype
assert dtype("int8") == "int8"
assert "int8" == dtype("int8")
@@ -44,7 +44,7 @@
assert dtype(bool) == bool
def test_dtype_with_types(self):
- from _numpypy import dtype
+ from numpypy import dtype
assert dtype(bool).num == 0
if self.ptr_size == 4:
@@ -66,13 +66,13 @@
assert dtype(float).num == 12
def test_array_dtype_attr(self):
- from _numpypy import array, dtype
+ from numpypy import array, dtype
a = array(range(5), long)
assert a.dtype is dtype(long)
def test_repr_str(self):
- from _numpypy import dtype
+ from numpypy import dtype
assert '.dtype' in repr(dtype)
d = dtype('?')
@@ -80,8 +80,7 @@
assert str(d) == "bool"
def test_bool_array(self):
- from _numpypy import array
- from numpypy import False_, True_
+ from numpypy import array, False_, True_
a = array([0, 1, 2, 2.5], dtype='?')
assert a[0] is False_
@@ -89,8 +88,7 @@
assert a[i] is True_
def test_copy_array_with_dtype(self):
- from _numpypy import array, longlong
- from numpypy import False_
+ from numpypy import array, longlong, False_
a = array([0, 1, 2, 3], dtype=long)
# int on 64-bit, long in 32-bit
@@ -104,37 +102,35 @@
assert b[0] is False_
def test_zeros_bool(self):
- from _numpypy import zeros
- from numpypy import False_
+ from numpypy import zeros, False_
a = zeros(10, dtype=bool)
for i in range(10):
assert a[i] is False_
def test_ones_bool(self):
- from _numpypy import ones
- from numpypy import True_
+ from numpypy import ones, True_
a = ones(10, dtype=bool)
for i in range(10):
assert a[i] is True_
def test_zeros_long(self):
- from _numpypy import zeros, longlong
+ from numpypy import zeros, longlong
a = zeros(10, dtype=long)
for i in range(10):
assert isinstance(a[i], longlong)
assert a[1] == 0
def test_ones_long(self):
- from _numpypy import ones, longlong
+ from numpypy import ones, longlong
a = ones(10, dtype=long)
for i in range(10):
assert isinstance(a[i], longlong)
assert a[1] == 1
def test_overflow(self):
- from _numpypy import array, dtype
+ from numpypy import array, dtype
assert array([128], 'b')[0] == -128
assert array([256], 'B')[0] == 0
assert array([32768], 'h')[0] == -32768
@@ -146,7 +142,7 @@
raises(OverflowError, "array([2**64], 'Q')")
def test_bool_binop_types(self):
- from _numpypy import array, dtype
+ from numpypy import array, dtype
types = [
'?', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd',
'e'
@@ -156,7 +152,7 @@
assert (a + array([0], t)).dtype is dtype(t)
def test_binop_types(self):
- from _numpypy import array, dtype
+ from numpypy import array, dtype
tests = [('b','B','h'), ('b','h','h'), ('b','H','i'), ('b','i','i'),
('b','l','l'), ('b','q','q'), ('b','Q','d'), ('B','h','h'),
('B','H','H'), ('B','i','i'), ('B','I','I'), ('B','l','l'),
@@ -180,7 +176,7 @@
assert (d1, d2) == (d1, d2) and d3 is dtype(dout)
def test_add_int8(self):
- from _numpypy import array, dtype
+ from numpypy import array, dtype
a = array(range(5), dtype="int8")
b = a + a
@@ -189,7 +185,7 @@
assert b[i] == i * 2
def test_add_int16(self):
- from _numpypy import array, dtype
+ from numpypy import array, dtype
a = array(range(5), dtype="int16")
b = a + a
@@ -198,7 +194,7 @@
assert b[i] == i * 2
def test_add_uint32(self):
- from _numpypy import array, dtype
+ from numpypy import array, dtype
a = array(range(5), dtype="I")
b = a + a
@@ -207,49 +203,49 @@
assert b[i] == i * 2
def test_shape(self):
- from _numpypy import dtype
+ from numpypy import dtype
assert dtype(long).shape == ()
def test_cant_subclass(self):
- from _numpypy import dtype
+ from numpypy import dtype
# You can't subclass dtype
raises(TypeError, type, "Foo", (dtype,), {})
def test_can_subclass(self):
- import _numpypy
- class xyz(_numpypy.void):
+ import numpypy
+ class xyz(numpypy.void):
pass
assert True
def test_aliases(self):
- from _numpypy import dtype
+ from numpypy import dtype
assert dtype("float") is dtype(float)
def test_index_int8(self):
- from _numpypy import array, int8
+ from numpypy import array, int8
a = array(range(10), dtype=int8)
b = array([0] * 10, dtype=int8)
for idx in b: a[idx] += 1
def test_index_int16(self):
- from _numpypy import array, int16
+ from numpypy import array, int16
a = array(range(10), dtype=int16)
b = array([0] * 10, dtype=int16)
for idx in b: a[idx] += 1
def test_index_int32(self):
- from _numpypy import array, int32
+ from numpypy import array, int32
a = array(range(10), dtype=int32)
b = array([0] * 10, dtype=int32)
for idx in b: a[idx] += 1
def test_index_int64(self):
- from _numpypy import array, int64
+ from numpypy import array, int64
a = array(range(10), dtype=int64)
b = array([0] * 10, dtype=int64)
@@ -257,7 +253,7 @@
a[idx] += 1
def test_hash(self):
- import _numpypy as numpy
+ import numpypy as numpy
for tp, value in [
(numpy.int8, 4),
(numpy.int16, 5),
@@ -272,7 +268,7 @@
class AppTestTypes(BaseAppTestDtypes):
def test_abstract_types(self):
- import _numpypy as numpy
+ import numpypy as numpy
raises(TypeError, numpy.generic, 0)
raises(TypeError, numpy.number, 0)
@@ -312,12 +308,12 @@
#assert a.dtype is numpy.dtype('|V4')
def test_new(self):
- import _numpypy as np
+ import numpypy as np
assert np.int_(4) == 4
assert np.float_(3.4) == 3.4
def test_pow(self):
- from _numpypy import int_
+ from numpypy import int_
assert int_(4) ** 2 == 16
def test_bool(self):
@@ -336,7 +332,7 @@
assert numpy.bool_("False") is numpy.True_
def test_int8(self):
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.int8.mro() == [numpy.int8, numpy.signedinteger,
numpy.integer, numpy.number,
@@ -360,7 +356,7 @@
assert numpy.int8('128') == -128
def test_uint8(self):
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.uint8.mro() == [numpy.uint8, numpy.unsignedinteger,
numpy.integer, numpy.number,
@@ -385,7 +381,7 @@
assert numpy.uint8('256') == 0
def test_int16(self):
- import _numpypy as numpy
+ import numpypy as numpy
x = numpy.int16(3)
assert x == 3
@@ -395,7 +391,7 @@
assert numpy.int16('32768') == -32768
def test_uint16(self):
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.uint16(65535) == 65535
assert numpy.uint16(65536) == 0
@@ -404,7 +400,7 @@
def test_int32(self):
import sys
- import _numpypy as numpy
+ import numpypy as numpy
x = numpy.int32(23)
assert x == 23
@@ -420,7 +416,7 @@
def test_uint32(self):
import sys
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.uint32(10) == 10
@@ -431,7 +427,7 @@
assert numpy.uint32('4294967296') == 0
def test_int_(self):
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.int_ is numpy.dtype(int).type
assert numpy.int_.mro() == [numpy.int_, numpy.signedinteger,
@@ -440,7 +436,7 @@
def test_int64(self):
import sys
- import _numpypy as numpy
+ import numpypy as numpy
if sys.maxint == 2 ** 63 -1:
assert numpy.int64.mro() == [numpy.int64, numpy.signedinteger,
@@ -462,7 +458,7 @@
def test_uint64(self):
import sys
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.uint64.mro() == [numpy.uint64, numpy.unsignedinteger,
numpy.integer, numpy.number,
@@ -479,7 +475,7 @@
raises(OverflowError, numpy.uint64(18446744073709551616))
def test_float16(self):
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.float16.mro() == [numpy.float16, numpy.floating,
numpy.inexact, numpy.number,
numpy.generic, object]
@@ -490,7 +486,7 @@
def test_float32(self):
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.float32.mro() == [numpy.float32, numpy.floating,
numpy.inexact, numpy.number,
@@ -501,7 +497,7 @@
raises(ValueError, numpy.float32, '23.2df')
def test_float64(self):
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.float64.mro() == [numpy.float64, numpy.floating,
numpy.inexact, numpy.number,
@@ -518,20 +514,20 @@
raises(ValueError, numpy.float64, '23.2df')
def test_float_None(self):
- import _numpypy as numpy
+ import numpypy as numpy
from math import isnan
assert isnan(numpy.float32(None))
assert isnan(numpy.float64(None))
def test_complex_floating(self):
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.complexfloating.__mro__ == (numpy.complexfloating,
numpy.inexact, numpy.number, numpy.generic, object)
def test_complex_format(self):
import sys
- import _numpypy as numpy
+ import numpypy as numpy
for complex_ in (numpy.complex128, numpy.complex64,):
for real, imag, should in [
@@ -571,7 +567,7 @@
assert "{:g}".format(numpy.complex_(0.5+1.5j)) == '{:g}'.format(0.5+1.5j)
def test_complex(self):
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.complex_ is numpy.complex128
assert numpy.complex64.__mro__ == (numpy.complex64,
@@ -589,7 +585,7 @@
assert d.char == 'F'
def test_subclass_type(self):
- import _numpypy as numpy
+ import numpypy as numpy
class X(numpy.float64):
def m(self):
@@ -600,12 +596,12 @@
assert b.m() == 12
def test_long_as_index(self):
- from _numpypy import int_, float64
+ from numpypy import int_, float64
assert (1, 2, 3)[int_(1)] == 2
raises(TypeError, lambda: (1, 2, 3)[float64(1)])
def test_int(self):
- from _numpypy import int32, int64, int_
+ from numpypy import int32, int64, int_
import sys
assert issubclass(int_, int)
if sys.maxint == (1<<31) - 1:
@@ -616,7 +612,7 @@
assert int_ is int64
def test_various_types(self):
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.int16 is numpy.short
assert numpy.int8 is numpy.byte
@@ -629,7 +625,7 @@
assert numpy.uintp is numpy.uint64
def test_mro(self):
- import _numpypy as numpy
+ import numpypy as numpy
assert numpy.int16.__mro__ == (numpy.int16, numpy.signedinteger,
numpy.integer, numpy.number,
@@ -638,8 +634,7 @@
def test_operators(self):
from operator import truediv
- from _numpypy import float64, int_
- from numpypy import True_, False_
+ from numpypy import float64, int_, True_, False_
assert 5 / int_(2) == int_(2)
assert truediv(int_(3), int_(2)) == float64(1.5)
assert truediv(3, int_(2)) == float64(1.5)
@@ -664,7 +659,7 @@
raises(TypeError, lambda: float64(3) & 1)
def test_alternate_constructs(self):
- from _numpypy import dtype
+ from numpypy import dtype
nnp = self.non_native_prefix
byteorder = self.native_prefix
assert dtype('i8') == dtype(byteorder + 'i8') == dtype('=i8') # XXX should be equal == dtype(long)
@@ -674,23 +669,23 @@
assert dtype(byteorder + 'i8').byteorder == '='
def test_intp(self):
- from _numpypy import dtype
+ from numpypy import dtype
assert dtype('p') == dtype('intp')
assert dtype('P') == dtype('uintp')
def test_alignment(self):
- from _numpypy import dtype
+ from numpypy import dtype
assert dtype('i4').alignment == 4
class AppTestStrUnicodeDtypes(BaseNumpyAppTest):
def test_str_unicode(self):
- from _numpypy import str_, unicode_, character, flexible, generic
+ from numpypy import str_, unicode_, character, flexible, generic
assert str_.mro() == [str_, str, basestring, character, flexible, generic, object]
assert unicode_.mro() == [unicode_, unicode, basestring, character, flexible, generic, object]
def test_str_dtype(self):
- from _numpypy import dtype, str_
+ from numpypy import dtype, str_
raises(TypeError, "dtype('Sx')")
d = dtype('S8')
@@ -702,7 +697,7 @@
assert d.num == 18
def test_unicode_dtype(self):
- from _numpypy import dtype, unicode_
+ from numpypy import dtype, unicode_
raises(TypeError, "dtype('Ux')")
d = dtype('U8')
@@ -714,16 +709,16 @@
assert d.num == 19
def test_string_boxes(self):
- from _numpypy import str_
+ from numpypy import str_
assert isinstance(str_(3), str_)
def test_unicode_boxes(self):
- from _numpypy import unicode_
+ from numpypy import unicode_
assert isinstance(unicode_(3), unicode)
class AppTestRecordDtypes(BaseNumpyAppTest):
def test_create(self):
- from _numpypy import dtype, void
+ from numpypy import dtype, void
raises(ValueError, "dtype([('x', int), ('x', float)])")
d = dtype([("x", "int32"), ("y", "int32"), ("z", "int32"), ("value", float)])
@@ -742,7 +737,7 @@
def test_create_from_dict(self):
skip("not yet")
- from _numpypy import dtype
+ from numpypy import dtype
d = dtype({'names': ['a', 'b', 'c'],
})
@@ -766,7 +761,7 @@
cls.w_check_non_native = cls.space.wrap(interp2app(check_non_native))
def test_non_native(self):
- from _numpypy import array
+ from numpypy import array
a = array([1, 2, 3], dtype=self.non_native_prefix + 'i2')
assert a[0] == 1
assert (a + a)[1] == 4
@@ -788,7 +783,8 @@
BaseNumpyAppTest.setup_class.im_func(cls)
def test_typeinfo(self):
- from _numpypy import typeinfo, void, number, int64, bool_
+ from numpypy import void, number, int64, bool_
+ from numpypy.core.multiarray import typeinfo
assert typeinfo['Number'] == number
assert typeinfo['LONGLONG'] == ('q', 9, 64, 8, 9223372036854775807L, -9223372036854775808L, int64)
assert typeinfo['VOID'] == ('V', 20, 0, 1, void)
@@ -804,11 +800,11 @@
BaseNumpyAppTest.setup_class.im_func(cls)
def test_nolongfloat(self):
- import _numpypy
- from _numpypy import dtype
- assert not getattr(_numpypy, 'longdouble', False)
- assert not getattr(_numpypy, 'float128', False)
- assert not getattr(_numpypy, 'float96', False)
+ import numpypy
+ from numpypy import dtype
+ assert not getattr(numpypy, 'longdouble', False)
+ assert not getattr(numpypy, 'float128', False)
+ assert not getattr(numpypy, 'float96', False)
raises(TypeError, dtype, 'longdouble')
raises(TypeError, dtype, 'clongdouble')
raises(TypeError, dtype, 'longfloat')
@@ -825,7 +821,7 @@
BaseNumpyAppTest.setup_class.im_func(cls)
def test_longfloat(self):
- import _numpypy as numpy
+ import numpypy as numpy
# it can be float96 or float128
if numpy.longfloat != numpy.float64:
assert numpy.longfloat.mro()[1:] == [numpy.floating,
@@ -838,33 +834,33 @@
raises(ValueError, numpy.longfloat, '23.2df')
def test_dtype_aliases(self):
- from _numpypy import dtype
+ from numpypy import dtype
assert dtype('longfloat').num in (12, 13)
assert dtype('longdouble').num in (12, 13)
assert dtype('clongfloat').num in (15, 16)
assert dtype('clongdouble').num in (15, 16)
def test_bool_binop_types(self):
- from _numpypy import array, dtype
+ from numpypy import array, dtype
types = ['g', 'G']
a = array([True], '?')
for t in types:
assert (a + array([0], t)).dtype is dtype(t)
def test_hash(self):
- import _numpypy as numpy
+ import numpypy as numpy
for tp, value in [
(numpy.longdouble, 4.32),
]:
assert hash(tp(value)) == hash(value)
def test_float_None(self):
- import _numpypy as numpy
+ import numpypy as numpy
from math import isnan
assert isnan(numpy.longdouble(None))
def test_non_native(self):
- from _numpypy import array
+ from numpypy import array
a = array([1, 2, 3], dtype=self.non_native_prefix + 'g') # longdouble
assert a[0] == 1
assert (a + a)[1] == 4
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
@@ -245,7 +245,7 @@
return CustomIntObject(value)
def test_ndarray(self):
- from _numpypy import ndarray, array, dtype
+ from numpypy import ndarray, array, dtype
assert type(ndarray) is type
assert type(array) is not type
@@ -262,24 +262,24 @@
assert a.shape == ()
def test_ndmin(self):
- from _numpypy import array
+ from numpypy import array
arr = array([[[1]]], ndmin=1)
assert arr.shape == (1, 1, 1)
def test_noop_ndmin(self):
- from _numpypy import array
+ from numpypy import array
arr = array([1], ndmin=3)
assert arr.shape == (1, 1, 1)
def test_type(self):
- from _numpypy import array
+ from numpypy import array
ar = array(range(5))
assert type(ar) is type(ar + ar)
def test_ndim(self):
- from _numpypy import array
+ from numpypy import array
x = array(0.2)
assert x.ndim == 0
x = array([1, 2])
@@ -288,12 +288,12 @@
assert x.ndim == 2
x = array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
assert x.ndim == 3
- # numpy actually raises an AttributeError, but _numpypy raises an
+ # numpy actually raises an AttributeError, but numpypy raises an
# TypeError
raises((TypeError, AttributeError), 'x.ndim = 3')
def test_init(self):
- from _numpypy import zeros
+ from numpypy import zeros
a = zeros(15)
# Check that storage was actually zero'd.
assert a[10] == 0.0
@@ -303,7 +303,7 @@
assert zeros(()).shape == ()
def test_size(self):
- from _numpypy import array,arange,cos
+ from numpypy import array,arange,cos
assert array(3).size == 1
a = array([1, 2, 3])
assert a.size == 3
@@ -316,13 +316,13 @@
Test that empty() works.
"""
- from _numpypy import empty
+ from numpypy import empty
a = empty(2)
a[1] = 1.0
assert a[1] == 1.0
def test_ones(self):
- from _numpypy import ones
+ from numpypy import ones
a = ones(3)
assert len(a) == 3
assert a[0] == 1
@@ -331,7 +331,7 @@
assert a[2] == 4
def test_copy(self):
- from _numpypy import arange, array
+ from numpypy import arange, array
a = arange(5)
b = a.copy()
for i in xrange(5):
@@ -357,12 +357,12 @@
assert b[0] == a[0]
def test_iterator_init(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
assert a[3] == 3
def test_getitem(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
raises(IndexError, "a[5]")
a = a + a
@@ -371,14 +371,14 @@
raises(IndexError, "a[-6]")
def test_getitem_float(self):
- from _numpypy import array
+ from numpypy import array
a = array([1, 2, 3, 4])
assert a[1.2] == 2
assert a[1.6] == 2
assert a[-1.2] == 4
def test_getitem_tuple(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
raises(IndexError, "a[(1,2)]")
for i in xrange(5):
@@ -388,20 +388,20 @@
assert a[i] == b[i]
def test_getitem_nd(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(15).reshape(3, 5)
assert a[1, 3] == 8
assert a.T[1, 2] == 11
def test_getitem_obj_index(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(10)
assert a[self.CustomIndexObject(1)] == 1
def test_getitem_obj_prefer_index_to_int(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(10)
@@ -409,14 +409,14 @@
assert a[self.CustomIndexIntObject(0, 1)] == 0
def test_getitem_obj_int(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(10)
assert a[self.CustomIntObject(1)] == 1
def test_setitem(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
a[-1] = 5.0
assert a[4] == 5.0
@@ -424,7 +424,7 @@
raises(IndexError, "a[-6] = 3.0")
def test_setitem_tuple(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
raises(IndexError, "a[(1,2)] = [0,1]")
for i in xrange(5):
@@ -435,7 +435,7 @@
assert a[i] == i
def test_setitem_obj_index(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(10)
@@ -443,7 +443,7 @@
assert a[1] == 100
def test_setitem_obj_prefer_index_to_int(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(10)
@@ -451,7 +451,7 @@
assert a[0] == 100
def test_setitem_obj_int(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(10)
@@ -471,13 +471,13 @@
# numpy will swallow errors in __int__ and __index__ and
# just raise IndexError.
- from _numpypy import arange
+ from numpypy import arange
a = arange(10)
raises(IndexError, "a[ErrorIndex()] == 0")
raises(IndexError, "a[ErrorInt()] == 0")
def test_setslice_array(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = array(range(2))
a[1:4:2] = b
@@ -488,7 +488,7 @@
assert b[1] == 0.
def test_setslice_of_slice_array(self):
- from _numpypy import array, zeros
+ from numpypy import array, zeros
a = zeros(5)
a[::2] = array([9., 10., 11.])
assert a[0] == 9.
@@ -507,7 +507,7 @@
assert a[0] == 3.
def test_setslice_list(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5), float)
b = [0., 1.]
a[1:4:2] = b
@@ -515,7 +515,7 @@
assert a[3] == 1.
def test_setslice_constant(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5), float)
a[1:4:2] = 0.
assert a[1] == 0.
@@ -523,7 +523,7 @@
def test_newaxis(self):
import math
- from _numpypy import array, cos, zeros
+ from numpypy import array, cos, zeros
from numpypy.core.numeric import newaxis
a = array(range(5))
b = array([range(5)])
@@ -537,7 +537,7 @@
assert ((cos(a)[:,newaxis] * cos(b).T) == expected).all()
def test_newaxis_slice(self):
- from _numpypy import array
+ from numpypy import array
from numpypy.core.numeric import newaxis
a = array(range(5))
@@ -550,7 +550,7 @@
assert (a[newaxis,1:] == c).all()
def test_newaxis_assign(self):
- from _numpypy import array
+ from numpypy import array
from numpypy.core.numeric import newaxis
a = array(range(5))
@@ -558,7 +558,7 @@
assert a[1] == 2
def test_newaxis_virtual(self):
- from _numpypy import array
+ from numpypy import array
from numpypy.core.numeric import newaxis
a = array(range(5))
@@ -567,7 +567,7 @@
assert (b == c).all()
def test_newaxis_then_slice(self):
- from _numpypy import array
+ from numpypy import array
from numpypy.core.numeric import newaxis
a = array(range(5))
b = a[newaxis]
@@ -575,14 +575,14 @@
assert (b[0,1:] == a[1:]).all()
def test_slice_then_newaxis(self):
- from _numpypy import array
+ from numpypy import array
from numpypy.core.numeric import newaxis
a = array(range(5))
b = a[2:]
assert (b[newaxis] == [[2, 3, 4]]).all()
def test_scalar(self):
- from _numpypy import array, dtype
+ from numpypy import array, dtype
a = array(3)
raises(IndexError, "a[0]")
raises(IndexError, "a[0] = 5")
@@ -591,13 +591,13 @@
assert a.dtype is dtype(int)
def test_len(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
assert len(a) == 5
assert len(a + a) == 5
def test_shape(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
assert a.shape == (5,)
b = a + a
@@ -607,7 +607,7 @@
assert array([]).shape == (0,)
def test_set_shape(self):
- from _numpypy import array, zeros
+ from numpypy import array, zeros
a = array([])
raises(ValueError, "a.shape = []")
a = array(range(12))
@@ -630,7 +630,7 @@
raises(AttributeError, 'a.shape = 6')
def test_reshape(self):
- from _numpypy import array, zeros
+ from numpypy import array, zeros
a = array(range(12))
exc = raises(ValueError, "b = a.reshape((3, 10))")
assert str(exc.value) == "total size of new array must be unchanged"
@@ -646,7 +646,7 @@
assert a.reshape((0,)).shape == (0,)
def test_slice_reshape(self):
- from _numpypy import zeros, arange
+ from numpypy import zeros, arange
a = zeros((4, 2, 3))
b = a[::2, :, :]
b.shape = (2, 6)
@@ -682,7 +682,7 @@
raises(ValueError, arange(10).reshape, (5, -1, -1))
def test_reshape_varargs(self):
- from _numpypy import arange
+ from numpypy import arange
z = arange(96).reshape(12, -1)
y = z.reshape(4, 3, 8)
assert y.shape == (4, 3, 8)
@@ -695,19 +695,19 @@
raises(ValueError, "a.reshape(3)")
def test_strides(self):
- from _numpypy import array
+ from numpypy import array
a = array([[1.0, 2.0],
[3.0, 4.0]])
assert a.strides == (16, 8)
assert a[1:].strides == (16, 8)
def test_strides_scalar(self):
- from _numpypy import array
+ from numpypy import array
a = array(42)
assert a.strides == ()
def test_add(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = a + a
for i in range(5):
@@ -720,7 +720,7 @@
assert c[i] == bool(a[i] + b[i])
def test_add_other(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = array([i for i in reversed(range(5))])
c = a + b
@@ -728,14 +728,14 @@
assert c[i] == 4
def test_add_constant(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = a + 5
for i in range(5):
assert b[i] == i + 5
def test_radd(self):
- from _numpypy import array
+ from numpypy import array
r = 3 + array(range(3))
for i in range(3):
assert r[i] == i + 3
@@ -743,7 +743,7 @@
assert (r == [2, 4]).all()
def test_add_list(self):
- from _numpypy import array, ndarray
+ from numpypy import array, ndarray
a = array(range(5))
b = list(reversed(range(5)))
c = a + b
@@ -752,14 +752,14 @@
assert c[i] == 4
def test_subtract(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = a - a
for i in range(5):
assert b[i] == 0
def test_subtract_other(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = array([1, 1, 1, 1, 1])
c = a - b
@@ -767,36 +767,35 @@
assert c[i] == i - 1
def test_subtract_constant(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = a - 5
for i in range(5):
assert b[i] == i - 5
def test_scalar_subtract(self):
- from _numpypy import int32
+ from numpypy import int32
assert int32(2) - 1 == 1
assert 1 - int32(2) == -1
def test_mul(self):
- import _numpypy
- from numpypy import False_, True_
+ import numpypy
- a = _numpypy.array(range(5))
+ a = numpypy.array(range(5))
b = a * a
for i in range(5):
assert b[i] == i * i
assert b.dtype is a.dtype
- a = _numpypy.array(range(5), dtype=bool)
+ a = numpypy.array(range(5), dtype=bool)
b = a * a
- assert b.dtype is _numpypy.dtype(bool)
- assert b[0] is False_
+ assert b.dtype is numpypy.dtype(bool)
+ assert b[0] is numpypy.False_
for i in range(1, 5):
- assert b[i] is True_
+ assert b[i] is numpypy.True_
def test_mul_constant(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = a * 5
for i in range(5):
@@ -804,7 +803,7 @@
def test_div(self):
from math import isnan
- from _numpypy import array, dtype
+ from numpypy import array, dtype
a = array(range(1, 6))
b = a / a
@@ -836,7 +835,7 @@
assert c[2] == float('-inf')
def test_div_other(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = array([2, 2, 2, 2, 2], float)
c = a / b
@@ -844,7 +843,7 @@
assert c[i] == i / 2.0
def test_div_constant(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = a / 5.0
for i in range(5):
@@ -852,7 +851,7 @@
def test_floordiv(self):
from math import isnan
- from _numpypy import array, dtype
+ from numpypy import array, dtype
a = array(range(1, 6))
b = a // a
@@ -882,47 +881,47 @@
assert c[2] == float('-inf')
def test_floordiv_other(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = array([2, 2, 2, 2, 2], float)
c = a // b
assert (c == [0, 0, 1, 1, 2]).all()
def test_rfloordiv(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(1, 6))
b = 3 // a
assert (b == [3, 1, 1, 0, 0]).all()
def test_floordiv_constant(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = a // 2
assert (b == [0, 0, 1, 1, 2]).all()
def test_truediv(self):
from operator import truediv
- from _numpypy import arange
+ from numpypy import arange
assert (truediv(arange(5), 2) == [0., .5, 1., 1.5, 2.]).all()
assert (truediv(2, arange(3)) == [float("inf"), 2., 1.]).all()
def test_divmod(self):
- from _numpypy import arange
+ from numpypy import arange
a, b = divmod(arange(10), 3)
assert (a == [0, 0, 0, 1, 1, 1, 2, 2, 2, 3]).all()
assert (b == [0, 1, 2, 0, 1, 2, 0, 1, 2, 0]).all()
def test_rdivmod(self):
- from _numpypy import arange
+ from numpypy import arange
a, b = divmod(3, arange(1, 5))
assert (a == [3, 1, 1, 0]).all()
assert (b == [0, 1, 0, 3]).all()
def test_lshift(self):
- from _numpypy import array
+ from numpypy import array
a = array([0, 1, 2, 3])
assert (a << 2 == [0, 4, 8, 12]).all()
@@ -932,13 +931,13 @@
raises(TypeError, lambda: a << 2)
def test_rlshift(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(3)
assert (2 << a == [2, 4, 8]).all()
def test_rshift(self):
- from _numpypy import arange, array
+ from numpypy import arange, array
a = arange(10)
assert (a >> 2 == [0, 0, 0, 0, 1, 1, 1, 1, 2, 2]).all()
@@ -948,13 +947,13 @@
raises(TypeError, lambda: a >> 1)
def test_rrshift(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(5)
assert (2 >> a == [2, 1, 0, 0, 0]).all()
def test_pow(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5), float)
b = a ** a
for i in range(5):
@@ -964,7 +963,7 @@
assert (a ** 2 == a * a).all()
def test_pow_other(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5), float)
b = array([2, 2, 2, 2, 2])
c = a ** b
@@ -972,14 +971,14 @@
assert c[i] == i ** 2
def test_pow_constant(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5), float)
b = a ** 2
for i in range(5):
assert b[i] == i ** 2
def test_mod(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(1, 6))
b = a % a
for i in range(5):
@@ -992,7 +991,7 @@
assert b[i] == 1
def test_mod_other(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = array([2, 2, 2, 2, 2])
c = a % b
@@ -1000,38 +999,38 @@
assert c[i] == i % 2
def test_mod_constant(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = a % 2
for i in range(5):
assert b[i] == i % 2
def test_rand(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(5)
assert (3 & a == [0, 1, 2, 3, 0]).all()
def test_ror(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(5)
assert (3 | a == [3, 3, 3, 3, 7]).all()
def test_xor(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(5)
assert (a ^ 3 == [3, 2, 1, 0, 7]).all()
def test_rxor(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(5)
assert (3 ^ a == [3, 2, 1, 0, 7]).all()
def test_pos(self):
- from _numpypy import array
+ from numpypy import array
a = array([1., -2., 3., -4., -5.])
b = +a
for i in range(5):
@@ -1042,7 +1041,7 @@
assert a[i] == i
def test_neg(self):
- from _numpypy import array
+ from numpypy import array
a = array([1., -2., 3., -4., -5.])
b = -a
for i in range(5):
@@ -1053,7 +1052,7 @@
assert a[i] == -i
def test_abs(self):
- from _numpypy import array
+ from numpypy import array
a = array([1., -2., 3., -4., -5.])
b = abs(a)
for i in range(5):
@@ -1064,7 +1063,7 @@
assert a[i + 5] == abs(i)
def test_auto_force(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
b = a - 1
a[2] = 3
@@ -1078,7 +1077,7 @@
assert c[1] == 4
def test_getslice(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
s = a[1:5]
assert len(s) == 4
@@ -1092,7 +1091,7 @@
assert s[0] == 5
def test_getslice_step(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(10))
s = a[1:9:2]
assert len(s) == 4
@@ -1100,7 +1099,7 @@
assert s[i] == a[2 * i + 1]
def test_slice_update(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
s = a[0:3]
s[1] = 10
@@ -1110,7 +1109,7 @@
def test_slice_invaidate(self):
# check that slice shares invalidation list with
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
s = a[0:2]
b = array([10, 11])
@@ -1124,7 +1123,7 @@
assert d[1] == 12
def test_mean(self):
- from _numpypy import array, arange
+ from numpypy import array, arange
a = array(range(5))
assert a.mean() == 2.0
assert a[:4].mean() == 1.5
@@ -1142,7 +1141,7 @@
assert (a.mean(1) == [0.5, 2.5, 4.5, 6.5, 8.5]).all()
def test_sum(self):
- from _numpypy import array, zeros
+ from numpypy import array, zeros
a = array(range(5))
assert a.sum() == 10
assert a[:4].sum() == 6
@@ -1190,13 +1189,13 @@
assert (array([[1,2],[3,4]]).prod(1) == [2, 12]).all()
def test_prod(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(1, 6))
assert a.prod() == 120.0
assert a[:4].prod() == 24.0
def test_max(self):
- from _numpypy import array, zeros
+ from numpypy import array, zeros
a = array([-1.2, 3.4, 5.7, -3.0, 2.7])
assert a.max() == 5.7
b = array([])
@@ -1206,12 +1205,12 @@
assert list(zeros((0, 2)).max(axis=1)) == []
def test_max_add(self):
- from _numpypy import array
+ from numpypy import array
a = array([-1.2, 3.4, 5.7, -3.0, 2.7])
assert (a + a).max() == 11.4
def test_min(self):
- from _numpypy import array, zeros
+ from numpypy import array, zeros
a = array([-1.2, 3.4, 5.7, -3.0, 2.7])
assert a.min() == -3.0
b = array([])
@@ -1221,7 +1220,7 @@
assert list(zeros((0, 2)).min(axis=1)) == []
def test_argmax(self):
- from _numpypy import array
+ from numpypy import array
a = array([-1.2, 3.4, 5.7, -3.0, 2.7])
r = a.argmax()
assert r == 2
@@ -1242,14 +1241,14 @@
assert a.argmax() == 2
def test_argmin(self):
- from _numpypy import array
+ from numpypy import array
a = array([-1.2, 3.4, 5.7, -3.0, 2.7])
assert a.argmin() == 3
b = array([])
raises(ValueError, "b.argmin()")
def test_all(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
assert a.all() == False
a[0] = 3.0
@@ -1258,7 +1257,7 @@
assert b.all() == True
def test_any(self):
- from _numpypy import array, zeros
+ from numpypy import array, zeros
a = array(range(5))
assert a.any() == True
b = zeros(5)
@@ -1267,7 +1266,7 @@
assert c.any() == False
def test_dtype_guessing(self):
- from _numpypy import array, dtype, float64, int8, bool_
+ from numpypy import array, dtype, float64, int8, bool_
assert array([True]).dtype is dtype(bool)
assert array([True, False]).dtype is dtype(bool)
@@ -1284,7 +1283,7 @@
def test_comparison(self):
import operator
- from _numpypy import array, dtype
+ from numpypy import array, dtype
a = array(range(5))
b = array(range(5), float)
@@ -1303,7 +1302,7 @@
assert c[i] == func(b[i], 3)
def test_nonzero(self):
- from _numpypy import array
+ from numpypy import array
a = array([1, 2])
raises(ValueError, bool, a)
raises(ValueError, bool, a == a)
@@ -1313,7 +1312,7 @@
assert not bool(array([0]))
def test_slice_assignment(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
a[::-1] = a
assert (a == [4, 3, 2, 1, 0]).all()
@@ -1323,7 +1322,7 @@
assert (a == [8, 6, 4, 2, 0]).all()
def test_virtual_views(self):
- from _numpypy import arange
+ from numpypy import arange
a = arange(15)
c = (a + a)
d = c[::2]
@@ -1341,7 +1340,7 @@
assert b[1] == 2
def test_realimag_views(self):
- from _numpypy import arange, array
+ from numpypy import arange, array
a = arange(15)
b = a.real
b[5]=50
@@ -1377,7 +1376,7 @@
assert a[2].imag == -5
def test_tolist_scalar(self):
- from _numpypy import int32, bool_
+ from numpypy import int32, bool_
x = int32(23)
assert x.tolist() == 23
assert type(x.tolist()) is int
@@ -1385,13 +1384,13 @@
assert y.tolist() is True
def test_tolist_zerodim(self):
- from _numpypy import array
+ from numpypy import array
x = array(3)
assert x.tolist() == 3
assert type(x.tolist()) is int
def test_tolist_singledim(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(5))
assert a.tolist() == [0, 1, 2, 3, 4]
assert type(a.tolist()[0]) is int
@@ -1399,23 +1398,23 @@
assert b.tolist() == [0.2, 0.4, 0.6]
def test_tolist_multidim(self):
- from _numpypy import array
+ from numpypy import array
a = array([[1, 2], [3, 4]])
assert a.tolist() == [[1, 2], [3, 4]]
def test_tolist_view(self):
- from _numpypy import array
+ from numpypy import array
a = array([[1, 2], [3, 4]])
assert (a + a).tolist() == [[2, 4], [6, 8]]
def test_tolist_slice(self):
- from _numpypy import array
+ from numpypy import array
a = array([[17.1, 27.2], [40.3, 50.3]])
assert a[:, 0].tolist() == [17.1, 40.3]
assert a[0].tolist() == [17.1, 27.2]
def test_var(self):
- from _numpypy import array, arange
+ from numpypy import array, arange
a = array(range(10))
assert a.var() == 8.25
a = array([5.0])
@@ -1484,14 +1483,14 @@
assert (b == [2, 6, 10, 2, 6, 10]).all()
def test_std(self):
- from _numpypy import array
+ from numpypy import array
a = array(range(10))
assert a.std() == 2.8722813232690143
a = array([5.0])
assert a.std() == 0.0
def test_flatten(self):
- from _numpypy import array
+ from numpypy import array
assert array(3).flatten().shape == (1,)
a = array([[1, 2], [3, 4]])
@@ -1514,7 +1513,7 @@
assert (a.T.flatten() == [1, 3, 2, 4]).all()
def test_itemsize(self):
- from _numpypy import ones, dtype, array
+ from numpypy import ones, dtype, array
for obj in [float, bool, int]:
assert ones(1, dtype=obj).itemsize == dtype(obj).itemsize
@@ -1523,7 +1522,7 @@
assert ones(1)[:].itemsize == 8
def test_nbytes(self):
- from _numpypy import array, ones
+ from numpypy import array, ones
assert ones(1).nbytes == 8
assert ones((2, 2)).nbytes == 32
@@ -1532,7 +1531,7 @@
assert array(3.0).nbytes == 8
def test_repeat(self):
- from _numpypy import repeat, array
+ from numpypy import repeat, array
assert (repeat([[1, 2], [3, 4]], 3) == [1, 1, 1, 2, 2, 2,
3, 3, 3, 4, 4, 4]).all()
assert (repeat([[1, 2], [3, 4]], 2, axis=0) == [[1, 2], [1, 2], [3, 4],
@@ -1543,7 +1542,7 @@
def test_swapaxes(self):
- from _numpypy import array
+ from numpypy import array
# testcases from numpy docstring
x = array([[1, 2, 3]])
assert (x.swapaxes(0, 1) == array([[1], [2], [3]])).all()
@@ -1629,7 +1628,7 @@
assert _weakref.ref(a)
def test_astype(self):
- from _numpypy import array, arange
+ from numpypy import array, arange
b = array(1).astype(float)
assert b == 1
assert b.dtype == float
@@ -1650,7 +1649,7 @@
assert a.itemsize == 3
def test_base(self):
- from _numpypy import array
+ from numpypy import array
assert array(1).base is None
assert array([1, 2]).base is None
a = array([1, 2, 3, 4])
@@ -1658,7 +1657,7 @@
assert b.base is a
def test_byteswap(self):
- from _numpypy import array
+ from numpypy import array
s1 = array(1.).byteswap().tostring()
s2 = array([1.]).byteswap().tostring()
@@ -1698,7 +1697,7 @@
assert list(reversed(s1[i1:i2])) == s2[i1:i2]
def test_clip(self):
- from _numpypy import array
+ from numpypy import array
a = array([1, 2, 17, -3, 12])
assert (a.clip(-2, 13) == [1, 2, 13, -2, 12]).all()
assert (a.clip(-1, 1, out=None) == [1, 1, 1, -1, 1]).all()
@@ -1708,7 +1707,7 @@
assert (a == [1, 2, 13, -2, 12]).all()
def test_data(self):
- from _numpypy import array
+ from numpypy import array
a = array([1, 2, 3, 4], dtype='i4')
assert a.data[0] == '\x01'
assert a.data[1] == '\x00'
@@ -1718,13 +1717,13 @@
assert len(a.data) == 16
def test_explicit_dtype_conversion(self):
- from _numpypy import array
+ from numpypy import array
a = array([1.0, 2.0])
b = array(a, dtype='d')
assert a.dtype is b.dtype
def test_notequal_different_shapes(self):
- from _numpypy import array
+ from numpypy import array
a = array([1, 2])
b = array([1, 2, 3, 4])
assert (a == b) == False
@@ -1732,23 +1731,23 @@
class AppTestMultiDim(BaseNumpyAppTest):
def test_init(self):
- import _numpypy
- a = _numpypy.zeros((2, 2))
+ import numpypy
+ a = numpypy.zeros((2, 2))
assert len(a) == 2
def test_shape(self):
- import _numpypy
- assert _numpypy.zeros(1).shape == (1,)
- assert _numpypy.zeros((2, 2)).shape == (2, 2)
- assert _numpypy.zeros((3, 1, 2)).shape == (3, 1, 2)
- assert _numpypy.array([[1], [2], [3]]).shape == (3, 1)
- assert len(_numpypy.zeros((3, 1, 2))) == 3
- raises(TypeError, len, _numpypy.zeros(()))
- raises(ValueError, _numpypy.array, [[1, 2], 3], dtype=float)
+ import numpypy
+ assert numpypy.zeros(1).shape == (1,)
+ assert numpypy.zeros((2, 2)).shape == (2, 2)
+ assert numpypy.zeros((3, 1, 2)).shape == (3, 1, 2)
+ assert numpypy.array([[1], [2], [3]]).shape == (3, 1)
+ assert len(numpypy.zeros((3, 1, 2))) == 3
+ raises(TypeError, len, numpypy.zeros(()))
+ raises(ValueError, numpypy.array, [[1, 2], 3], dtype=float)
def test_getsetitem(self):
- import _numpypy
- a = _numpypy.zeros((2, 3, 1))
+ import numpypy
+ a = numpypy.zeros((2, 3, 1))
raises(IndexError, a.__getitem__, (2, 0, 0))
raises(IndexError, a.__getitem__, (0, 3, 0))
More information about the pypy-commit
mailing list