Tracking issue: Add array API standard support to the main namespace #25076
Copy link
Copy link
Closed
Description
See the slides from the NumPy 2.0 developer meeting in the numpy archive for an initial overview. That content has to be expanded into a NEP.
Backlog
Infra/support/docs
- a CI job that runs https://github.com/data-apis/array-api-tests/ on the main namespace (MAINT: Add
array-api-testsCI stage, addndarray.__array_namespace__#25167) - reference guide documentation
-
a user guide documentation page
main namespace
-
np.bool(API: Add and redefinenumpy.bool[Array API] #25080) -
np.astype(API: Introducenp.astype[Array API] #25079) -
unique_all,unique_counts,unique_inverse,unique_values(API: Add Array API setops [Array API] #25088) -
concat,permute_dims(API: Add Array API aliases (math, bitwise, linalg, misc) [Array API] #25086) - Trigonometric functions' aliases (API: Add Array API aliases (math, bitwise, linalg, misc) [Array API] #25086)
-
bitwise_left_shift,bitwise_right_shift,bitwise_invert(API: Add Array API aliases (math, bitwise, linalg, misc) [Array API] #25086) -
copykeyword argument fornp.asarray(API: Introducecopyargument fornp.asarray[Array API] #25168)
linalg namespace
- cross (API: Add
crosstonumpy.linalg[Array API] #25145) - matmul (API: Add Array API aliases (math, bitwise, linalg, misc) [Array API] #25086)
- matrix_norm (API: Add
matrix_norm,vector_norm,vecdotandmatrix_transpose[Array API] #25155) - matrix_transpose (API: Add
matrix_norm,vector_norm,vecdotandmatrix_transpose[Array API] #25155) - outer (API: Add
outertonumpy.linalg[Array API] #25101) - svdvals (API: Add
svdvalstonumpy.linalg[Array API] #24940) - tensordot (API: Add Array API aliases (math, bitwise, linalg, misc) [Array API] #25086)
- vecdot (API: Add
matrix_norm,vector_norm,vecdotandmatrix_transpose[Array API] #25155) - vector_norm (API: Add
matrix_norm,vector_norm,vecdotandmatrix_transpose[Array API] #25155)
ndarray methods and attributes
-
__array_namespace__method (MAINT: Addarray-api-testsCI stage, addndarray.__array_namespace__#25167) -
to_deviceanddevicemembers (API: Adddeviceandto_devicetonumpy.ndarray[Array API] #25233)
miscellaneous
-
correctionargument forvarandstd(API: Introducecorrectionargument fornp.varandnp.std[Array API] #25169) -
rtolparameter forpinvandupperparameter forcholesky(API: Adjustlinalg.pinvandlinalg.choleskyto Array API #25388)
Reactions are currently unavailable
Metadata
Metadata
Type
Projects
- StatusShow more project fields✅ Done
Activity
[-]Add array API standard support to the main namespace[/-][+]Tracking issue: Add array API standard support to the main namespace[/+]asmeurer commentedon Nov 6, 2023
This mailing list thread goes into details for some of the "easy and useful" changes https://mail.python.org/archives/list/[email protected]/thread/TTZEUKXUICDHGTCX5EMR6DQTYOSDGRV7/#YKBWQ2AP76WYWAP6GFRYMPHZCKTC43KM
seberg commentedon Nov 7, 2023
I would be very happy to hear any opinion here around adding aliases for functions or kwargs that do the exact same thing as existing ones. I don't dislike at least most of them.
But we do have a choice:
__array_namespace__definitions can differ from the normal definitions without making the transition story for libraries really harder, there is a certain symmetry to doing it maybe, but I still cannot see it as a necessity, so I think we should do whatever we think is best for users.rgommers commentedon Nov 8, 2023
It looks to me like that would require adding a whole new hidden namespace, rather then a simple
return numpy, potentially confusing, a lot of extra work, and the potential for extra bugs. Plus it would mean that the main namespace would actually not be compatible, which has other side effects. So that does not sound all that appealing. I'll add it to the NEP draft (ETA within a week; hard to keep up with Mateusz:)) as a design alternative though.mtsokol commentedon Nov 15, 2023
Hi! I'm finalizing the last
np.linalgArray API PR and I realized that althoughvecdot(vector dot) is available only innp.array_api:there's
np.vdotthat also claims to be a vector dot, but with completely different semantics (it ravels input to 1-D arrays, doesn't haveaxiskeyword and it'sComplex-conjugating dot product). I find it a bit confusing to havenp.vdotandnp.vecdot.What do you think about renaming
vdotto something else, likeconj_vecdot?rgommers commentedon Nov 16, 2023
vdotis a bit unfortunate indeed, but on the other hand we already have a lot of similar functions so adding yet another name perhaps does not help. The four array API functions should be orthogonal and complete, so I'd suggest applying the new.. legacy::admonition tovdotand de-emphasizing it when we reorganize the docs.2 remaining items
lucascolley commentedon Dec 16, 2023
also,
numpy.fft.{fftfreq, rfftfreq}need thedeviceparameter.jakevdp commentedon Jan 4, 2024
Another TODO to add here:
np.sort()andnp.argsort()need adescendingargument: https://data-apis.org/array-api/2022.12/API_specification/generated/array_api.sort.htmlI'm interested in what choice NumPy will make regarding the treatment of
NaNentries when sorted in descending order, as this is not specified by the array API, but we'd like to makejax.numpyfollow thenumpyimplementation in this respect.rgommers commentedon Jan 5, 2024
Good question. Whether
nans go at the beginning or the end forsortoutput is undefined on purpose, and in numpy they go at the end. For consistency, I'd expect fordescending=Falsethe whole array to be reversed, so thennans go at the beginning:jakevdp commentedon Jan 5, 2024
Great, thanks! That's exactly how I ended up implementing it here: jax-ml/jax#19201
NEP: add NEP 56 on array API standard support in main namespace
NEP: add NEP 56 on array API standard support in main namespace (#25542)
rgommers commentedon Mar 4, 2024
This is all done, so let's close this tracking issue. Thanks all!
mdhaber commentedon Dec 1, 2024
@rgommers Re: #25076 (comment), was closing this without
sort/argsorthaving adescendingkeyword intentional? Crossref gh-14728.rgommers commentedon Dec 2, 2024
Yes, intentional to close this tracking issue as "declaring victory for 2.0.0". For several of the loose ends we decided that individual issues could be used - tracking issues shouldn't stay open indefinitely.
IIRC
descendingwas investigated and determined that it was a lot of work (because ofnansorting, as noted in gh-14728) and hence we punted on that for 2.0. @mtsokol you may be able to add some extra color here (I thought there was discussion elsewhere aside from gh-14728, but can't remember where)?mtsokol commentedon Dec 2, 2024
Apart from that issue I had one attempt to implement it, here: mtsokol#5 but it turned out to be too much to bite at once. I also found another attempt here: #14989.
lucascolley commentedon Dec 2, 2024
shall we open a new issue to track it? Or are there other array API standard compatibility things tracked somewhere?
rgommers commentedon Dec 2, 2024
Please use gh-14728 for this
descendingone, adding content as needed.I'm not in favor of a permanent array API compatibility issue if that's what you meant, it'd be better to use the existing label for it.