Skip to content

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

Merged
rok merged 5 commits into
apache:mainfrom
shrivasshankar:feature/add-hypot-kernel
Jul 1, 2026
Merged

GH-50197: [C++][Python] Add "hypot" compute kernel#50198
rok merged 5 commits into
apache:mainfrom
shrivasshankar:feature/add-hypot-kernel

Conversation

@shrivasshankar

@shrivasshankar shrivasshankar commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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.

@shrivasshankar

Copy link
Copy Markdown
Contributor 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 thread cpp/src/arrow/compute/kernels/scalar_arithmetic.cc Outdated
@shrivasshankar shrivasshankar force-pushed the feature/add-hypot-kernel branch from 9568a77 to 7e74a4c Compare June 28, 2026 21:32
@shrivasshankar

Copy link
Copy Markdown
Contributor Author

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

added hypot to the python compute docs and rebased on main. Thanks for the review!

@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Jun 28, 2026

@rok rok left a comment

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.

This looks good. @pitrou could you do a pass?

@rok

rok commented Jun 29, 2026

Copy link
Copy Markdown
Member

@shrivasshankar I don't think the failures are related. Could you try rebasing?

@shrivasshankar shrivasshankar force-pushed the feature/add-hypot-kernel branch from 7e74a4c to bd4b80c Compare June 29, 2026 20:19
@shrivasshankar

shrivasshankar commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@shrivasshankar I don't think the failures are related. Could you try rebasing?

I rebased and it has to rerun

@shrivasshankar shrivasshankar requested a review from rok June 29, 2026 20:31
Comment thread python/pyarrow/tests/test_compute.py Outdated
@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Jun 29, 2026
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 shrivasshankar force-pushed the feature/add-hypot-kernel branch from bd4b80c to 6168525 Compare June 29, 2026 23:13
@github-actions github-actions Bot removed the awaiting changes Awaiting changes label Jun 29, 2026
@github-actions github-actions Bot added the awaiting change review Awaiting change review label Jun 29, 2026
Comment thread python/pyarrow/tests/test_compute.py Outdated
@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Jun 29, 2026

@rok rok left a comment

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.

I think this is good to go if CI passes.

Co-authored-by: Rok Mihevc <rok@mihevc.org>
@shrivasshankar

Copy link
Copy Markdown
Contributor Author

I think this is good to go if CI passes.

sounds good applying ur suggestion reset the CI again

@github-actions github-actions Bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jun 29, 2026
@shrivasshankar

Copy link
Copy Markdown
Contributor Author

@rok all pass besides 1 which seems to be a runner crash not a test failure

@rok

rok commented Jun 30, 2026

Copy link
Copy Markdown
Member

@pitrou I think this is ready to go, if you can please take a final look, I'd like to merge for this release.

Comment thread cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc
Comment thread cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc Outdated
@rok

rok commented Jun 30, 2026

Copy link
Copy Markdown
Member

@shrivasshankar would you consider adding two tests?

@rok rok left a comment

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.

Would like to add the two test cases before merging.

shrivasshankar and others added 2 commits June 30, 2026 19:06
Co-authored-by: Rok Mihevc <rok@mihevc.org>
Co-authored-by: Rok Mihevc <rok@mihevc.org>
@shrivasshankar

Copy link
Copy Markdown
Contributor Author

I added the 2 tests @rok

Comment thread cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc Outdated
@rok rok merged commit 5d2a8fa into apache:main Jul 1, 2026
60 checks passed
@rok rok removed the awaiting change review Awaiting change review label Jul 1, 2026
@rok

rok commented Jul 1, 2026

Copy link
Copy Markdown
Member

Thanks for working on this @shrivasshankar !

@shrivasshankar shrivasshankar deleted the feature/add-hypot-kernel branch July 1, 2026 01:25
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