Commit 3a7fafdb authored by Matti Picus's avatar Matti Picus Committed by GitHub

Use properties in numpy.pxd to avoid a dependency on internal details (GH-3365)

parent 6a4a0ada
...@@ -244,14 +244,27 @@ cdef extern from "numpy/arrayobject.h": ...@@ -244,14 +244,27 @@ cdef extern from "numpy/arrayobject.h":
cdef: cdef:
# Only taking a few of the most commonly used and stable fields. # Only taking a few of the most commonly used and stable fields.
# One should use PyArray_* macros instead to access the C fields.
char *data char *data
int ndim "nd"
npy_intp *shape "dimensions"
npy_intp *strides
dtype descr # deprecated since NumPy 1.7 ! dtype descr # deprecated since NumPy 1.7 !
PyObject* base PyObject* base
@property
cdef int ndim(self):
return PyArray_NDIM(self)
@property
cdef npy_intp *shape(self):
return PyArray_DIMS(self)
@property
cdef npy_intp *strides(self):
return PyArray_STRIDES(self)
@property
cdef npy_intp size(self):
return PyArray_SIZE(ndarray)
# Note: This syntax (function definition in pxd files) is an # Note: This syntax (function definition in pxd files) is an
# experimental exception made for __getbuffer__ and __releasebuffer__ # experimental exception made for __getbuffer__ and __releasebuffer__
# -- the details of this may change. # -- the details of this may change.
......
# tag: numpy_old # tag: numpy
# You can ignore the previous line. # You can ignore the previous line.
# It's for internal testing of the cython documentation. # It's for internal testing of the cython documentation.
......
...@@ -136,7 +136,6 @@ def get_distutils_distro(_cache=[]): ...@@ -136,7 +136,6 @@ def get_distutils_distro(_cache=[]):
EXT_DEP_MODULES = { EXT_DEP_MODULES = {
'tag:numpy': 'numpy', 'tag:numpy': 'numpy',
'tag:numpy_old': 'numpy',
'tag:pythran': 'pythran', 'tag:pythran': 'pythran',
'tag:setuptools': 'setuptools.sandbox', 'tag:setuptools': 'setuptools.sandbox',
'tag:asyncio': 'asyncio', 'tag:asyncio': 'asyncio',
...@@ -256,10 +255,6 @@ def update_linetrace_extension(ext): ...@@ -256,10 +255,6 @@ def update_linetrace_extension(ext):
return ext return ext
def update_old_numpy_extension(ext):
update_numpy_extension(ext, set_api17_macro=False)
def update_numpy_extension(ext, set_api17_macro=True): def update_numpy_extension(ext, set_api17_macro=True):
import numpy import numpy
from numpy.distutils.misc_util import get_info from numpy.distutils.misc_util import get_info
...@@ -400,7 +395,6 @@ EXCLUDE_EXT = object() ...@@ -400,7 +395,6 @@ EXCLUDE_EXT = object()
EXT_EXTRAS = { EXT_EXTRAS = {
'tag:numpy' : update_numpy_extension, 'tag:numpy' : update_numpy_extension,
'tag:numpy_old' : update_old_numpy_extension,
'tag:openmp': update_openmp_extension, 'tag:openmp': update_openmp_extension,
'tag:cpp11': update_cpp11_extension, 'tag:cpp11': update_cpp11_extension,
'tag:trace' : update_linetrace_extension, 'tag:trace' : update_linetrace_extension,
......
# ticket: 155 # ticket: 155
# tag: numpy_old # tag: numpy
""" """
>>> myfunc() >>> myfunc()
...@@ -17,4 +17,3 @@ def myfunc(): ...@@ -17,4 +17,3 @@ def myfunc():
A[i, :] /= 2 A[i, :] /= 2
return A[0,0] return A[0,0]
include "numpy_common.pxi"
...@@ -6,4 +6,3 @@ ...@@ -6,4 +6,3 @@
True True
""" """
cimport numpy as np cimport numpy as np
include "numpy_common.pxi"
# hack to avoid C compiler warnings about unused functions in the NumPy header files
cdef extern from *:
bint FALSE "0"
void import_array()
# void import_umath()
if FALSE:
import_array()
# import_umath()
# tag: numpy_old # tag: numpy
# tag: openmp # tag: openmp
cimport cython cimport cython
from cython.parallel import prange from cython.parallel import prange
cimport numpy as np cimport numpy as np
include "numpy_common.pxi"
@cython.boundscheck(False) @cython.boundscheck(False)
......
# tag: numpy_old # tag: numpy
cimport numpy as np cimport numpy as np
cimport cython cimport cython
......
# tag: numpy_old # tag: numpy
# cannot be named "numpy" in order to not clash with the numpy module!
cimport numpy as np cimport numpy as np
cimport cython cimport cython
...@@ -945,5 +944,3 @@ def test_broadcast_comparison(np.ndarray[double, ndim=1] a): ...@@ -945,5 +944,3 @@ def test_broadcast_comparison(np.ndarray[double, ndim=1] a):
cdef object obj = a cdef object obj = a
return a == 0, obj == 0, a == 1, obj == 1 return a == 0, obj == 0, a == 1, obj == 1
include "numpy_common.pxi"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment