Sun, 27 Apr 2025 15:45:40 -0500
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
| 5 | 1 | /*! |
| 2 | Aggregation / summarisation of information in branches of bisection trees. | |
| 3 | */ | |
| 4 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
5 | use crate::instance::Instance; |
| 0 | 6 | use crate::sets::Set; |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
7 | use crate::types::*; |
| 0 | 8 | |
| 5 | 9 | /// Trait for aggregating information about a branch of a [bisection tree][super::BT]. |
| 10 | /// | |
| 11 | /// Currently [`Bounds`] is the only provided aggregator. | |
| 12 | /// It keeps track of upper and lower bounds of a function representeed by the `BT` by | |
| 13 | /// summing [`Bounds`] produced by [`LocalAnalysis`][super::support::LocalAnalysis] of the | |
| 14 | /// [`Support`][super::support::Support]s of the data stored in the tree. | |
| 15 | /// For the `Bounds` aggregator: | |
| 16 | /// * [`Self::aggregate`] sums input bounds to the current bound. This provides a conservative | |
| 17 | /// estimate of the upper and lower bounds of a sum of functions. | |
| 18 | /// * [`Self::summarise`] takes the maximum of the input bounds. This calculates the bounds | |
| 19 | /// of a function on a greater domain from bounds on subdomains | |
| 20 | /// (in practise [`Cube`][crate::sets::Cube]s). | |
| 21 | /// | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
22 | pub trait Aggregator: Clone + Sync + Send + 'static + std::fmt::Debug { |
| 5 | 23 | /// Aggregate a new data to current state. |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
24 | fn aggregate<I>(&mut self, aggregates: I) |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
25 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
26 | I: Iterator<Item = Self>; |
| 0 | 27 | |
| 5 | 28 | /// Summarise several other aggregators, resetting current state. |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
29 | fn summarise<'a, I>(&'a mut self, aggregates: I) |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
30 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
31 | I: Iterator<Item = &'a Self>; |
| 0 | 32 | |
| 5 | 33 | /// Create a new “empty” aggregate data. |
| 0 | 34 | fn new() -> Self; |
| 35 | } | |
| 36 | ||
| 37 | /// An [`Aggregator`] that doesn't aggregate anything. | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
38 | #[derive(Clone, Debug)] |
| 0 | 39 | pub struct NullAggregator; |
| 40 | ||
| 41 | impl Aggregator for NullAggregator { | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
42 | fn aggregate<I>(&mut self, _aggregates: I) |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
43 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
44 | I: Iterator<Item = Self>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
45 | { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
46 | } |
| 0 | 47 | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
48 | fn summarise<'a, I>(&'a mut self, _aggregates: I) |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
49 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
50 | I: Iterator<Item = &'a Self>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
51 | { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
52 | } |
| 0 | 53 | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
54 | fn new() -> Self { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
55 | NullAggregator |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
56 | } |
| 0 | 57 | } |
| 58 | ||
| 59 | /// Upper and lower bounds on an `F`-valued function. | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
60 | #[derive(Copy, Clone, Debug)] |
| 5 | 61 | pub struct Bounds<F>( |
| 62 | /// Lower bound | |
| 63 | pub F, | |
| 64 | /// Upper bound | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
65 | pub F, |
| 5 | 66 | ); |
| 0 | 67 | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
68 | impl<F: Copy> Bounds<F> { |
| 0 | 69 | /// Returns the lower bound |
| 70 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
71 | pub fn lower(&self) -> F { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
72 | self.0 |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
73 | } |
| 0 | 74 | |
| 75 | /// Returns the upper bound | |
| 76 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
77 | pub fn upper(&self) -> F { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
78 | self.1 |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
79 | } |
| 0 | 80 | } |
| 81 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
82 | impl<F: Float> Bounds<F> { |
| 5 | 83 | /// Returns a uniform bound. |
| 84 | /// | |
| 85 | /// This is maximum over the absolute values of the upper and lower bound. | |
| 0 | 86 | #[inline] |
| 87 | pub fn uniform(&self) -> F { | |
| 88 | let &Bounds(lower, upper) = self; | |
| 89 | lower.abs().max(upper.abs()) | |
| 90 | } | |
|
8
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
91 | |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
92 | /// Construct a bounds, making sure `lower` bound is less than `upper` |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
93 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
94 | pub fn corrected(lower: F, upper: F) -> Self { |
|
8
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
95 | if lower <= upper { |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
96 | Bounds(lower, upper) |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
97 | } else { |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
98 | Bounds(upper, lower) |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
99 | } |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
100 | } |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
101 | |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
102 | /// Refine the lower bound |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
103 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
104 | pub fn refine_lower(&self, lower: F) -> Self { |
|
8
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
105 | let &Bounds(l, u) = self; |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
106 | debug_assert!(l <= u); |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
107 | Bounds(l.max(lower), u.max(lower)) |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
108 | } |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
109 | |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
110 | /// Refine the lower bound |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
111 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
112 | pub fn refine_upper(&self, upper: F) -> Self { |
|
8
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
113 | let &Bounds(l, u) = self; |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
114 | debug_assert!(l <= u); |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
115 | Bounds(l.min(upper), u.min(upper)) |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
116 | } |
| 0 | 117 | } |
| 118 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
119 | impl<'a, F: Float> std::ops::Add<Self> for Bounds<F> { |
| 0 | 120 | type Output = Self; |
| 121 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
122 | fn add(self, Bounds(l2, u2): Self) -> Self::Output { |
| 0 | 123 | let Bounds(l1, u1) = self; |
| 124 | debug_assert!(l1 <= u1 && l2 <= u2); | |
| 125 | Bounds(l1 + l2, u1 + u2) | |
| 126 | } | |
| 127 | } | |
| 128 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
129 | impl<'a, F: Float> std::ops::Mul<Self> for Bounds<F> { |
| 0 | 130 | type Output = Self; |
| 131 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
132 | fn mul(self, Bounds(l2, u2): Self) -> Self::Output { |
| 0 | 133 | let Bounds(l1, u1) = self; |
| 134 | debug_assert!(l1 <= u1 && l2 <= u2); | |
| 135 | let a = l1 * l2; | |
| 136 | let b = u1 * u2; | |
| 137 | // The order may flip when negative numbers are involved, so need min/max | |
| 138 | Bounds(a.min(b), a.max(b)) | |
| 139 | } | |
| 140 | } | |
| 141 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
142 | impl<F: Float> std::iter::Product for Bounds<F> { |
| 0 | 143 | #[inline] |
| 144 | fn product<I>(mut iter: I) -> Self | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
145 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
146 | I: Iterator<Item = Self>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
147 | { |
| 0 | 148 | match iter.next() { |
| 149 | None => Bounds(F::ZERO, F::ZERO), | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
150 | Some(init) => iter.fold(init, |a, b| a * b), |
| 0 | 151 | } |
| 152 | } | |
| 153 | } | |
| 154 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
155 | impl<F: Float> Set<F> for Bounds<F> { |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
156 | fn contains<I: Instance<F>>(&self, item: I) -> bool { |
|
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
157 | let v = item.own(); |
| 0 | 158 | let &Bounds(l, u) = self; |
| 159 | debug_assert!(l <= u); | |
|
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
160 | l <= v && v <= u |
| 0 | 161 | } |
| 162 | } | |
| 163 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
164 | impl<F: Float> Bounds<F> { |
| 0 | 165 | /// Calculate a common bound (glb, lub) for two bounds. |
| 166 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
167 | pub fn common(&self, &Bounds(l2, u2): &Self) -> Self { |
| 0 | 168 | let &Bounds(l1, u1) = self; |
| 169 | debug_assert!(l1 <= u1 && l2 <= u2); | |
| 170 | Bounds(l1.min(l2), u1.max(u2)) | |
| 171 | } | |
| 172 | ||
| 5 | 173 | /// Indicates whether `Self` is a superset of the argument bound. |
| 0 | 174 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
175 | pub fn superset(&self, &Bounds(l2, u2): &Self) -> bool { |
| 0 | 176 | let &Bounds(l1, u1) = self; |
| 177 | debug_assert!(l1 <= u1 && l2 <= u2); | |
| 178 | l1 <= l2 && u2 <= u1 | |
| 179 | } | |
| 180 | ||
| 5 | 181 | /// Returns the greatest bound contained by both argument bounds, if one exists. |
| 0 | 182 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
183 | pub fn glb(&self, &Bounds(l2, u2): &Self) -> Option<Self> { |
| 0 | 184 | let &Bounds(l1, u1) = self; |
| 185 | debug_assert!(l1 <= u1 && l2 <= u2); | |
| 186 | let l = l1.max(l2); | |
| 187 | let u = u1.min(u2); | |
|
8
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
188 | debug_assert!(l <= u); |
| 0 | 189 | if l < u { |
| 190 | Some(Bounds(l, u)) | |
| 191 | } else { | |
| 192 | None | |
| 193 | } | |
| 194 | } | |
| 195 | } | |
| 196 | ||
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
197 | impl<F: Float> Aggregator for Bounds<F> { |
| 0 | 198 | #[inline] |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
199 | fn aggregate<I>(&mut self, aggregates: I) |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
200 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
201 | I: Iterator<Item = Self>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
202 | { |
| 0 | 203 | *self = aggregates.fold(*self, |a, b| a + b); |
| 204 | } | |
| 205 | ||
| 206 | #[inline] | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
207 | fn summarise<'a, I>(&'a mut self, mut aggregates: I) |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
208 | where |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
209 | I: Iterator<Item = &'a Self>, |
|
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
210 | { |
| 0 | 211 | *self = match aggregates.next() { |
| 212 | None => Bounds(F::ZERO, F::ZERO), // No parts in this cube; the function is zero | |
|
96
962c8e346ab9
Allow Zed to reindent btfn.rs, support.rs, aggregator.rs, and bt.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
213 | Some(&bounds) => aggregates.fold(bounds, |a, b| a.common(b)), |
| 0 | 214 | } |
| 215 | } | |
| 216 | ||
| 217 | #[inline] | |
| 218 | fn new() -> Self { | |
| 219 | Bounds(F::ZERO, F::ZERO) | |
| 220 | } | |
| 221 | } |