felipecrv commented on code in PR #37060:
URL: https://github.com/apache/arrow/pull/37060#discussion_r1310442460
##########
cpp/src/arrow/compute/kernels/vector_rolling.cc:
##########
@@ -110,16 +110,49 @@ struct ProdWindow {
using ArgValue = typename GetViewType<ArgType>::T;
using OutValue = typename GetOutputType<OutType>::T;
KernelContext* ctx;
- ArgValue prod = 1;
+ ArgValue prod = 1; // the product of non-nan and non-zero values in the
window
+ int64_t nan_count = 0;
+ int64_t zero_count = 0;
+
explicit ProdWindow(KernelContext* ctx) : ctx(ctx) {}
void Append(ArgValue value, Status* st) {
+ if constexpr (std::is_floating_point_v<ArgValue>) {
+ if (std::isnan(value)) {
+ nan_count++;
+ return;
+ }
+ }
+ if (value == 0) {
+ zero_count++;
+ return;
+ }
prod = Multiply::Call<ArgValue, ArgValue, ArgValue>(ctx, prod, value, st);
}
void Remove(ArgValue value, Status* st) {
+ if constexpr (std::is_floating_point_v<ArgValue>) {
+ if (std::isnan(value)) {
+ nan_count--;
+ return;
+ }
+ }
+ if (value == 0) {
+ zero_count--;
+ return;
+ }
Review Comment:
To avoid division by zero! Clever.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]