-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
consistently call import_array() after cimport of numpy #17054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @grlee77 ! Yes, there seem to be a few related reports on the Cython side lately e.g. cython/cython#3520. In Cython 3 cython/cython#3524 should fix it, but meanwhile this LGTM.
I think that we also need to make sure that we include the headers in the setups for each cython extension using the cython numpy api: There are files where you added the import_array even though we don't use the ndarray api at all, in |
Shouldn't it fail at compilation time if headers are missing, though?
Are you sure memoryviews don't interact with numpy at all? |
right
I'm almost sure but couldn't find confirmation in the docs. |
@jeremiedbb does this have your approval? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. We can put this for the release and check when it's really necessary to cimport numpy afterwards
thanks @grlee77 ! |
Reference Issues/PRs
This might help with #16956, although I have not verified on ppc64le. Even if it does not fully resolve the issue, it seems that these calls to
import_array
are recommended by Cython.We had the same issue as #16956 in the
PyWavelets
feedstock where ppc64le+pypy would crash, and adding calls toimport_array
fixed the issue. We also saw a similar issue on x86 with cython 3.0a1 in scikit-image where adding these resolved the segfaults.What does this implement/fix? Explain your changes.
After calls to
cimport numpy as np
in Cython there should also be a call tonp.import_array()
.This is done many places in
scikit-learn
already. This PR aims to add it to the remaining files where it was missing (with a few exceptions in.pxd
files when the corresponding.pyx
file already had such a call)Any other comments?