Maciej Fijalkowski avatar Maciej Fijalkowski committed 31b1dba Merge

merge

Comments (0)

Files changed (6)

lib_pypy/numpypy/test/test_fromnumeric.py

-
 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
         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
         # 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
         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]])
         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)

pypy/module/_codecs/interp_codecs.py

     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

pypy/module/micronumpy/__init__.py

 
     appleveldefs = {
         'average': 'app_numpy.average',
-        'mean': 'app_numpy.mean',
         'sum': 'app_numpy.sum',
         'min': 'app_numpy.min',
         'identity': 'app_numpy.identity',
         'e': 'app_numpy.e',
         'pi': 'app_numpy.pi',
         'arange': 'app_numpy.arange',
-        'reshape': 'app_numpy.reshape',
     }

pypy/module/micronumpy/app_numpy.py

 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
     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
         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.
         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)

pypy/module/micronumpy/test/test_module.py

 
 
 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
         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

pypy/module/micronumpy/test/test_numarray.py

         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
         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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.