mbutrovich commented on code in PR #12062:
URL: https://github.com/apache/arrow-rs/pull/12062#discussion_r4635045897
##########
arrow/benches/arithmetic_kernels.rs:
##########
@@ -60,5 +67,160 @@ fn add_benchmark(c: &mut Criterion) {
}
}
-criterion_group!(benches, add_benchmark);
+/// Like `create_primitive_array_range`, but with its own `seed`, so that two
+/// arrays hold different values and nulls.
+fn seeded_array<T>(
Review Comment:
> Could it move to `arrow/src/util/bench_util.rs` as
`create_primitive_array_range_with_seed`, next to
`create_primitive_array_with_seed`?
The copy here is identical to the one in #12058, so a trial merge of the two
heads (`git merge-tree fe005b260b aee0225d39`) merges it cleanly into one. The
file conflicts in the imports, in the new benchmark functions, and in
`criterion_group!`, which the move doesn't change. The two PRs carry identical
copies of what they share so that neither depends on the other
(https://github.com/apache/arrow-rs/pull/12062#discussion_r4568419018 and
https://github.com/apache/arrow-rs/pull/12058#discussion_r4588942444). Only
this file calls it, so I'd keep it here instead of adding a public function to
`arrow::util::bench_util`.
> nit: `a64` and `b64` repeat the same expression, and a `decimal64 = |seed|
...` closure like `decimal32` would remove the repetition.
Done.
##########
arrow-arith/src/numeric.rs:
##########
@@ -1192,31 +1500,72 @@ where
let l_mul = T::Native::usize_as(10).pow_checked((result_scale -
s1) as _)?;
let r_mul = T::Native::usize_as(10).pow_checked((result_scale -
s2) as _)?;
+ // A scalar with the smaller scale is rescaled once here, rather
than
+ // on every row, which makes its multiplier one.
+ let (l_rescaled, r_rescaled) =
+ (rescale_scalar(l, l_s, l_mul), rescale_scalar(r, r_s, r_mul));
+ let one = T::Native::ONE;
+ let (l, l_mul) = l_rescaled.as_ref().map_or((l, l_mul), |l| (l,
one));
+ let (r, r_mul) = r_rescaled.as_ref().map_or((r, r_mul), |r| (r,
one));
+ let unscaled = l_mul.is_eq(one) && r_mul.is_eq(one);
+
match op {
- // Equal scales make both decimal multipliers one.
- Op::Add | Op::AddWrapping if s1 == s2 => {
- try_op!(l, l_s, r, r_s, l.add_checked(r))
+ Op::Add | Op::AddWrapping if unscaled => {
+ match overflowing_op(l, l_s, r, r_s,
T::Native::add_overflowing)? {
+ Some(array) => array,
+ None => try_op!(l, l_s, r, r_s, l.add_checked(r)),
+ }
}
- Op::Sub | Op::SubWrapping if s1 == s2 => {
- try_op!(l, l_s, r, r_s, l.sub_checked(r))
+ Op::Sub | Op::SubWrapping if unscaled => {
+ match overflowing_op(l, l_s, r, r_s,
T::Native::sub_overflowing)? {
+ Some(array) => array,
+ None => try_op!(l, l_s, r, r_s, l.sub_checked(r)),
+ }
}
+ // `move` copies the multipliers into the closures. Borrowed,
they
+ // keep the loop from vectorizing under thin LTO, like the
borrowed
+ // captures #11525 fixed in `unary`.
Op::Add | Op::AddWrapping => {
- try_op!(
- l,
- l_s,
- r,
- r_s,
-
l.mul_checked(l_mul)?.add_checked(r.mul_checked(r_mul)?)
- )
+ let add = T::Native::add_overflowing;
Review Comment:
Done. A local `rescaled_op!` macro holds the rescaled arm, and `Add` and
`Sub` call it with their operations. `rescale_scalar` now follows
`rescale_right`.
--
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]