Skip to content
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

RFC: add inspection support for querying the maximum number of supported dimensions #694

Closed
kgryte opened this issue Sep 25, 2023 · 5 comments · Fixed by #763
Closed

RFC: add inspection support for querying the maximum number of supported dimensions #694

kgryte opened this issue Sep 25, 2023 · 5 comments · Fixed by #763
Labels
Accepted RFC feature request which has been accepted. API extension Adds new functions or objects to the API. RFC Request for comments. Feature requests and proposed changes. topic: Inspection Array API inspection.
Milestone

Comments

@kgryte
Copy link
Contributor

kgryte commented Sep 25, 2023

In #640, we proposed adding a unified inspection API namespace, and, in that proposal, we included support for querying array library capabilities.

That RFC includes two capabilities:

  • data_dependent_shapes
  • boolean_indexing

In this RFC, I'd like to propose a third; namely, the ability to query the maximum number of supported dimensions. This RFC is related to #479, where it was requested that the specification provide better guidance regarding the minimum upper bound array rank. During Consortium working group meetings, a minimum upper bound of 4 has been discussed.

As such, different array libraries are likely to support different upper bounds, and downstream libraries should have an ergonomic means for determine what that upper bound is in order to ensure portable code. This RFC proposes that we add another field to the dictionary returned by info.capabilities(): max_rank.

As currently written, #640 requires dictionary values be booleans. This RFC would require that requirement to be relaxed, such that dictionary values may, in general, be any value, but specific dictionary keys must be assigned values of a particular type. In this case, max_rank should have an integer value.

@kgryte kgryte added the API extension Adds new functions or objects to the API. label Sep 25, 2023
@rgommers
Copy link
Member

Thanks @kgryte. Seems reasonable to me to add this.

In this case, max_rank should have an integer value.

It is not unlikely that there is no such value for some libraries, it may be infinite. If you can instantiate an empty array with a fixed memory cost rather than it increasing with the number of dimensions, there's no reason that there must be a max rank. So allow None?

@leofang
Copy link
Contributor

leofang commented Sep 25, 2023

IIRC PyTorch allows it to be infinite (through broadcast). But why not just use library-specific inf if it exists, or use the builtin float('inf')?

@seberg
Copy link
Contributor

seberg commented Sep 25, 2023

Allowing float('inf') sounds reasonable, although I doubt there is any lib at this time with truly no limit, it might just be somthing very large like 2**31 or even up to 2**64 (which is bigger than anything plausible anyway).

@rgommers
Copy link
Member

It doesn't matter too much, but Optional[int] communicates the intent better and seems a little nicer static typing-wise than Union[int, float] for something that inherently is an integer if it exists.

@leofang
Copy link
Contributor

leofang commented Sep 26, 2023

Sounds good to me. I support this RFC.

@kgryte kgryte added this to the v2023 milestone Nov 6, 2023
@kgryte kgryte modified the milestones: v2023, v2024 Feb 14, 2024
kgryte added a commit to kgryte/array-api that referenced this issue Mar 21, 2024
@kgryte kgryte added RFC Request for comments. Feature requests and proposed changes. topic: Inspection Array API inspection. Accepted RFC feature request which has been accepted. labels Apr 4, 2024
kgryte added a commit that referenced this issue May 2, 2024
PR-URL: #763
Closes: #694
Reviewed-by: Ralf Gommers <ralf.gommers@gmail.com>
Reviewed-by: Leo Fang <leo80042@gmail.com>
@github-project-automation github-project-automation bot moved this to Stage 2 in Proposals Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted RFC feature request which has been accepted. API extension Adds new functions or objects to the API. RFC Request for comments. Feature requests and proposed changes. topic: Inspection Array API inspection.
Projects
Status: Stage 2
Development

Successfully merging a pull request may close this issue.

4 participants