-
Notifications
You must be signed in to change notification settings - Fork 50
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
feat: add support for real-valued arrays in real
and conj
#884
base: main
Are you sure you want to change the base?
Conversation
@ev-br Thanks for opening this PR. My sense is that we should leave it unspecified and implementation-dependent. Forcing a copy is likely a no-go for libraries leveraging strided arrays and focused on performance. |
Agreed. Trying it on numpy, it seems that Nonetheless, allowing Therefore, the last commit updates the wording to make the view/semantics explicitly unspecified. |
A view is not a thing in the standard (xref https://data-apis.org/array-api/latest/design_topics/copies_views_and_mutation.html), so I don't think we will ever want to mandate anything here. View vs. copy is only observable when mutating aliased memory (which should be avoided) and otherwise a performance optimization that isn't visible in syntax or semantics. |
In principle, we could support a |
real
and conj
My only wish is that there's some wording, however mysterious, to show that the spec thought about the semantics and left it to be implementation-defined. For me as a user even "if you plac the output to the left of the assignment sign, the result is implementation-defined" would have been sufficient (and having no note would be worse). Re: forcing a copy with a keyword, I'd suggest to to have a minimal version in 2024.12 spec for downstream to use, and refine based on usage. |
Co-authored-by: Athan <[email protected]>
Okay, fine with the current wording then. We can always revise the details of the note later if needed. Just wanted to make sure that you're aware that a view isn't a concept, so we shouldn't overuse it. |
@ev-br I tweaked the language a bit, removing explicit mention of "views", and I also updated the guidance to require numeric input types. The previous guidance was "should" in order to allow libraries supporting real-valued dtypes to continue doing so. Now that we're expanding the scope of these functions to all numeric dtypes that wiggle room is no longer necessary. |
Closes #824 by allowing
real
andconj
to accept real-valued arrays, and leavingimag
to still require complex-valued arguments.One possibly thorny issue is whether
xp.real(x)
is a view or a copy of ofx
. This is also discussed in gh-824, not 100% sure what the resolution is though.In this PR, err on the side of caution and require that both
real
andconj
always return copies.Prior art is not very consistent AFAICS: numpy can return either a view or a copy depending on the dtype, not sure what other libraries do.
OTOH,
imag
to create a new array of zeros.