Description
gh-427 summarizes the rationale for requiring that inputs to real
, imag
, and conj
be complex-valued:
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.
#446 (comment) states that this is open to being revisited.
If the concern is ambiguity between intended and unintended use, was there a similar discussion for functions that are no-ops for integers, such as round
and isinf
? It looks like the initial commit that added rounding functions already included the special case for integers, but I couldn't find a discussion about it.
Perhaps it didn't come up because it is common for code paths that work on floating point dtypes to also be used for integer dtypes. In the same way, I'd suggest that code for complex dtypes can also be valid for real dtypes. If it is not easy to tell whether unintended or intended uses of these functions on real data is more common in the wild, perhaps the precedent set by NumPy and other libraries (e.g. CuPy, JAX, PyTorch, Dask Array, Tensorflow) is not wrong, and these functions can allow real input.