[pypy-commit] pypy default: merge
fijal
noreply at buildbot.pypy.org
Tue Jan 17 20:46:33 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r51420:31b1dbaa7024
Date: 2012-01-17 21:45 +0200
http://bitbucket.org/pypy/pypy/changeset/31b1dbaa7024/
Log: merge
diff --git a/lib_pypy/numpypy/test/test_fromnumeric.py b/lib_pypy/numpypy/test/test_fromnumeric.py
--- a/lib_pypy/numpypy/test/test_fromnumeric.py
+++ b/lib_pypy/numpypy/test/test_fromnumeric.py
@@ -1,7 +1,7 @@
-
from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
-class AppTestFromNumeric(BaseNumpyAppTest):
+
+class AppTestFromNumeric(BaseNumpyAppTest):
def test_argmax(self):
# tests taken from numpy/core/fromnumeric.py docstring
from numpypy import array, arange, argmax
@@ -18,12 +18,12 @@
from numpypy import array, arange, argmin
a = arange(6).reshape((2,3))
assert argmin(a) == 0
- # assert (argmax(a, axis=0) == array([0, 0, 0])).all()
- # assert (argmax(a, axis=1) == array([0, 0])).all()
+ assert (argmin(a, axis=0) == array([0, 0, 0])).all()
+ assert (argmin(a, axis=1) == array([0, 0])).all()
b = arange(6)
b[1] = 0
assert argmin(b) == 0
-
+
def test_shape(self):
# tests taken from numpy/core/fromnumeric.py docstring
from numpypy import array, identity, shape
@@ -44,7 +44,7 @@
# assert (sum([[0, 1], [0, 5]], axis=1) == array([1, 5])).all()
# If the accumulator is too small, overflow occurs:
# assert ones(128, dtype=int8).sum(dtype=int8) == -128
-
+
def test_amin(self):
# tests taken from numpy/core/fromnumeric.py docstring
from numpypy import array, arange, amin
@@ -86,14 +86,14 @@
assert ndim([[1,2,3],[4,5,6]]) == 2
assert ndim(array([[1,2,3],[4,5,6]])) == 2
assert ndim(1) == 0
-
+
def test_rank(self):
# tests taken from numpy/core/fromnumeric.py docstring
from numpypy import array, rank
assert rank([[1,2,3],[4,5,6]]) == 2
assert rank(array([[1,2,3],[4,5,6]])) == 2
assert rank(1) == 0
-
+
def test_var(self):
from numpypy import array, var
a = array([[1,2],[3,4]])
@@ -107,3 +107,21 @@
assert std(a) == 1.1180339887498949
# assert (std(a, axis=0) == array([ 1., 1.])).all()
# assert (std(a, axis=1) == array([ 0.5, 0.5]).all()
+
+ def test_mean(self):
+ from numpypy import array, mean
+ assert mean(array(range(5))) == 2.0
+ assert mean(range(5)) == 2.0
+
+ def test_reshape(self):
+ from numpypy import arange, array, dtype, reshape
+ a = arange(12)
+ b = reshape(a, (3, 4))
+ assert b.shape == (3, 4)
+ a = range(12)
+ b = reshape(a, (3, 4))
+ assert b.shape == (3, 4)
+ a = array(range(105)).reshape(3, 5, 7)
+ assert reshape(a, (1, -1)).shape == (1, 105)
+ assert reshape(a, (1, 1, -1)).shape == (1, 1, 105)
+ assert reshape(a, (-1, 1, 1)).shape == (105, 1, 1)
diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -108,6 +108,10 @@
w_result = state.codec_search_cache.get(normalized_encoding, None)
if w_result is not None:
return w_result
+ return _lookup_codec_loop(space, encoding, normalized_encoding)
+
+def _lookup_codec_loop(space, encoding, normalized_encoding):
+ state = space.fromcache(CodecState)
if state.codec_need_encodings:
w_import = space.getattr(space.builtin, space.wrap("__import__"))
# registers new codecs
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
@@ -90,7 +90,6 @@
appleveldefs = {
'average': 'app_numpy.average',
- 'mean': 'app_numpy.mean',
'sum': 'app_numpy.sum',
'min': 'app_numpy.min',
'identity': 'app_numpy.identity',
@@ -99,5 +98,4 @@
'e': 'app_numpy.e',
'pi': 'app_numpy.pi',
'arange': 'app_numpy.arange',
- 'reshape': 'app_numpy.reshape',
}
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
@@ -11,23 +11,20 @@
def average(a):
# This implements a weighted average, for now we don't implement the
# weighting, just the average part!
- return mean(a)
+ if not hasattr(a, "mean"):
+ a = _numpypy.array(a)
+ return a.mean()
def identity(n, dtype=None):
- a = _numpypy.zeros((n,n), dtype=dtype)
+ a = _numpypy.zeros((n, n), dtype=dtype)
for i in range(n):
a[i][i] = 1
return a
-def mean(a, axis=None):
- if not hasattr(a, "mean"):
- a = _numpypy.array(a)
- return a.mean(axis)
-
def sum(a,axis=None):
'''sum(a, axis=None)
Sum of array elements over a given axis.
-
+
Parameters
----------
a : array_like
@@ -35,7 +32,7 @@
axis : integer, optional
Axis over which the sum is taken. By default `axis` is None,
and all elements are summed.
-
+
Returns
-------
sum_along_axis : ndarray
@@ -43,7 +40,7 @@
axis removed. If `a` is a 0-d array, or if `axis` is None, a scalar
is returned. If an output array is specified, a reference to
`out` is returned.
-
+
See Also
--------
ndarray.sum : Equivalent method.
@@ -79,40 +76,3 @@
arr[j] = i
i += step
return arr
-
-
-def reshape(a, shape):
- '''reshape(a, newshape)
- Gives a new shape to an array without changing its data.
-
- Parameters
- ----------
- a : array_like
- Array to be reshaped.
- newshape : int or tuple of ints
- The new shape should be compatible with the original shape. If
- an integer, then the result will be a 1-D array of that length.
- One shape dimension can be -1. In this case, the value is inferred
- from the length of the array and remaining dimensions.
-
- Returns
- -------
- reshaped_array : ndarray
- This will be a new view object if possible; otherwise, it will
- be a copy.
-
-
- See Also
- --------
- ndarray.reshape : Equivalent method.
-
- Notes
- -----
-
- It is not always possible to change the shape of an array without
- copying the data. If you want an error to be raise if the data is copied,
- you should assign the new shape to the shape attribute of the array
-'''
- if not hasattr(a, 'reshape'):
- a = _numpypy.array(a)
- return a.reshape(shape)
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
@@ -2,16 +2,11 @@
class AppTestNumPyModule(BaseNumpyAppTest):
- def test_mean(self):
- from _numpypy import array, mean
- assert mean(array(range(5))) == 2.0
- assert mean(range(5)) == 2.0
-
def test_average(self):
from _numpypy import array, average
assert average(range(10)) == 4.5
assert average(array(range(10))) == 4.5
-
+
def test_sum(self):
from _numpypy import array, sum
assert sum(range(10)) == 45
@@ -21,7 +16,7 @@
from _numpypy import array, min
assert min(range(10)) == 0
assert min(array(range(10))) == 0
-
+
def test_max(self):
from _numpypy import array, max
assert max(range(10)) == 9
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
@@ -726,16 +726,16 @@
assert d[1] == 12
def test_mean(self):
- from _numpypy import array, mean
+ from _numpypy import array
a = array(range(5))
assert a.mean() == 2.0
assert a[:4].mean() == 1.5
a = array(range(105)).reshape(3, 5, 7)
- b = mean(a, axis=0)
- b[0,0]==35.
+ b = a.mean(axis=0)
+ b[0, 0]==35.
assert a.mean(axis=0)[0, 0] == 35
assert (b == array(range(35, 70), dtype=float).reshape(5, 7)).all()
- assert (mean(a, 2) == array(range(0, 15), dtype=float).reshape(3, 5) * 7 + 3).all()
+ assert (a.mean(2) == array(range(0, 15), dtype=float).reshape(3, 5) * 7 + 3).all()
def test_sum(self):
from _numpypy import array
@@ -1550,18 +1550,3 @@
a = arange(0, 0.8, 0.1)
assert len(a) == 8
assert arange(False, True, True).dtype is dtype(int)
-
-
-class AppTestRanges(BaseNumpyAppTest):
- def test_app_reshape(self):
- from _numpypy import arange, array, dtype, reshape
- a = arange(12)
- b = reshape(a, (3, 4))
- assert b.shape == (3, 4)
- a = range(12)
- b = reshape(a, (3, 4))
- assert b.shape == (3, 4)
- a = array(range(105)).reshape(3, 5, 7)
- assert a.reshape(1, -1).shape == (1, 105)
- assert a.reshape(1, 1, -1).shape == (1, 1, 105)
- assert a.reshape(-1, 1, 1).shape == (105, 1, 1)
More information about the pypy-commit
mailing list