Skip to content

GH-50197: [C++][Python] Add "hypot" compute kernel#50198

Open
shrivasshankar wants to merge 1 commit into
apache:mainfrom
shrivasshankar:feature/add-hypot-kernel
Open

GH-50197: [C++][Python] Add "hypot" compute kernel#50198
shrivasshankar wants to merge 1 commit into
apache:mainfrom
shrivasshankar:feature/add-hypot-kernel

Conversation

@shrivasshankar

@shrivasshankar shrivasshankar commented Jun 16, 2026

Copy link
Copy Markdown

Rationale for this change

Arrow has atan2 and logb but no hypot. Computing a Euclidean norm currently needs sqrt(add(multiply(x, x), multiply(y, y))), which can overflow at the multiply step even when the result is representable.

What changes are included in this PR?

Add a hypot kernel backed by std::hypot (float32/float64, with integer/decimal inputs promoted to float64), the Hypot() C++ function, a FunctionDoc and compute.rst entry, and a Python expression test. pc.hypot is auto-exposed from the registry.

Are these changes tested?

Yes, C++ tests for the basic cases, null/NaN/Inf handling, and an overflow case confirming it doesn't fall back to a naive sqrt(x*x + y*y).

Are there any user-facing changes?

Yes, a new hypot function in C++ and Python. Additive only.

@github-actions github-actions Bot added the awaiting review Awaiting review label Jun 16, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #50197 has no components, please add labels for components.

Add a binary floating-point compute function "hypot" that computes the
hypotenuse sqrt(x^2 + y^2) without undue overflow or underflow at
intermediate stages, mirroring numpy.hypot and std::hypot.

The kernel reuses the existing MakeArithmeticFunctionFloatingPoint
factory (as atan2 does), registering float32 and float64 kernels and
promoting integer/decimal inputs to float64 via DispatchBest. Also adds
the Hypot() convenience function and declaration, a FunctionDoc, C++
tests (including an overflow-safety test that exercises inputs whose
squares overflow float32), a compute.rst entry, and pyarrow expression
coverage.
@shrivasshankar

Copy link
Copy Markdown
Author

i rebased on main @pitrou could you check this out

@rok

rok commented Jun 24, 2026

Copy link
Copy Markdown
Member

This looks good. Consider adding hypot to the python docs too:

Trigonometric Functions
-----------------------
Trigonometric functions are also supported, and also offer ``_checked``
variants which detect domain errors where appropriate.
.. autosummary::
:toctree: ../generated/
acos
acos_checked
asin
asin_checked
atan
atan2
cos
cos_checked
sin
sin_checked
tan
tan_checked

Comment on lines +374 to +375
static_assert(std::is_same<T, Arg0>::value, "");
static_assert(std::is_same<Arg0, Arg1>::value, "");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All all these assertions necessary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants