-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
API,MAINT: Make NpyIter_GetTransferFlags
public and avoid old uses
#27998
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.
LGTM, once it is rebased and tests pass.
numpy/_core/src/multiarray/ctors.c
Outdated
@@ -2795,7 +2786,8 @@ PyArray_CopyAsFlat(PyArrayObject *dst, PyArrayObject *src, NPY_ORDER order) | |||
NpyIter_Deallocate(src_iter); | |||
return -1; | |||
} | |||
needs_api |= (flags & NPY_METH_REQUIRES_PYAPI) != 0; | |||
/* No need to worry about API use in unbuffered iterator */ | |||
needs_api = (flags & NPY_METH_REQUIRES_PYAPI) != 0; |
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.
Should probably declare and set the value together.
needs_api = (flags & NPY_METH_REQUIRES_PYAPI) != 0; | |
int needs_api = (flags & NPY_METH_REQUIRES_PYAPI) != 0; |
This makes NpyIter_IterationNeedsAPI public, since there is no reason not to now that the flags are public.
…here Also remove any duplicate calls which are now much slower.
efd6688
to
71e33fd
Compare
Ping @ngoldbaum for awareness though, since it adds the public function. Also, will push one small change: The return value should be |
OK, put this in very happy to follow up if the docs should be improved (or anything else). |
This combines two related things:
NpyIter_GetTransferFlags
a public function. Now that we have these flags in the public API, there seems no reason not to make this public.NEEDS_API
flag every time (withREFS_OK
) for use inNpyIter_IterationNeedsAPI
. But we should generally not useNpyIter_IterationNeedsAPI
anymore in NumPy. The reason is that we need to know what buffering needs, but already know anyway if we need the API for whatever we do with the dtypes. So:NpyIter_IterationNeedsAPI
so that we avoid the unnecessary flag discovery (at least in throttled CPU mode ~5% of a trivial reduce).I completely removed one macro, because I didn't want the confusion of which version is used (or two macros).
This is ready for review, but marking as draft, because the reduce code move is probably only safe after gh-27883. (if we are lucky, the sanitizer CI run notices this)