Author: Maciej Fijalkowski <[email protected]>
Branch: numpy-back-to-applevel
Changeset: r51741:838a81530121
Date: 2012-01-24 20:57 +0200
http://bitbucket.org/pypy/pypy/changeset/838a81530121/
Log: move test and make it pass on CPython. besides, trick numpy into
believing it's numpypy when running with -A on CPython
diff --git a/lib_pypy/numpypy/core/arrayprint.py
b/lib_pypy/numpypy/core/arrayprint.py
--- a/lib_pypy/numpypy/core/arrayprint.py
+++ b/lib_pypy/numpypy/core/arrayprint.py
@@ -305,10 +305,10 @@
#else:
format_function = formatdict['int']
elif issubclass(dtypeobj, _nt.floating):
- if issubclass(dtypeobj, _nt.longfloat):
- format_function = formatdict['longfloat']
- else:
- format_function = formatdict['float']
+ #if issubclass(dtypeobj, _nt.longfloat):
+ # format_function = formatdict['longfloat']
+ #else:
+ format_function = formatdict['float']
elif issubclass(dtypeobj, _nt.complexfloating):
if issubclass(dtypeobj, _nt.clongfloat):
format_function = formatdict['longcomplexfloat']
@@ -610,7 +610,7 @@
def __call__(self, x, strip_zeros=True):
import numeric as _nc
- err = _nc.seterr(invalid='ignore')
+ #err = _nc.seterr(invalid='ignore')
try:
if isna(x):
return self.special_fmt % (str(x).replace('NA', _na_str, 1),)
@@ -628,7 +628,8 @@
else:
return self.special_fmt % ('-' + _inf_str,)
finally:
- _nc.seterr(**err)
+ pass
+ #_nc.seterr(**err)
s = self.format % x
if self.large_exponent:
diff --git a/pypy/module/micronumpy/test/test_base.py
b/pypy/module/micronumpy/test/test_base.py
--- a/pypy/module/micronumpy/test/test_base.py
+++ b/pypy/module/micronumpy/test/test_base.py
@@ -3,9 +3,15 @@
from pypy.module.micronumpy.interp_numarray import W_NDimArray, Scalar
from pypy.module.micronumpy.interp_ufuncs import (find_binop_result_dtype,
find_unaryop_result_dtype)
+from pypy.conftest import option
+import sys
class BaseNumpyAppTest(object):
def setup_class(cls):
+ if option.runappdirect:
+ if '__pypy__' not in sys.builtin_module_names:
+ import numpy
+ sys.modules['numpypy'] = numpy
cls.space = gettestobjspace(usemodules=['micronumpy'])
class TestSignature(object):
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
@@ -1513,128 +1513,6 @@
raises(ValueError, fromstring, "\x01\x02\x03", count=5, dtype=uint8)
-class AppTestRepr(BaseNumpyAppTest):
- def test_repr(self):
- from _numpypy import array, zeros
- int_size = array(5).dtype.itemsize
- a = array(range(5), float)
- assert repr(a) == "array([0.0, 1.0, 2.0, 3.0, 4.0])"
- a = array([], float)
- assert repr(a) == "array([], dtype=float64)"
- a = zeros(1001)
- assert repr(a) == "array([0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0])"
- a = array(range(5), long)
- if a.dtype.itemsize == int_size:
- assert repr(a) == "array([0, 1, 2, 3, 4])"
- else:
- assert repr(a) == "array([0, 1, 2, 3, 4], dtype=int64)"
- a = array(range(5), 'int32')
- if a.dtype.itemsize == int_size:
- assert repr(a) == "array([0, 1, 2, 3, 4])"
- else:
- assert repr(a) == "array([0, 1, 2, 3, 4], dtype=int32)"
- a = array([], long)
- assert repr(a) == "array([], dtype=int64)"
- a = array([True, False, True, False], "?")
- assert repr(a) == "array([True, False, True, False], dtype=bool)"
- a = zeros([])
- assert repr(a) == "array(0.0)"
- a = array(0.2)
- assert repr(a) == "array(0.2)"
- a = array([2])
- assert repr(a) == "array([2])"
-
- def test_repr_multi(self):
- from _numpypy import arange, zeros, array
- a = zeros((3, 4))
- assert repr(a) == '''array([[0.0, 0.0, 0.0, 0.0],
- [0.0, 0.0, 0.0, 0.0],
- [0.0, 0.0, 0.0, 0.0]])'''
- a = zeros((2, 3, 4))
- assert repr(a) == '''array([[[0.0, 0.0, 0.0, 0.0],
- [0.0, 0.0, 0.0, 0.0],
- [0.0, 0.0, 0.0, 0.0]],
-
- [[0.0, 0.0, 0.0, 0.0],
- [0.0, 0.0, 0.0, 0.0],
- [0.0, 0.0, 0.0, 0.0]]])'''
- a = arange(1002).reshape((2, 501))
- assert repr(a) == '''array([[0, 1, 2, ..., 498, 499, 500],
- [501, 502, 503, ..., 999, 1000, 1001]])'''
- assert repr(a.T) == '''array([[0, 501],
- [1, 502],
- [2, 503],
- ...,
- [498, 999],
- [499, 1000],
- [500, 1001]])'''
- a = arange(2).reshape((2,1))
- assert repr(a) == '''array([[0],
- [1]])'''
-
- def test_repr_slice(self):
- from _numpypy import array, zeros
- a = array(range(5), float)
- b = a[1::2]
- assert repr(b) == "array([1.0, 3.0])"
- a = zeros(2002)
- b = a[::2]
- assert repr(b) == "array([0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0])"
- a = array((range(5), range(5, 10)), dtype="int16")
- b = a[1, 2:]
- assert repr(b) == "array([7, 8, 9], dtype=int16)"
- # an empty slice prints its shape
- b = a[2:1, ]
- assert repr(b) == "array([], shape=(0, 5), dtype=int16)"
-
- def test_str(self):
- from _numpypy import array, zeros
- a = array(range(5), float)
- assert str(a) == "[0.0 1.0 2.0 3.0 4.0]"
- assert str((2 * a)[:]) == "[0.0 2.0 4.0 6.0 8.0]"
- a = zeros(1001)
- assert str(a) == "[0.0 0.0 0.0 ..., 0.0 0.0 0.0]"
-
- a = array(range(5), dtype=long)
- assert str(a) == "[0 1 2 3 4]"
- a = array([True, False, True, False], dtype="?")
- assert str(a) == "[True False True False]"
-
- a = array(range(5), dtype="int8")
- assert str(a) == "[0 1 2 3 4]"
-
- a = array(range(5), dtype="int16")
- assert str(a) == "[0 1 2 3 4]"
-
- a = array((range(5), range(5, 10)), dtype="int16")
- assert str(a) == "[[0 1 2 3 4]\n [5 6 7 8 9]]"
-
- a = array(3, dtype=int)
- assert str(a) == "3"
-
- a = zeros((400, 400), dtype=int)
- assert str(a) == "[[0 0 0 ..., 0 0 0]\n [0 0 0 ..., 0 0 0]\n" \
- " [0 0 0 ..., 0 0 0]\n ...,\n [0 0 0 ..., 0 0 0]\n" \
- " [0 0 0 ..., 0 0 0]\n [0 0 0 ..., 0 0 0]]"
- a = zeros((2, 2, 2))
- r = str(a)
- assert r == '[[[0.0 0.0]\n [0.0 0.0]]\n\n [[0.0 0.0]\n [0.0 0.0]]]'
-
- def test_str_slice(self):
- from _numpypy import array, zeros
- a = array(range(5), float)
- b = a[1::2]
- assert str(b) == "[1.0 3.0]"
- a = zeros(2002)
- b = a[::2]
- assert str(b) == "[0.0 0.0 0.0 ..., 0.0 0.0 0.0]"
- a = array((range(5), range(5, 10)), dtype="int16")
- b = a[1, 2:]
- assert str(b) == "[7 8 9]"
- b = a[2:1, ]
- assert str(b) == "[]"
-
-
class AppTestRanges(BaseNumpyAppTest):
def test_arange(self):
from _numpypy import arange, array, dtype
diff --git a/pypy/module/test_lib_pypy/numpypy/core/test_numeric.py
b/pypy/module/test_lib_pypy/numpypy/core/test_numeric.py
--- a/pypy/module/test_lib_pypy/numpypy/core/test_numeric.py
+++ b/pypy/module/test_lib_pypy/numpypy/core/test_numeric.py
@@ -24,3 +24,121 @@
def test_repr(self):
from numpypy import array
assert repr(array([1, 2, 3, 4])) == 'array([1, 2, 3, 4])'
+
+ def test_repr_2(self):
+ from numpypy import array, zeros
+ int_size = array(5).dtype.itemsize
+ a = array(range(5), float)
+ assert repr(a) == "array([ 0., 1., 2., 3., 4.])"
+ a = array([], float)
+ assert repr(a) == "array([], dtype=float64)"
+ a = zeros(1001)
+ assert repr(a) == "array([ 0., 0., 0., ..., 0., 0., 0.])"
+ a = array(range(5), long)
+ if a.dtype.itemsize == int_size:
+ assert repr(a) == "array([0, 1, 2, 3, 4])"
+ else:
+ assert repr(a) == "array([0, 1, 2, 3, 4], dtype=int64)"
+ a = array(range(5), 'int32')
+ if a.dtype.itemsize == int_size:
+ assert repr(a) == "array([0, 1, 2, 3, 4])"
+ else:
+ assert repr(a) == "array([0, 1, 2, 3, 4], dtype=int32)"
+ a = array([], long)
+ assert repr(a) == "array([], dtype=int64)"
+ a = array([True, False, True, False], "?")
+ assert repr(a) == "array([ True, False, True, False], dtype=bool)"
+ a = zeros([])
+ assert repr(a) == "array(0.0)"
+ a = array(0.2)
+ assert repr(a) == "array(0.2)"
+ a = array([2])
+ assert repr(a) == "array([2])"
+
+ def test_repr_multi(self):
+ from numpypy import arange, zeros, array
+ a = zeros((3, 4))
+ assert repr(a) == '''array([[ 0., 0., 0., 0.],
+ [ 0., 0., 0., 0.],
+ [ 0., 0., 0., 0.]])'''
+ a = zeros((2, 3, 4))
+ assert repr(a) == '''array([[[ 0., 0., 0., 0.],
+ [ 0., 0., 0., 0.],
+ [ 0., 0., 0., 0.]],
+
+ [[ 0., 0., 0., 0.],
+ [ 0., 0., 0., 0.],
+ [ 0., 0., 0., 0.]]])'''
+ a = arange(1002).reshape((2, 501))
+ assert repr(a) == '''array([[ 0, 1, 2, ..., 498, 499, 500],
+ [ 501, 502, 503, ..., 999, 1000, 1001]])'''
+ assert repr(a.T) == '''array([[ 0, 501],
+ [ 1, 502],
+ [ 2, 503],
+ ...,
+ [ 498, 999],
+ [ 499, 1000],
+ [ 500, 1001]])'''
+ a = arange(2).reshape((2,1))
+ assert repr(a) == '''array([[0],
+ [1]])'''
+
+ def test_repr_slice(self):
+ from numpypy import array, zeros
+ a = array(range(5), float)
+ b = a[1::2]
+ assert repr(b) == "array([ 1., 3.])"
+ a = zeros(2002)
+ b = a[::2]
+ assert repr(b) == "array([ 0., 0., 0., ..., 0., 0., 0.])"
+ a = array((range(5), range(5, 10)), dtype="int16")
+ b = a[1, 2:]
+ assert repr(b) == "array([7, 8, 9], dtype=int16)"
+ # an empty slice prints its shape
+ b = a[2:1, ]
+ assert repr(b) == "array([], shape=(0, 5), dtype=int16)"
+
+ def test_str(self):
+ from numpypy import array, zeros
+ a = array(range(5), float)
+ assert str(a) == "[ 0. 1. 2. 3. 4.]"
+ assert str((2 * a)[:]) == "[ 0. 2. 4. 6. 8.]"
+ a = zeros(1001)
+ assert str(a) == "[ 0. 0. 0. ..., 0. 0. 0.]"
+
+ a = array(range(5), dtype=long)
+ assert str(a) == "[0 1 2 3 4]"
+ a = array([True, False, True, False], dtype="?")
+ assert str(a) == "[ True False True False]"
+
+ a = array(range(5), dtype="int8")
+ assert str(a) == "[0 1 2 3 4]"
+
+ a = array(range(5), dtype="int16")
+ assert str(a) == "[0 1 2 3 4]"
+
+ a = array((range(5), range(5, 10)), dtype="int16")
+ assert str(a) == "[[0 1 2 3 4]\n [5 6 7 8 9]]"
+
+ a = array(3, dtype=int)
+ assert str(a) == "3"
+
+ a = zeros((400, 400), dtype=int)
+ assert str(a) == '[[0 0 0 ..., 0 0 0]\n [0 0 0 ..., 0 0 0]\n [0 0 0
..., 0 0 0]\n ..., \n [0 0 0 ..., 0 0 0]\n [0 0 0 ..., 0 0 0]\n [0 0 0 ..., 0 0
0]]'
+ a = zeros((2, 2, 2))
+ r = str(a)
+ assert r == '[[[ 0. 0.]\n [ 0. 0.]]\n\n [[ 0. 0.]\n [ 0. 0.]]]'
+
+ def test_str_slice(self):
+ from numpypy import array, zeros
+ a = array(range(5), float)
+ b = a[1::2]
+ assert str(b) == "[ 1. 3.]"
+ a = zeros(2002)
+ b = a[::2]
+ assert str(b) == "[ 0. 0. 0. ..., 0. 0. 0.]"
+ a = array((range(5), range(5, 10)), dtype="int16")
+ b = a[1, 2:]
+ assert str(b) == "[7 8 9]"
+ b = a[2:1, ]
+ assert str(b) == "[]"
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit