You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it make sense for NumPy to provide numpy.pxd and numpy/math.pxd (currently included in Cython)?
Given NumPy already ships SWIG bindings, providing Cython bindings seems reasonable and is not too different in concept. Plus there are already internal consumers of Cython bindings, which would likely benefit from having access to a single public API. Would add that other projects like SciPy have been adding a fair number of things in *.pxd files included in their public API making this a bit of a trend. This would certainly help build a framework for NumPy to expose other things in the public API. Finally would note that having the Cython bindings live in Cython complicates the process of keeping them up-to-date as they must provide support for various versions of NumPy, which should hopefully be less of a problem if Cython bindings were included in NumPy's public API.
Thoughts on this would be welcome. :)
Reacted by Ian Henriksen, scoder, Harshal Prakash Patankar (pharshalp), Mehdi H and Leo Fang
Sounds reasonable, and there is even a start in numpy/random/mtrand/numpy.pxd, which is used as include "numpy.pxd" in mtrand.pyx. I see that most code does not use the include statement rather the cython cimport: cimport numpy as np. How we would get the latter to use our wrapper over cython's wrapper? Would it be enough to encourage use of from numpy cimport numpy as np?
Should we pin tests to a certain version of cython, or would it be better to test against a range of cython versions (with the associated complications)?
It seems totally right to me to have NumPy maintain and ship its own Cython declarations, rather than letting Cython do it. Above all, the C-API that they describe depends on the NumPy version and not on the Cython version, and it's not Cython's decision when and how to deal with additions or incompatible changes.
For a migration, Cython already searches the include path before its own standard include directories, so as long as users pass numpy.get_includes() into Cython's build, and NumPy keeps its .pxd files in that path, Cython should pick up NumPy's own .pxd files first. We'd still have to keep the files on our side for a while so that users can Cython-translate their code with older NumPy versions, but at least there'd be a layed-out path towards removing them somewhere in the 2020's.
This came up again recently in regards to whether certain NumPy functions require the GIL and whether that is reflected correctly in the Cython API. ( cython/cython#2663 )
Side note: Some questions were raised regarding documentation of GIL use in NumPy's C API as well.
Activity
shoyer commentedon Aug 22, 2018
I think this would probably be a good idea.
rgommers commentedon Aug 23, 2018
Makes sense I think. The Cython wrappers in SciPy have been popular and unproblematic.
mattip commentedon Aug 23, 2018
Sounds reasonable, and there is even a start in
numpy/random/mtrand/numpy.pxd, which is used asinclude "numpy.pxd"inmtrand.pyx. I see that most code does not use theincludestatement rather the cython cimport:cimport numpy as np. How we would get the latter to use our wrapper over cython's wrapper? Would it be enough to encourage use offrom numpy cimport numpy as np?Should we pin tests to a certain version of cython, or would it be better to test against a range of cython versions (with the associated complications)?
bashtage commentedon Aug 23, 2018
Doesn't Cython already provide a lot of the NumPy API?
https://github.com/cython/cython/blob/master/Cython/Includes/numpy/__init__.pxd
mattip commentedon Aug 23, 2018
@bashtage I think this discussion began as cython/cython#2498, and now we need to decide what is easier:
scoder commentedon Sep 1, 2018
It seems totally right to me to have NumPy maintain and ship its own Cython declarations, rather than letting Cython do it. Above all, the C-API that they describe depends on the NumPy version and not on the Cython version, and it's not Cython's decision when and how to deal with additions or incompatible changes.
For a migration, Cython already searches the include path before its own standard include directories, so as long as users pass
numpy.get_includes()into Cython's build, and NumPy keeps its.pxdfiles in that path, Cython should pick up NumPy's own.pxdfiles first. We'd still have to keep the files on our side for a while so that users can Cython-translate their code with older NumPy versions, but at least there'd be a layed-out path towards removing them somewhere in the 2020's.jakirkham commentedon Oct 16, 2018
This came up again recently in regards to whether certain NumPy functions require the GIL and whether that is reflected correctly in the Cython API. ( cython/cython#2663 )
Side note: Some questions were raised regarding documentation of GIL use in NumPy's C API as well.