-
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
Add real
specification for returning the real component of a complex number
#427
Conversation
So this PR should be merged after resolving #425. |
@leofang Yes, I would think so. |
I was looking for |
As |
Atm, the function, as spec'd, states that the input array "should have a complex floating-point data type". This affords array libraries some flexibility in allowing real-valued data types, as "should" is more lenient than "must". At this point, I don't think we should wait on #425, as data type inspection still lacks consensus. We should merge this as is so that array libraries can begin their spec compliant implementations, and we can revisit/make changes to the spec upon receiving feedback based on real-world implementations. |
Sounds good to me, as long as we are committed to get #425 done in the same year. |
As discussed in the Sept 22, 2022, consortium meeting, the plan is to merge this and #446 as is. We can revisit the decision to only support complex dtypes based on downstream library implementations and feedback should this prove problematic/undesirable. |
This PR
adds a specification for
real
, an API for returning the real component of a complex number for each elementx_i
of an input arrayx
.chooses to follow PyTorch in restricting the allowed input array data types to only complex floating-point data types. NumPy et al and TensorFlow allow both real- and complex-valued input array data types. For real-valued data types,
real(x)
is a no-op.An argument can be made that, as real numbers are a subset of complex numbers, when providing a real-valued array, this is equivalent to a complex number array whose imaginary components are all zeros. As such, any numeric array is a complex number array regardless of its storage data type.
This PR chooses to be more restrictive based on the premise that consumers should be explicit when performing a complex number operation (e.g., if real-valued inputs are allowed, was calling
real(x)
intentional when providing a real-valuedx
or was this an unintended bug wherex
should have been complex valued?). Given potential ambiguity between intended versus unintended behavior, this PR places the onus on consumers to resolve this ambiguity.Provided RFC: add data type inspection utilities to the array API specification #425 moves forward, array API consumers should have standardized means for inspecting array data types and branching accordingly. E.g.,
is dependent on Add complex floating-point data types #418 which adds complex floating-point data types to the specification.