We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9f1c4d2 commit bbc4a75Copy full SHA for bbc4a75
src/numeric_util.rs
@@ -67,7 +67,25 @@ where
67
}
68
partial_sums.push(partial_sum);
69
70
- pairwise_sum(&partial_sums)
+ pure_pairwise_sum(&partial_sums)
71
+}
72
+
73
+/// An implementation of pairwise summation for a vector slice that never
74
+/// switches to the naive sum algorithm.
75
+fn pure_pairwise_sum<A>(v: &[A]) -> A
76
+ where
77
+ A: Clone + Add<Output=A> + Zero,
78
+{
79
+ let n = v.len();
80
+ match n {
81
+ 0 => A::zero(),
82
+ 1 => v[0].clone(),
83
+ n => {
84
+ let mid_index = n / 2;
85
+ let (v1, v2) = v.split_at(mid_index);
86
+ pure_pairwise_sum(v1) + pure_pairwise_sum(v2)
87
+ }
88
89
90
91
/// Fold over the manually unrolled `xs` with `f`
0 commit comments