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.

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.
@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.

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.

1 participant