pitrou commented on code in PR #45677:
URL: https://github.com/apache/arrow/pull/45677#discussion_r1981549131
##########
cpp/src/arrow/compute/kernels/hash_aggregate.cc:
##########
@@ -928,27 +969,34 @@ struct GroupedVarStdImpl : public GroupedAggregator {
means[i] = ToDouble(sums[i]) / counts[i];
}
+ double* m2s = state.m2s_mutable_data();
+ double* m3s = state.m3s_mutable_data();
+ double* m4s = state.m4s_mutable_data();
+ // Having distinct VisitGroupedValuesNonNull calls based on moments_level_
+ // would increase code generation for relatively little benefit.
VisitGroupedValuesNonNull<Type>(
batch, [&](uint32_t g, typename TypeTraits<Type>::CType value) {
- const double v = ToDouble(value);
- m2s[g] += (v - means[g]) * (v - means[g]);
+ const double d = ToDouble(value) - means[g];
+ const double d2 = d * d;
+ switch (moments_level_) {
+ case 4:
+ m4s[g] += d2 * d2;
+ [[fallthrough]];
+ case 3:
+ m3s[g] += d2 * d;
+ [[fallthrough]];
+ default:
+ m2s[g] += d2;
+ break;
+ }
});
- ARROW_ASSIGN_OR_RAISE(auto mapping,
- AllocateBuffer(num_groups_ * sizeof(uint32_t),
pool_));
- for (uint32_t i = 0; static_cast<int64_t>(i) < num_groups_; i++) {
- mapping->template mutable_data_as<uint32_t>()[i] = i;
- }
- ArrayData group_id_mapping(uint32(), num_groups_, {nullptr,
std::move(mapping)},
- /*null_count=*/0);
- return this->Merge(std::move(state), group_id_mapping);
Review Comment:
This was doing a pointless allocation of the identity mapping at every batch
consumption stage.
--
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]