Skip to content

API: Fix compat header and add new import helpers#25866

Merged
ngoldbaum merged 2 commits intonumpy:mainfrom
seberg:fix-compat-and-import
Feb 26, 2024
Merged

API: Fix compat header and add new import helpers#25866
ngoldbaum merged 2 commits intonumpy:mainfrom
seberg:fix-compat-and-import

Conversation

@seberg
Copy link
Member

@seberg seberg commented Feb 21, 2024

This PR does three somewhat related things:

  1. I fixed the npy_2_compat.h so now it should work fine when backported.
  2. Add a short segment that some functionality moved (I don't want to add a full list now, since it'll grow, and it will be obvious anyway: you get a compilation error). This includes a warning to ensure you imported the API as otherwise things may fail cryptically unfortunately.
  3. The way import_array works is odd, as it includes the return statement, which IMO is terrible and misleading. I also wanted to tell downstream they can just import array judiciously without the need to figure out importing it exactly once at import time (which clearly nicer, but may not be trivial to update in all cases).
    Thus I added PyArray_ImportNumPyAPI and PyUFunc_ImportUFuncAPI as functions, the first is back-portable since otherwise I can't suggest to use it :).

I will double check the new pattern works for backporting (I assume it does, but marking as draft until I checked).

I believe this should alleviate the main problem with the arrfuncs PR, although it may be that the GETITEM and SETITEM macros need to move headers still.

@seberg seberg force-pushed the fix-compat-and-import branch from bfc333e to b75a069 Compare February 21, 2024 12:44
@seberg seberg marked this pull request as ready for review February 21, 2024 12:44
Copy link
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@treddy any chance you can see if vendoring the version of npy_2_compat.h in this PR in scipy causes issues like you saw before?

@seberg there are some changes related to string ufuncs that I think shouldn't be in this PR? Maybe need a rebase?

The current import functions are a bit silly as they are all macros
which immediately return on error.  Thus we really should have a new
helper anyway.

The one added also checks for whether the API was already imported
so that downstream can add it judiciously in case the proper setup
is more difficult.
@seberg seberg force-pushed the fix-compat-and-import branch from b75a069 to fa028cf Compare February 22, 2024 21:39
@seberg seberg force-pushed the fix-compat-and-import branch from fa028cf to 89be919 Compare February 22, 2024 21:40
@ngoldbaum
Copy link
Member

I like this just to have an idempotent function to import the API tables, LGTM. I'll wait to merge to give scipy folks a chance to look at this.

@charris
Copy link
Member

charris commented Feb 23, 2024

npy_2_compat.h so now it should work fine when backported.

What do you mean by backported?

Copy link
Contributor

@tylerjereddy tylerjereddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the following scenarios:

  • unmodified SciPy main alongside this branch of NumPy for both building and testing: full suite passes
  • SciPy main with the new npy_2_compat.h from this PR vendored in along with the includes I used in scipy/scipy#20108 (but without the ->f descr changes in SciPy or NumPy), using NumPy 1.26.4 for both build and test: full suite passes
  • SciPy main with those same changes/includes, but built against this NumPy PR and tested against NumPy 1.26.4: full suite passes
  • SciPy main + same changes/includes, build and test against this PR branch: full suite passes

I didn't go as far as trying to revert the descr ->f reversion in gh-25862, because some of the same files are touched and may require deep expertise to resolve the conflicts the intended way.

@seberg
Copy link
Member Author

seberg commented Feb 24, 2024

What do you mean by backported?

I meant vendoring by users if they need new things (most of course shouldn't but arrfuns or user dtypes requires need it; arrfuns should not be super common since get/setitem have existing macros).

@seberg
Copy link
Member Author

seberg commented Feb 26, 2024

Is there any doubt about adding the new idempotent (and actual) inline functions for importing? Because if this is delayed due to that, I would just take it out, even if I think it is useful.

@ngoldbaum
Copy link
Member

I think we're just low on reviewer bandwidth at the moment. I was sick on Friday and tried to take it easy this weekend so haven't had a chance to take a look at this again until now.

Let's pull this in, we can iterate on the new functions if people object later.

@ngoldbaum ngoldbaum merged commit 8c2584d into numpy:main Feb 26, 2024
@seberg seberg deleted the fix-compat-and-import branch February 26, 2024 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants