Author: Stefan H. Muller <[email protected]>
Branch: pypy-pyarray
Changeset: r66341:3c29d99be539
Date: 2013-08-05 05:03 +0200
http://bitbucket.org/pypy/pypy/changeset/3c29d99be539/
Log: - lib_pypy/numpypy/__init__.py: __version__ and get_include() now
defined here, so that site-packages/numpy can get it.
- lib_pypy/numpy.py: Contains only the warning. This file should be
shadowed if site-packages/numpy is installed. It presently isn't so
it must be renamed.
- cpyext/include/complexobject.h: Fix error in macro usage.
- micronumpy/base.py: convert_to_array(): Add call to __array__()
method, if it exists.
diff --git a/lib_pypy/numpy.py b/lib_pypy/numpy.py
--- a/lib_pypy/numpy.py
+++ b/lib_pypy/numpy.py
@@ -6,11 +6,4 @@
from numpypy import *
-import os
-__version__ = '1.6.2'
-
-def get_include():
- head, tail = os.path.split(os.path.dirname(os.path.abspath(__file__)))
- return os.path.join(head, 'include')
-
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
@@ -6,9 +6,19 @@
from __builtin__ import bool, int, long, float, complex, object, unicode, str
from core import abs, max, min
-__all__ = []
+__version__ = '1.7.0'
+
+import os
+def get_include():
+ head, tail = os.path.split(os.path.dirname(os.path.abspath(__file__)))
+ return os.path.join(head, '../include')
+
+
+__all__ = ['__version__', 'get_include']
__all__ += core.__all__
__all__ += lib.__all__
#import sys
#sys.modules.setdefault('numpy', sys.modules['numpypy'])
+
+
diff --git a/pypy/module/cpyext/include/complexobject.h
b/pypy/module/cpyext/include/complexobject.h
--- a/pypy/module/cpyext/include/complexobject.h
+++ b/pypy/module/cpyext/include/complexobject.h
@@ -28,7 +28,7 @@
// shmuller 2013/07/30: Make a function, since macro will fail in C++ due to
// const correctness if called with "const Py_complex"
//#define PyComplex_FromCComplex(c) _PyComplex_FromCComplex(&c)
-Py_LOCAL_INLINE(PyObject) *PyComplex_FromCComplex(Py_complex c) {
+Py_LOCAL_INLINE(PyObject *) PyComplex_FromCComplex(Py_complex c) {
return _PyComplex_FromCComplex(&c);
}
diff --git a/pypy/module/micronumpy/base.py b/pypy/module/micronumpy/base.py
--- a/pypy/module/micronumpy/base.py
+++ b/pypy/module/micronumpy/base.py
@@ -1,4 +1,5 @@
+from pypy.interpreter.error import OperationError
from pypy.interpreter.baseobjspace import W_Root
from rpython.tool.pairtype import extendabletype
from pypy.module.micronumpy.support import calc_strides
@@ -91,10 +92,20 @@
if isinstance(w_obj, W_NDimArray):
return w_obj
- elif issequence_w(space, w_obj):
- # Convert to array.
- return array(space, w_obj, w_order=None)
else:
- # If it's a scalar
- dtype = interp_ufuncs.find_dtype_for_scalar(space, w_obj)
- return W_NDimArray.new_scalar(space, dtype, w_obj)
+ # Use __array__() method if it exists
+ w_array = space.lookup(w_obj, "__array__")
+ if w_array is not None:
+ w_result = space.get_and_call_function(w_array, w_obj)
+ if isinstance(w_result, W_NDimArray):
+ return w_result
+ else:
+ raise OperationError(space.w_ValueError,
+ space.wrap("object __array__ method not producing an
array"))
+ elif issequence_w(space, w_obj):
+ # Convert to array.
+ return array(space, w_obj, w_order=None)
+ else:
+ # If it's a scalar
+ dtype = interp_ufuncs.find_dtype_for_scalar(space, w_obj)
+ return W_NDimArray.new_scalar(space, dtype, w_obj)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit