Author: Brian Kearns <[email protected]>
Branch:
Changeset: r67380:c65912c9d433
Date: 2013-10-15 01:16 -0400
http://bitbucket.org/pypy/pypy/changeset/c65912c9d433/
Log: clean up some more numpy imports/work towards compat with upstream
numpy code
diff --git a/lib_pypy/numpypy/core/__init__.py
b/lib_pypy/numpypy/core/__init__.py
--- a/lib_pypy/numpypy/core/__init__.py
+++ b/lib_pypy/numpypy/core/__init__.py
@@ -1,12 +1,16 @@
-import numeric
-from numeric import *
-import fromnumeric
-from fromnumeric import *
-import shape_base
-from shape_base import *
+from __future__ import division, absolute_import, print_function
-from fromnumeric import amax as max, amin as min
-from numeric import absolute as abs
+from . import multiarray
+from . import umath
+from . import numeric
+from .numeric import *
+from . import fromnumeric
+from .fromnumeric import *
+from . import shape_base
+from .shape_base import *
+
+from .fromnumeric import amax as max, amin as min
+from .numeric import absolute as abs
__all__ = []
__all__ += numeric.__all__
diff --git a/lib_pypy/numpypy/core/numeric.py b/lib_pypy/numpypy/core/numeric.py
--- a/lib_pypy/numpypy/core/numeric.py
+++ b/lib_pypy/numpypy/core/numeric.py
@@ -1,3 +1,5 @@
+from __future__ import division, absolute_import, print_function
+
__all__ = [
'newaxis', 'ufunc',
'asarray', 'asanyarray', 'base_repr',
@@ -8,14 +10,14 @@
]
import sys
-import multiarray
-from multiarray import *
+from . import multiarray
+from .multiarray import *
del set_string_function
del typeinfo
-import umath
-from umath import *
-import numerictypes
-from numerictypes import *
+from . import umath
+from .umath import *
+from . import numerictypes
+from .numerictypes import *
def extend_all(module):
adict = {}
@@ -41,6 +43,76 @@
def seterr(**args):
return args
+def asarray(a, dtype=None, order=None):
+ """
+ Convert the input to an array.
+
+ Parameters
+ ----------
+ a : array_like
+ Input data, in any form that can be converted to an array. This
+ includes lists, lists of tuples, tuples, tuples of tuples, tuples
+ of lists and ndarrays.
+ dtype : data-type, optional
+ By default, the data-type is inferred from the input data.
+ order : {'C', 'F'}, optional
+ Whether to use row-major ('C') or column-major ('F' for FORTRAN)
+ memory representation. Defaults to 'C'.
+
+ Returns
+ -------
+ out : ndarray
+ Array interpretation of `a`. No copy is performed if the input
+ is already an ndarray. If `a` is a subclass of ndarray, a base
+ class ndarray is returned.
+
+ See Also
+ --------
+ asanyarray : Similar function which passes through subclasses.
+ ascontiguousarray : Convert input to a contiguous array.
+ asfarray : Convert input to a floating point ndarray.
+ asfortranarray : Convert input to an ndarray with column-major
+ memory order.
+ asarray_chkfinite : Similar function which checks input for NaNs and Infs.
+ fromiter : Create an array from an iterator.
+ fromfunction : Construct an array by executing a function on grid
+ positions.
+
+ Examples
+ --------
+ Convert a list into an array:
+
+ >>> a = [1, 2]
+ >>> np.asarray(a)
+ array([1, 2])
+
+ Existing arrays are not copied:
+
+ >>> a = np.array([1, 2])
+ >>> np.asarray(a) is a
+ True
+
+ If `dtype` is set, array is copied only if dtype does not match:
+
+ >>> a = np.array([1, 2], dtype=np.float32)
+ >>> np.asarray(a, dtype=np.float32) is a
+ True
+ >>> np.asarray(a, dtype=np.float64) is a
+ False
+
+ Contrary to `asanyarray`, ndarray subclasses are not passed through:
+
+ >>> issubclass(np.matrix, np.ndarray)
+ True
+ >>> a = np.matrix([[1, 2]])
+ >>> np.asarray(a) is a
+ False
+ >>> np.asanyarray(a) is a
+ True
+
+ """
+ return array(a, dtype, copy=False, order=order)
+
def asanyarray(a, dtype=None, order=None):
"""
Convert the input to an ndarray, but pass ndarray subclasses through.
@@ -148,7 +220,7 @@
#Use numarray's printing function
-from arrayprint import array2string
+from .arrayprint import array2string
_typelessdata = [int_, float_]#, complex_]
# XXX
@@ -381,76 +453,6 @@
return False
return bool((a1 == a2).all())
-def asarray(a, dtype=None, order=None):
- """
- Convert the input to an array.
-
- Parameters
- ----------
- a : array_like
- Input data, in any form that can be converted to an array. This
- includes lists, lists of tuples, tuples, tuples of tuples, tuples
- of lists and ndarrays.
- dtype : data-type, optional
- By default, the data-type is inferred from the input data.
- order : {'C', 'F'}, optional
- Whether to use row-major ('C') or column-major ('F' for FORTRAN)
- memory representation. Defaults to 'C'.
-
- Returns
- -------
- out : ndarray
- Array interpretation of `a`. No copy is performed if the input
- is already an ndarray. If `a` is a subclass of ndarray, a base
- class ndarray is returned.
-
- See Also
- --------
- asanyarray : Similar function which passes through subclasses.
- ascontiguousarray : Convert input to a contiguous array.
- asfarray : Convert input to a floating point ndarray.
- asfortranarray : Convert input to an ndarray with column-major
- memory order.
- asarray_chkfinite : Similar function which checks input for NaNs and Infs.
- fromiter : Create an array from an iterator.
- fromfunction : Construct an array by executing a function on grid
- positions.
-
- Examples
- --------
- Convert a list into an array:
-
- >>> a = [1, 2]
- >>> np.asarray(a)
- array([1, 2])
-
- Existing arrays are not copied:
-
- >>> a = np.array([1, 2])
- >>> np.asarray(a) is a
- True
-
- If `dtype` is set, array is copied only if dtype does not match:
-
- >>> a = np.array([1, 2], dtype=np.float32)
- >>> np.asarray(a, dtype=np.float32) is a
- True
- >>> np.asarray(a, dtype=np.float64) is a
- False
-
- Contrary to `asanyarray`, ndarray subclasses are not passed through:
-
- >>> issubclass(np.matrix, np.ndarray)
- True
- >>> a = np.matrix([[1, 2]])
- >>> np.asarray(a) is a
- False
- >>> np.asanyarray(a) is a
- True
-
- """
- return array(a, dtype, copy=False, order=order)
-
def outer(a,b):
"""
Compute the outer product of two vectors.
@@ -614,6 +616,6 @@
False_ = bool_(False)
True_ = bool_(True)
-import fromnumeric
-from fromnumeric import *
+from . import fromnumeric
+from .fromnumeric import *
extend_all(fromnumeric)
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,6 @@
from _numpypy.numerictypes import *
-from _numpypy.multiarray import dtype
+
+from .multiarray import dtype
def issubclass_(arg1, arg2):
"""
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit