Add support for computing the hypotenuse via `hypot`
See original GitHub issueThis RFC requests to include a new API in the array API specification for the purpose of computing the hypotenuse.
Based on array comparison data, the API is available across all major array libraries in the PyData ecosystem (note: TensorFlow implements hypot
in its experimental numpy
namespace).
While hypot
can be implemented in userland using existing array API functions (e.g., sqrt(x1*x1 + x2*x2)
), this function is typically implemented in a specialized manner to help prevent over/underflow.
Furthermore, need for this API arose when adding complex number support to the array API specification, particularly with regard to adding complex number support to abs
, where the absolute value (magnitude) of a complex number is computed as hypot(real(z), imag(z))
.
As this API already exists in the ecosystem and satisfies needs (e.g., numerical stability and complex number support), this API seems a good candidate for inclusion in the standard.
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
In terms of API, all supporting libraries implement as a standard element-wise binary function:
hypot(x1, x2)
, wherex1
andx2
follow conventional broadcast rules.As discussed last Thursday, the special cases for
abs
can be put in theabs
description. This is implemented in gh-546.We’re already nearing the end of 2022, and are close to finalizing the 2022 standard.
hypot
is not urgent enough to squeeze it in now, so let’s defer deciding on that till later. There’s a larger queue of suggested new APIs that needs considering in Q1.