Author: Matti Picus <[email protected]>
Branch:
Changeset: r67378:f320ec7a85b5
Date: 2013-10-15 06:57 +0300
http://bitbucket.org/pypy/pypy/changeset/f320ec7a85b5/
Log: fixes for removed numpy.py
diff --git a/lib_pypy/numpypy/__init__.py b/lib_pypy/numpypy/__init__.py
--- a/lib_pypy/numpypy/__init__.py
+++ b/lib_pypy/numpypy/__init__.py
@@ -28,9 +28,10 @@
...
"""
- import numpy
- if getattr(numpy, 'show_config', None) is None:
- # running from numpy source directory
+ try:
+ import numpy
+ except:
+ # running from pypy source directory
head, tail = os.path.split(os.path.dirname(os.path.abspath(__file__)))
return os.path.join(head, '../include')
else:
@@ -44,7 +45,6 @@
__all__ = ['__version__', 'get_include']
__all__ += core.__all__
__all__ += lib.__all__
-
#import sys
#sys.modules.setdefault('numpy', sys.modules['numpypy'])
diff --git a/lib_pypy/numpypy/core/fromnumeric.py
b/lib_pypy/numpypy/core/fromnumeric.py
--- a/lib_pypy/numpypy/core/fromnumeric.py
+++ b/lib_pypy/numpypy/core/fromnumeric.py
@@ -1,11 +1,11 @@
-######################################################################
+######################################################################
# This is a copy of numpy/core/fromnumeric.py modified for numpypy
######################################################################
-# Each name in __all__ was a function in 'numeric' that is now
+# Each name in __all__ was a function in 'numeric' that is now
# a method in 'numpy'.
# When the corresponding method is added to numpypy BaseArray
-# each function should be added as a module function
-# at the applevel
+# each function should be added as a module function
+# at the applevel
# This can be as simple as doing the following
#
# def func(a, ...):
@@ -15,8 +15,8 @@
#
######################################################################
-import numpypy
import _numpypy
+from _numpypy.multiarray import array as numpyarray
# Module containing non-deprecated functions borrowed from Numeric.
__docformat__ = "restructuredtext en"
@@ -152,7 +152,7 @@
"""
assert order == 'C'
if not hasattr(a, 'reshape'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.reshape(newshape)
@@ -457,7 +457,7 @@
if axes is not None:
raise NotImplementedError('No "axes" arg yet.')
if not hasattr(a, 'T'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.T
def sort(a, axis=-1, kind='quicksort', order=None):
@@ -695,7 +695,7 @@
"""
assert axis is None
if not hasattr(a, 'argmax'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.argmax()
@@ -711,7 +711,7 @@
"""
assert axis is None
if not hasattr(a, 'argmin'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.argmin()
@@ -1057,7 +1057,7 @@
"""
if not hasattr(a, 'ravel'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.ravel(order=order)
def nonzero(a):
@@ -1181,7 +1181,7 @@
"""
if not hasattr(a, 'shape'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.shape
@@ -1298,7 +1298,7 @@
"""
if not hasattr(a, 'clip'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.clip(a_min, a_max, out=out)
@@ -1370,7 +1370,7 @@
"""
assert dtype is None
if not hasattr(a, "sum"):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.sum(axis=axis, out=out)
@@ -1400,7 +1400,7 @@
assert axis is None
assert out is None
if not hasattr(a, 'any'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.any()
@@ -1416,7 +1416,7 @@
assert axis is None
assert out is None
if not hasattr(a, 'all'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.all()
def any(a,axis=None, out=None):
@@ -1486,7 +1486,7 @@
assert axis is None
assert out is None
if not hasattr(a, 'any'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.any()
@@ -1550,7 +1550,7 @@
assert axis is None
assert out is None
if not hasattr(a, 'all'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.all()
@@ -1729,9 +1729,9 @@
"""
if not hasattr(a, "max"):
- a = numpypy.array(a)
+ a = numpyarray(a)
if a.size < 1:
- return numpypy.array([])
+ return numpyarray([])
return a.max(axis=axis, out=out)
@@ -1791,9 +1791,9 @@
"""
if not hasattr(a, 'min'):
- a = numpypy.array(a)
+ a = numpyarray(a)
if a.size < 1:
- return numpypy.array([])
+ return numpyarray([])
return a.min(axis=axis, out=out)
def alen(a):
@@ -1824,7 +1824,7 @@
"""
if not hasattr(a, 'shape'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.shape[0]
@@ -2000,7 +2000,7 @@
"""
if not hasattr(a, 'ndim'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.ndim
@@ -2045,7 +2045,7 @@
"""
if not hasattr(a, 'ndim'):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.ndim
@@ -2243,7 +2243,7 @@
assert dtype is None
assert out is None
if not hasattr(a, "mean"):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.mean(axis=axis)
@@ -2337,7 +2337,7 @@
assert out is None
assert ddof == 0
if not hasattr(a, "std"):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.std(axis=axis)
@@ -2433,5 +2433,6 @@
assert out is None
assert ddof == 0
if not hasattr(a, "var"):
- a = numpypy.array(a)
+ a = numpyarray(a)
return a.var(axis=axis)
+
diff --git a/lib_pypy/numpypy/core/numerictypes.py
b/lib_pypy/numpypy/core/numerictypes.py
--- a/lib_pypy/numpypy/core/numerictypes.py
+++ b/lib_pypy/numpypy/core/numerictypes.py
@@ -1,5 +1,5 @@
from _numpypy.numerictypes import *
-import numpypy
+from _numpypy.multiarray import dtype
def issubclass_(arg1, arg2):
"""
@@ -66,10 +66,10 @@
"""
if issubclass_(arg2, generic):
- return issubclass(numpypy.dtype(arg1).type, arg2)
- mro = numpypy.dtype(arg2).type.mro()
+ return issubclass(dtype(arg1).type, arg2)
+ mro = dtype(arg2).type.mro()
if len(mro) > 1:
val = mro[1]
else:
val = mro[0]
- return issubclass(numpypy.dtype(arg1).type, val)
+ return issubclass(dtype(arg1).type, val)
diff --git a/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
--- a/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
+++ b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
@@ -4,7 +4,7 @@
class AppTestFromNumeric(BaseNumpyAppTest):
def test_argmax(self):
# tests taken from numpy/core/fromnumeric.py docstring
- from numpypy import array, arange, argmax
+ from numpypy import arange, argmax
a = arange(6).reshape((2,3))
assert argmax(a) == 5
# assert (argmax(a, axis=0) == array([1, 1, 1])).all()
@@ -15,7 +15,7 @@
def test_argmin(self):
# tests adapted from test_argmax
- from numpypy import array, arange, argmin
+ from numpypy import arange, argmin
a = arange(6).reshape((2,3))
assert argmin(a) == 0
#assert (argmin(a, axis=0) == array([0, 0, 0])).all()
@@ -26,7 +26,7 @@
def test_shape(self):
# tests taken from numpy/core/fromnumeric.py docstring
- from numpypy import array, identity, shape
+ from numpypy import identity, shape
assert shape(identity(3)) == (3, 3)
assert shape([[1, 2]]) == (1, 2)
assert shape([0]) == (1,)
@@ -50,7 +50,7 @@
def test_sum(self):
# tests taken from numpy/core/fromnumeric.py docstring
- from numpypy import array, sum, ones, zeros
+ from numpypy import sum, ones, zeros, array
assert sum([0.5, 1.5])== 2.0
assert sum([[0, 1], [0, 5]]) == 6
# assert sum([0.5, 0.7, 0.2, 1.5], dtype=int32) == 1
@@ -175,7 +175,7 @@
assert reshape(a, (1, 1, -1)).shape == (1, 1, 105)
assert reshape(a, (-1, 1, 1)).shape == (105, 1, 1)
- def test_transpose(self):
+ def test_transpose(self):
from numpypy import arange, array, transpose, ones
x = arange(4).reshape((2,2))
assert (transpose(x) == array([[0, 2],[1, 3]])).all()
@@ -189,5 +189,5 @@
x = array([[1,2,3]])
assert (swapaxes(x,0,1) == array([[1], [2], [3]])).all()
x = array([[[0,1],[2,3]],[[4,5],[6,7]]])
- assert (swapaxes(x,0,2) == array([[[0, 4], [2, 6]],
+ assert (swapaxes(x,0,2) == array([[[0, 4], [2, 6]],
[[1, 5], [3, 7]]])).all()
diff --git a/pypy/module/test_lib_pypy/numpypy/test_numpy.py
b/pypy/module/test_lib_pypy/numpypy/test_numpy.py
--- a/pypy/module/test_lib_pypy/numpypy/test_numpy.py
+++ b/pypy/module/test_lib_pypy/numpypy/test_numpy.py
@@ -2,47 +2,6 @@
import py, sys
from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
-class AppTestNumpyImport1(object):
- spaceconfig = dict(usemodules=['micronumpy'])
-
- @classmethod
- def setup_class(cls):
- if option.runappdirect and '__pypy__' not in sys.builtin_module_names:
- py.test.skip("pypy only test")
-
- def test_imports_no_warning(self):
- from warnings import catch_warnings
- with catch_warnings(record=True) as w:
- import numpypy
- import numpy
- assert len(w) == 0
- import numpy
- assert len(w) == 0
-
-class AppTestNumpyImport2(object):
- spaceconfig = dict(usemodules=['micronumpy'])
-
- @classmethod
- def setup_class(cls):
- if option.runappdirect and '__pypy__' not in sys.builtin_module_names:
- py.test.skip("pypy only test")
-
- def test_imports_with_warning(self):
- import sys
- from warnings import catch_warnings
- # XXX why are numpypy and numpy modules already imported?
- mods = [d for d in sys.modules.keys() if d.find('numpy') >= 0]
- if mods:
- skip('%s already imported' % mods)
-
- with catch_warnings(record=True) as w:
- import numpy
- msg = w[0].message
- assert msg.message.startswith(
- "The 'numpy' module of PyPy is in-development")
- import numpy
- assert len(w) == 1
-
class AppTestNumpy(BaseNumpyAppTest):
def test_min_max_after_import(self):
import __builtin__
@@ -95,15 +54,15 @@
assert math.isnan(numpypy.nan)
def test___all__(self):
- import numpy
- assert '__all__' in dir(numpy)
- assert 'numpypy' not in dir(numpy)
+ import numpypy
+ assert '__all__' in dir(numpypy)
+ assert 'numpypy' not in dir(numpypy)
def test_get_include(self):
import sys
if not hasattr(sys, 'pypy_translation_info'):
skip("pypy white-box test")
- import numpy, os
- assert 'get_include' in dir(numpy)
- path = numpy.get_include()
+ import numpypy, os
+ assert 'get_include' in dir(numpypy)
+ path = numpypy.get_include()
assert os.path.exists(path + '/numpy/arrayobject.h')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit