[pypy-commit] pypy pypy-pyarray: - cpyext/ndarrayobject.py: Rename PyArray_* routines to _PyArray_* to
shmuller
noreply at buildbot.pypy.org
Fri Aug 2 12:19:13 CEST 2013
Author: Stefan H. Muller <shmueller2 at gmail.com>
Branch: pypy-pyarray
Changeset: r65897:bf28f2841084
Date: 2013-07-28 21:49 +0200
http://bitbucket.org/pypy/pypy/changeset/bf28f2841084/
Log: - cpyext/ndarrayobject.py: Rename PyArray_* routines to _PyArray_*
to avoid name clashes with other implementations of numpy in the
future.
diff --git a/pypy/module/cpyext/include/numpy/arrayobject.h b/pypy/module/cpyext/include/numpy/arrayobject.h
--- a/pypy/module/cpyext/include/numpy/arrayobject.h
+++ b/pypy/module/cpyext/include/numpy/arrayobject.h
@@ -17,6 +17,23 @@
#define import_array()
#endif
+#ifndef PyArray_NDIM
+
+#define PyArray_NDIM _PyArray_NDIM
+#define PyArray_DIM _PyArray_DIM
+#define PyArray_SIZE _PyArray_SIZE
+#define PyArray_ITEMSIZE _PyArray_ITEMSIZE
+#define PyArray_NBYTES _PyArray_NBYTES
+#define PyArray_TYPE _PyArray_TYPE
+#define PyArray_DATA _PyArray_DATA
+#define PyArray_FromAny _PyArray_FromAny
+
+#define PyArray_SimpleNew _PyArray_SimpleNew
+#define PyArray_SimpleNewFromData _PyArray_SimpleNewFromData
+#define PyArray_SimpleNewFromDataOwning _PyArray_SimpleNewFromDataOwning
+
+#endif
+
/* copied from numpy/ndarraytypes.h
* keep numbers in sync with micronumpy.interp_dtype.DTypeCache
*/
diff --git a/pypy/module/cpyext/ndarrayobject.py b/pypy/module/cpyext/ndarrayobject.py
--- a/pypy/module/cpyext/ndarrayobject.py
+++ b/pypy/module/cpyext/ndarrayobject.py
@@ -13,38 +13,38 @@
# the asserts are needed, otherwise the translation fails
@cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
-def PyArray_NDIM(space, w_array):
+def _PyArray_NDIM(space, w_array):
assert isinstance(w_array, W_NDimArray)
return len(w_array.get_shape())
@cpython_api([PyObject, Py_ssize_t], Py_ssize_t, error=CANNOT_FAIL)
-def PyArray_DIM(space, w_array, n):
+def _PyArray_DIM(space, w_array, n):
assert isinstance(w_array, W_NDimArray)
return w_array.get_shape()[n]
@cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
-def PyArray_SIZE(space, w_array):
+def _PyArray_SIZE(space, w_array):
assert isinstance(w_array, W_NDimArray)
return w_array.get_size()
@cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
-def PyArray_ITEMSIZE(space, w_array):
+def _PyArray_ITEMSIZE(space, w_array):
assert isinstance(w_array, W_NDimArray)
return w_array.get_dtype().get_size()
@cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
-def PyArray_NBYTES(space, w_array):
+def _PyArray_NBYTES(space, w_array):
assert isinstance(w_array, W_NDimArray)
return w_array.get_size() * w_array.get_dtype().get_size()
@cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
-def PyArray_TYPE(space, w_array):
+def _PyArray_TYPE(space, w_array):
assert isinstance(w_array, W_NDimArray)
return w_array.get_dtype().num
@cpython_api([PyObject], rffi.VOIDP, error=CANNOT_FAIL)
-def PyArray_DATA(space, w_array):
+def _PyArray_DATA(space, w_array):
# fails on scalars - see PyArray_FromAny()
assert isinstance(w_array, W_NDimArray)
return rffi.cast(rffi.VOIDP, w_array.implementation.storage)
@@ -52,7 +52,7 @@
@cpython_api([PyObject, rffi.VOIDP, Py_ssize_t, Py_ssize_t, Py_ssize_t, rffi.VOIDP],
PyObject)
-def PyArray_FromAny(space, w_obj, dtype, min_depth, max_depth, requirements, context):
+def _PyArray_FromAny(space, w_obj, dtype, min_depth, max_depth, requirements, context):
# ignore all additional arguments for now
w_array = convert_to_array(space, w_obj)
if w_array.is_scalar():
@@ -69,7 +69,7 @@
@cpython_api([Py_ssize_t, rffi.LONGP, Py_ssize_t], PyObject)
-def PyArray_SimpleNew(space, nd, dims, typenum):
+def _PyArray_SimpleNew(space, nd, dims, typenum):
dtype = get_dtype_cache(space).dtypes_by_num[typenum]
shape = []
for i in range(nd):
@@ -94,11 +94,11 @@
return W_NDimArray.from_shape_and_storage(space, shape, storage, dtype, owning=owning)
@cpython_api([Py_ssize_t, rffi.LONGP, Py_ssize_t, rffi.VOIDP], PyObject)
-def PyArray_SimpleNewFromData(space, nd, dims, typenum, data):
+def _PyArray_SimpleNewFromData(space, nd, dims, typenum, data):
return simple_new_from_data(space, nd, dims, typenum, data, owning=False)
@cpython_api([Py_ssize_t, rffi.LONGP, Py_ssize_t, rffi.VOIDP], PyObject)
-def PyArray_SimpleNewFromDataOwning(space, nd, dims, typenum, data):
+def _PyArray_SimpleNewFromDataOwning(space, nd, dims, typenum, data):
# Variant to take over ownership of the memory, equivalent to:
# PyObject *arr = PyArray_SimpleNewFromData(nd, dims, typenum, data);
# ((PyArrayObject*)arr)->flags |= NPY_OWNDATA;
diff --git a/pypy/module/cpyext/test/test_ndarrayobject.py b/pypy/module/cpyext/test/test_ndarrayobject.py
--- a/pypy/module/cpyext/test/test_ndarrayobject.py
+++ b/pypy/module/cpyext/test/test_ndarrayobject.py
@@ -26,31 +26,31 @@
def test_NDIM(self, space, api):
a = array(space, [10, 5, 3])
- assert api.PyArray_NDIM(a) == 3
+ assert api._PyArray_NDIM(a) == 3
def test_DIM(self, space, api):
a = array(space, [10, 5, 3])
- assert api.PyArray_DIM(a, 1) == 5
+ assert api._PyArray_DIM(a, 1) == 5
def test_SIZE(self, space, api):
a = array(space, [10, 5, 3])
- assert api.PyArray_SIZE(a) == 150
+ assert api._PyArray_SIZE(a) == 150
def test_ITEMSIZE(self, space, api):
a = array(space, [10, 5, 3])
- assert api.PyArray_ITEMSIZE(a) == 8
+ assert api._PyArray_ITEMSIZE(a) == 8
def test_NBYTES(self, space, api):
a = array(space, [10, 5, 3])
- assert api.PyArray_NBYTES(a) == 1200
+ assert api._PyArray_NBYTES(a) == 1200
def test_TYPE(self, space, api):
a = array(space, [10, 5, 3])
- assert api.PyArray_TYPE(a) == 12
+ assert api._PyArray_TYPE(a) == 12
def test_DATA(self, space, api):
a = array(space, [10, 5, 3])
- addr = api.PyArray_DATA(a)
+ addr = api._PyArray_DATA(a)
addr2 = rffi.cast(rffi.VOIDP, a.implementation.storage)
assert addr == addr2
@@ -58,15 +58,15 @@
a0 = scalar(space)
assert a0.implementation.get_scalar_value().value == 10.
- a = api.PyArray_FromAny(a0, NULL, 0, 0, 0, NULL)
- assert api.PyArray_NDIM(a) == 0
+ a = api._PyArray_FromAny(a0, NULL, 0, 0, 0, NULL)
+ assert api._PyArray_NDIM(a) == 0
- ptr = rffi.cast(rffi.DOUBLEP, api.PyArray_DATA(a))
+ ptr = rffi.cast(rffi.DOUBLEP, api._PyArray_DATA(a))
assert ptr[0] == 10.
def test_FromAny(self, space, api):
a = array(space, [10, 5, 3])
- assert api.PyArray_FromAny(a, NULL, 0, 0, 0, NULL) is a
+ assert api._PyArray_FromAny(a, NULL, 0, 0, 0, NULL) is a
def test_list_from_fixedptr(self, space, api):
A = lltype.GcArray(lltype.Float)
@@ -81,7 +81,7 @@
def test_list_from_openptr(self, space, api):
nd = 3
a = array(space, [nd])
- ptr = rffi.cast(rffi.DOUBLEP, api.PyArray_DATA(a))
+ ptr = rffi.cast(rffi.DOUBLEP, api._PyArray_DATA(a))
ptr[0] = 10.
ptr[1] = 5.
ptr[2] = 3.
@@ -92,7 +92,7 @@
def test_SimpleNew_scalar(self, space, api):
ptr_s = lltype.nullptr(rffi.LONGP.TO)
- a = api.PyArray_SimpleNew(0, ptr_s, 12)
+ a = api._PyArray_SimpleNew(0, ptr_s, 12)
dtype = get_dtype_cache(space).w_float64dtype
@@ -101,15 +101,15 @@
def test_SimpleNewFromData_scalar(self, space, api):
a = array(space, [1])
- num = api.PyArray_TYPE(a)
- ptr_a = api.PyArray_DATA(a)
+ num = api._PyArray_TYPE(a)
+ ptr_a = api._PyArray_DATA(a)
x = rffi.cast(rffi.DOUBLEP, ptr_a)
x[0] = float(10.)
ptr_s = lltype.nullptr(rffi.LONGP.TO)
- res = api.PyArray_SimpleNewFromData(0, ptr_s, num, ptr_a)
+ res = api._PyArray_SimpleNewFromData(0, ptr_s, num, ptr_a)
assert res.is_scalar()
assert res.get_scalar_value().value == 10.
@@ -118,16 +118,16 @@
nd = len(shape)
s = iarray(space, [nd])
- ptr_s = rffi.cast(rffi.LONGP, api.PyArray_DATA(s))
+ ptr_s = rffi.cast(rffi.LONGP, api._PyArray_DATA(s))
ptr_s[0] = 10
ptr_s[1] = 5
ptr_s[2] = 3
- a = api.PyArray_SimpleNew(nd, ptr_s, 12)
+ a = api._PyArray_SimpleNew(nd, ptr_s, 12)
- #assert list(api.PyArray_DIMS(a))[:3] == shape
+ #assert list(api._PyArray_DIMS(a))[:3] == shape
- ptr_a = api.PyArray_DATA(a)
+ ptr_a = api._PyArray_DATA(a)
x = rffi.cast(rffi.DOUBLEP, ptr_a)
for i in range(150):
@@ -141,31 +141,31 @@
nd = len(shape)
s = iarray(space, [nd])
- ptr_s = rffi.cast(rffi.LONGP, api.PyArray_DATA(s))
+ ptr_s = rffi.cast(rffi.LONGP, api._PyArray_DATA(s))
ptr_s[0] = 10
ptr_s[1] = 5
ptr_s[2] = 3
a = array(space, shape)
- num = api.PyArray_TYPE(a)
- ptr_a = api.PyArray_DATA(a)
+ num = api._PyArray_TYPE(a)
+ ptr_a = api._PyArray_DATA(a)
x = rffi.cast(rffi.DOUBLEP, ptr_a)
for i in range(150):
x[i] = float(i)
- res = api.PyArray_SimpleNewFromData(nd, ptr_s, num, ptr_a)
- assert api.PyArray_TYPE(res) == num
- assert api.PyArray_DATA(res) == ptr_a
+ res = api._PyArray_SimpleNewFromData(nd, ptr_s, num, ptr_a)
+ assert api._PyArray_TYPE(res) == num
+ assert api._PyArray_DATA(res) == ptr_a
for i in range(nd):
- assert api.PyArray_DIM(res, i) == shape[i]
- ptr_r = rffi.cast(rffi.DOUBLEP, api.PyArray_DATA(res))
+ assert api._PyArray_DIM(res, i) == shape[i]
+ ptr_r = rffi.cast(rffi.DOUBLEP, api._PyArray_DATA(res))
for i in range(150):
assert ptr_r[i] == float(i)
def test_SimpleNewFromData_complex(self, space, api):
a = array(space, [2])
- ptr_a = api.PyArray_DATA(a)
+ ptr_a = api._PyArray_DATA(a)
x = rffi.cast(rffi.DOUBLEP, ptr_a)
x[0] = 3.
@@ -173,7 +173,7 @@
ptr_s = lltype.nullptr(rffi.LONGP.TO)
- res = api.PyArray_SimpleNewFromData(0, ptr_s, 15, ptr_a)
+ res = api._PyArray_SimpleNewFromData(0, ptr_s, 15, ptr_a)
assert res.get_scalar_value().real == 3.
assert res.get_scalar_value().imag == 4.
More information about the pypy-commit
mailing list