-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-32190: [C++][Compute] Implement cumulative prod, max and min functions #36020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
91e474f
4bd7ca2
439b5fc
58c0952
ce630a5
c61d6cf
bfc5396
8611992
cee20ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |||||||||||||||
|
|
||||||||||||||||
| #pragma once | ||||||||||||||||
|
|
||||||||||||||||
| #include <limits> | ||||||||||||||||
| #include "arrow/compute/api_scalar.h" | ||||||||||||||||
| #include "arrow/compute/kernels/common_internal.h" | ||||||||||||||||
| #include "arrow/compute/kernels/util_internal.h" | ||||||||||||||||
|
|
@@ -605,6 +606,86 @@ struct Sign { | |||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| struct Max { | ||||||||||||||||
| template <typename T, typename Arg0, typename Arg1> | ||||||||||||||||
| static constexpr enable_if_not_floating_value<T> Call(KernelContext*, Arg0 arg0, | ||||||||||||||||
| Arg1 arg1, Status*) { | ||||||||||||||||
| static_assert(std::is_same<T, Arg0>::value && std::is_same<Arg0, Arg1>::value); | ||||||||||||||||
| return std::max(arg0, arg1); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| template <typename T, typename Arg0, typename Arg1> | ||||||||||||||||
| static constexpr enable_if_floating_value<T> Call(KernelContext*, Arg0 left, Arg1 right, | ||||||||||||||||
| Status*) { | ||||||||||||||||
| static_assert(std::is_same<T, Arg0>::value && std::is_same<Arg0, Arg1>::value); | ||||||||||||||||
| if (std::isnan(left)) { | ||||||||||||||||
bkietz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||
| return right; | ||||||||||||||||
| } else if (std::isnan(right)) { | ||||||||||||||||
| return left; | ||||||||||||||||
| } else { | ||||||||||||||||
| return std::max(left, right); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| struct Min { | ||||||||||||||||
| template <typename T, typename Arg0, typename Arg1> | ||||||||||||||||
| static constexpr enable_if_not_floating_value<T> Call(KernelContext*, Arg0 arg0, | ||||||||||||||||
| Arg1 arg1, Status*) { | ||||||||||||||||
| static_assert(std::is_same<T, Arg0>::value && std::is_same<Arg0, Arg1>::value); | ||||||||||||||||
| return std::min(arg0, arg1); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| template <typename T, typename Arg0, typename Arg1> | ||||||||||||||||
| static constexpr enable_if_floating_value<T> Call(KernelContext*, Arg0 left, Arg1 right, | ||||||||||||||||
| Status*) { | ||||||||||||||||
| static_assert(std::is_same<T, Arg0>::value && std::is_same<Arg0, Arg1>::value); | ||||||||||||||||
| if (std::isnan(left)) { | ||||||||||||||||
| return right; | ||||||||||||||||
| } else if (std::isnan(right)) { | ||||||||||||||||
| return left; | ||||||||||||||||
| } else { | ||||||||||||||||
| return std::min(left, right); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| /// The term identity is from the mathematical notation monoid. | ||||||||||||||||
| /// For any associative binary operation, identity is defined as: | ||||||||||||||||
| /// Op(identity, x) = x for all x. | ||||||||||||||||
| template <typename Op> | ||||||||||||||||
| struct Identity; | ||||||||||||||||
|
|
||||||||||||||||
| template <> | ||||||||||||||||
| struct Identity<Add> { | ||||||||||||||||
| template <typename Value> | ||||||||||||||||
| static constexpr Value value{0}; | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| template <> | ||||||||||||||||
| struct Identity<AddChecked> : Identity<Add> {}; | ||||||||||||||||
|
|
||||||||||||||||
| template <> | ||||||||||||||||
| struct Identity<Multiply> { | ||||||||||||||||
| template <typename Value> | ||||||||||||||||
| static constexpr Value value{1}; | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| template <> | ||||||||||||||||
| struct Identity<MultiplyChecked> : Identity<Multiply> {}; | ||||||||||||||||
|
|
||||||||||||||||
| template <> | ||||||||||||||||
| struct Identity<Max> { | ||||||||||||||||
| template <typename Value> | ||||||||||||||||
| static constexpr Value value{std::numeric_limits<Value>::min()}; | ||||||||||||||||
|
Comment on lines
+679
to
+680
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These cumulative ops aren't currently instantiated for decimal types anyway: https://github.com/apache/arrow/blob/44edc27/cpp/src/arrow/compute/kernels/codegen_internal.h#L1070-L1100 ... if you feel like filing a follow up issue for them, it should be fairly straightforward to specify these as specializations:
Suggested change
Multiplication will require more effort since we can't construct
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll remove them for this pr. Will send another pr for decimals. |
||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| template <> | ||||||||||||||||
| struct Identity<Min> { | ||||||||||||||||
| template <typename Value> | ||||||||||||||||
| static constexpr Value value{std::numeric_limits<Value>::max()}; | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| } // namespace internal | ||||||||||||||||
| } // namespace compute | ||||||||||||||||
| } // namespace arrow | ||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.