Thu, 03 Sep 2026 11:55:09 -0500
p2powers_diff maybe fix
| 5 | 1 | /*! |
| 2 | Second order polynomical (P2) models on real intervals and planar 2D simplices. | |
| 3 | */ | |
| 4 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
5 | use super::base::{LocalModel, RealLocalModel}; |
|
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
6 | use crate::euclidean::Euclidean; |
|
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
7 | use crate::instance::Instance; |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
8 | use crate::linsolve::*; |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
9 | use crate::loc::Loc; |
| 0 | 10 | use crate::sets::Cube; |
|
208
6be69f736c79
Possible p2 model solution fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
206
diff
changeset
|
11 | use crate::sets::Set; |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
12 | use crate::types::*; |
| 0 | 13 | use numeric_literals::replace_float_literals; |
| 14 | ||
| 5 | 15 | /// Type for simplices of arbitrary dimension `N`. |
| 16 | /// | |
| 17 | /// The type parameter `D` indicates the number of nodes. (Rust's const generics do not currently | |
| 18 | /// allow its automatic calculation from `N`.) | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
19 | pub struct Simplex<F: Float, const N: usize, const D: usize>(pub [Loc<N, F>; D]); |
| 5 | 20 | /// A two-dimensional planar simplex |
| 21 | pub type PlanarSimplex<F> = Simplex<F, 2, 3>; | |
| 22 | /// A real interval | |
| 23 | pub type RealInterval<F> = Simplex<F, 1, 2>; | |
| 0 | 24 | |
| 5 | 25 | /// Calculates (a+b)/2 |
| 0 | 26 | #[inline] |
| 27 | #[replace_float_literals(F::cast_from(literal))] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
28 | pub(crate) fn midpoint<F: Float, const N: usize>(a: &Loc<N, F>, b: &Loc<N, F>) -> Loc<N, F> { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
29 | (a + b) / 2.0 |
| 0 | 30 | } |
| 31 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
32 | impl<'a, F: Float> Set<Loc<1, F>> for RealInterval<F> { |
| 0 | 33 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
34 | fn contains<I: Instance<Loc<1, F>>>(&self, z: I) -> bool { |
| 171 | 35 | z.eval_ref(|&Loc([x])| { |
|
133
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
127
diff
changeset
|
36 | let &[Loc([x0]), Loc([x1])] = &self.0; |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
127
diff
changeset
|
37 | (x0 < x && x < x1) || (x1 < x && x < x0) |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
127
diff
changeset
|
38 | }) |
| 0 | 39 | } |
| 40 | } | |
| 41 | ||
|
206
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
42 | #[replace_float_literals(F::cast_from(literal))] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
43 | impl<'a, F: Float> Set<Loc<2, F>> for PlanarSimplex<F> { |
| 0 | 44 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
45 | fn contains<I: Instance<Loc<2, F>>>(&self, z: I) -> bool { |
|
206
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
46 | z.eval_ref(|&Loc([x, y])| { |
|
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
47 | let [Loc([x1, y1]), Loc([x2, y2]), Loc([x3, y3])] = self.0; |
|
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
48 | |
|
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
49 | let areax2 = (x1 - x3) * (y2 - y3) + (x2 - x3) * (y1 - y3); |
|
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
50 | |
|
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
51 | // Unscaled barycentric coordinates |
|
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
52 | let s_unscaled = (y2 - y3) * (x - x3) + (x3 - x2) * (y - y3); |
|
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
53 | let t_unscaled = (y3 - y1) * (x - x3) + (x1 - x3) * (y - y3); |
|
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
54 | |
|
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
55 | (0.0 <= s_unscaled/*&& s <= areax2*/) |
|
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
56 | && (0.0 <= t_unscaled/*&& t <= areax2*/) |
|
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
57 | && s_unscaled + t_unscaled <= areax2 |
|
ce37ff3ce507
p2_local_model triangle containment check improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
58 | }) |
| 0 | 59 | } |
| 60 | } | |
| 61 | ||
| 62 | trait P2Powers { | |
| 63 | type Output; | |
| 64 | type Diff; | |
| 65 | type Full; | |
| 66 | fn p2powers(&self) -> Self::Output; | |
| 67 | fn p2powers_full(&self) -> Self::Full; | |
| 68 | fn p2powers_diff(&self) -> Self::Diff; | |
| 69 | } | |
| 70 | ||
| 71 | #[replace_float_literals(F::cast_from(literal))] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
72 | impl<F: Float> P2Powers for Loc<1, F> { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
73 | type Output = Loc<1, F>; |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
74 | type Full = Loc<3, F>; |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
75 | type Diff = Loc<1, Loc<1, F>>; |
| 0 | 76 | |
| 77 | #[inline] | |
| 78 | fn p2powers(&self) -> Self::Output { | |
| 79 | let &Loc([x0]) = self; | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
80 | [x0 * x0].into() |
| 0 | 81 | } |
| 82 | ||
| 83 | #[inline] | |
| 84 | fn p2powers_full(&self) -> Self::Full { | |
| 85 | let &Loc([x0]) = self; | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
86 | [1.0, x0, x0 * x0].into() |
| 0 | 87 | } |
| 88 | ||
| 89 | #[inline] | |
| 90 | fn p2powers_diff(&self) -> Self::Diff { | |
| 91 | let &Loc([x0]) = self; | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
92 | [[x0 + x0].into()].into() |
| 0 | 93 | } |
| 94 | } | |
| 95 | ||
| 96 | #[replace_float_literals(F::cast_from(literal))] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
97 | impl<F: Float> P2Powers for Loc<2, F> { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
98 | type Output = Loc<3, F>; |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
99 | type Full = Loc<6, F>; |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
100 | type Diff = Loc<2, Loc<3, F>>; |
| 0 | 101 | |
| 102 | #[inline] | |
| 103 | fn p2powers(&self) -> Self::Output { | |
| 104 | let &Loc([x0, x1]) = self; | |
|
208
6be69f736c79
Possible p2 model solution fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
206
diff
changeset
|
105 | [x0 * x0, 2.0 * x0 * x1, x1 * x1].into() |
| 0 | 106 | } |
| 107 | ||
| 108 | #[inline] | |
| 109 | fn p2powers_full(&self) -> Self::Full { | |
| 110 | let &Loc([x0, x1]) = self; | |
|
208
6be69f736c79
Possible p2 model solution fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
206
diff
changeset
|
111 | [1.0, x0, x1, x0 * x0, 2.0 * x0 * x1, x1 * x1].into() |
| 0 | 112 | } |
| 113 | ||
| 114 | #[inline] | |
| 115 | fn p2powers_diff(&self) -> Self::Diff { | |
| 116 | let &Loc([x0, x1]) = self; | |
| 209 | 117 | [ |
| 118 | [x0 + x0, x1 + x1, 0.0].into(), | |
| 119 | [0.0, x0 + x0, x1 + x1].into(), | |
| 120 | ] | |
| 121 | .into() | |
| 0 | 122 | } |
| 123 | } | |
| 124 | ||
| 5 | 125 | /// A trait for generating second order polynomial model of dimension `N` on `Self´. |
| 126 | /// | |
| 127 | /// `Self` should present a subset aset of elements of the type [`Loc`]`<F, N>`. | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
128 | pub trait P2Model<F: Num, const N: usize> { |
| 5 | 129 | /// Implementation type of the second order polynomical model. |
| 130 | /// Typically a [`P2LocalModel`]. | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
131 | type Model: LocalModel<Loc<N, F>, F>; |
| 5 | 132 | /// Generates a second order polynomial model of the function `g` on `Self`. |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
133 | fn p2_model<G: Fn(&Loc<N, F>) -> F>(&self, g: G) -> Self::Model; |
| 0 | 134 | } |
| 135 | ||
| 5 | 136 | /// A local second order polynomical model of dimension `N` with `E` edges |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
137 | pub struct P2LocalModel< |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
138 | F: Num, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
139 | const N: usize, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
140 | const E: usize, /*, const V : usize, const Q : usize*/ |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
141 | > { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
142 | a0: F, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
143 | a1: Loc<N, F>, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
144 | a2: Loc<E, F>, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
145 | //node_values : Loc<V, F>, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
146 | //edge_values : Loc<Q, F>, |
| 0 | 147 | } |
| 148 | ||
| 149 | // | |
| 150 | // 1D planar model construction | |
| 151 | // | |
| 152 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
153 | impl<F: Float> RealInterval<F> { |
| 0 | 154 | #[inline] |
|
127
212f75931da0
Make midpoints of p2_local_models public
Tuomo Valkonen <tuomov@iki.fi>
parents:
124
diff
changeset
|
155 | pub fn midpoints(&self) -> [Loc<1, F>; 1] { |
| 0 | 156 | let [ref n0, ref n1] = &self.0; |
| 157 | let n01 = midpoint(n0, n1); | |
| 158 | [n01] | |
| 159 | } | |
| 160 | } | |
| 161 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
162 | impl<F: Float> P2LocalModel<F, 1, 1 /*, 2, 0*/> { |
| 5 | 163 | /// Creates a new 1D second order polynomical model based on three nodal coordinates and |
| 164 | /// corresponding function values. | |
| 0 | 165 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
166 | pub fn new(&[n0, n1, n01]: &[Loc<1, F>; 3], &[v0, v1, v01]: &[F; 3]) -> Self { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
167 | let p = move |x: &Loc<1, F>, v: F| { |
| 0 | 168 | let Loc([c, d, e]) = x.p2powers_full(); |
| 169 | [c, d, e, v] | |
| 170 | }; | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
171 | let [a0, a1, a11] = linsolve([p(&n0, v0), p(&n1, v1), p(&n01, v01)]); |
| 0 | 172 | P2LocalModel { |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
173 | a0: a0, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
174 | a1: [a1].into(), |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
175 | a2: [a11].into(), |
| 0 | 176 | //node_values : [v0, v1].into(), |
| 177 | //edge_values: [].into(), | |
| 178 | } | |
| 179 | } | |
| 180 | } | |
| 181 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
182 | impl<F: Float> P2Model<F, 1> for RealInterval<F> { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
183 | type Model = P2LocalModel<F, 1, 1 /*, 2, 0*/>; |
| 0 | 184 | |
| 185 | #[inline] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
186 | fn p2_model<G: Fn(&Loc<1, F>) -> F>(&self, g: G) -> Self::Model { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
187 | let [n01] = self.midpoints(); |
| 0 | 188 | let [n0, n1] = self.0; |
| 189 | let vals = [g(&n0), g(&n1), g(&n01)]; | |
| 190 | let nodes = [n0, n1, n01]; | |
| 191 | Self::Model::new(&nodes, &vals) | |
| 192 | } | |
| 193 | } | |
| 194 | ||
| 195 | // | |
| 196 | // 2D planar model construction | |
| 197 | // | |
| 198 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
199 | impl<F: Float> PlanarSimplex<F> { |
| 0 | 200 | #[inline] |
| 5 | 201 | /// Returns the midpoints of all the edges of the simplex |
|
127
212f75931da0
Make midpoints of p2_local_models public
Tuomo Valkonen <tuomov@iki.fi>
parents:
124
diff
changeset
|
202 | pub fn midpoints(&self) -> [Loc<2, F>; 3] { |
| 0 | 203 | let [ref n0, ref n1, ref n2] = &self.0; |
| 204 | let n01 = midpoint(n0, n1); | |
| 205 | let n12 = midpoint(n1, n2); | |
| 206 | let n20 = midpoint(n2, n0); | |
| 207 | [n01, n12, n20] | |
| 208 | } | |
| 209 | } | |
| 210 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
211 | impl<F: Float> P2LocalModel<F, 2, 3 /*, 3, 3*/> { |
| 5 | 212 | /// Creates a new 2D second order polynomical model based on six nodal coordinates and |
| 213 | /// corresponding function values. | |
| 0 | 214 | #[inline] |
| 215 | pub fn new( | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
216 | &[n0, n1, n2, n01, n12, n20]: &[Loc<2, F>; 6], |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
217 | &[v0, v1, v2, v01, v12, v20]: &[F; 6], |
| 0 | 218 | ) -> Self { |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
219 | let p = move |x: &Loc<2, F>, v: F| { |
| 0 | 220 | let Loc([c, d, e, f, g, h]) = x.p2powers_full(); |
| 221 | [c, d, e, f, g, h, v] | |
| 222 | }; | |
| 223 | let [a0, a1, a2, a11, a12, a22] = linsolve([ | |
| 224 | p(&n0, v0), | |
| 225 | p(&n1, v1), | |
| 226 | p(&n2, v2), | |
| 227 | p(&n01, v01), | |
| 228 | p(&n12, v12), | |
| 229 | p(&n20, v20), | |
| 230 | ]); | |
| 231 | P2LocalModel { | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
232 | a0: a0, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
233 | a1: [a1, a2].into(), |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
234 | a2: [a11, a12, a22].into(), |
| 0 | 235 | //node_values : [v0, v1, v2].into(), |
| 236 | //edge_values: [v01, v12, v20].into(), | |
| 237 | } | |
| 238 | } | |
| 239 | } | |
| 240 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
241 | impl<F: Float> P2Model<F, 2> for PlanarSimplex<F> { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
242 | type Model = P2LocalModel<F, 2, 3 /*, 3, 3*/>; |
| 0 | 243 | |
| 244 | #[inline] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
245 | fn p2_model<G: Fn(&Loc<2, F>) -> F>(&self, g: G) -> Self::Model { |
| 0 | 246 | let midpoints = self.midpoints(); |
| 247 | let [ref n0, ref n1, ref n2] = self.0; | |
| 248 | let [ref n01, ref n12, ref n20] = midpoints; | |
| 249 | let vals = [g(n0), g(n1), g(n2), g(n01), g(n12), g(n20)]; | |
| 250 | let nodes = [*n0, *n1, *n2, *n01, *n12, *n20]; | |
| 251 | Self::Model::new(&nodes, &vals) | |
| 252 | } | |
| 253 | } | |
| 254 | ||
| 255 | macro_rules! impl_local_model { | |
| 256 | ($n:literal, $e:literal, $v:literal, $q:literal) => { | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
257 | impl<F: Float> LocalModel<Loc<$n, F>, F> for P2LocalModel<F, $n, /*, $v, $q*/ $e> { |
| 0 | 258 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
259 | fn value(&self, x: &Loc<$n, F>) -> F { |
| 0 | 260 | self.a0 + x.dot(&self.a1) + x.p2powers().dot(&self.a2) |
| 261 | } | |
| 262 | ||
| 263 | #[inline] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
264 | fn differential(&self, x: &Loc<$n, F>) -> Loc<$n, F> { |
| 0 | 265 | self.a1 + x.p2powers_diff().map(|di| di.dot(&self.a2)) |
| 266 | } | |
| 267 | } | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
268 | }; |
| 0 | 269 | } |
| 270 | ||
| 271 | impl_local_model!(1, 1, 2, 0); | |
| 272 | impl_local_model!(2, 3, 3, 3); | |
| 273 | ||
| 274 | // | |
| 275 | // Minimisation | |
| 276 | // | |
| 277 | ||
| 278 | #[replace_float_literals(F::cast_from(literal))] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
279 | impl<F: Float> P2LocalModel<F, 1, 1 /*, 2, 0*/> { |
| 5 | 280 | /// Minimises the model along the edge `[x0, x1]`. |
| 0 | 281 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
282 | fn minimise_edge(&self, x0: Loc<1, F>, x1: Loc<1, F>) -> (Loc<1, F>, F) { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
283 | let &P2LocalModel { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
284 | a1: Loc([a1]), |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
285 | a2: Loc([a11]), |
| 0 | 286 | //node_values : Loc([v0, v1]), |
| 287 | .. | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
288 | } = self; |
| 0 | 289 | // We do this in cases, first trying for an interior solution, then edges. |
| 290 | // For interior solution, first check determinant; no point trying if non-positive | |
| 291 | if a11 > 0.0 { | |
| 292 | // An interior solution x[1] has to satisfy | |
| 293 | // 2a₁₁*x[1] + a₁ =0 | |
| 294 | // This gives | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
295 | let t = -a1 / (2.0 * a11); |
| 0 | 296 | let (Loc([t0]), Loc([t1])) = (x0, x1); |
| 297 | if (t0 <= t && t <= t1) || (t1 <= t && t <= t0) { | |
| 298 | let x = [t].into(); | |
| 299 | let v = self.value(&x); | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
300 | return (x, v); |
| 0 | 301 | } |
| 302 | } | |
| 303 | ||
| 304 | let v0 = self.value(&x0); | |
| 305 | let v1 = self.value(&x1); | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
306 | if v0 < v1 { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
307 | (x0, v0) |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
308 | } else { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
309 | (x1, v1) |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
310 | } |
| 0 | 311 | } |
| 312 | } | |
| 313 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
314 | impl<'a, F: Float> RealLocalModel<RealInterval<F>, Loc<1, F>, F> |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
315 | for P2LocalModel<F, 1, 1 /*, 2, 0*/> |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
316 | { |
| 0 | 317 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
318 | fn minimise(&self, &Simplex([x0, x1]): &RealInterval<F>) -> (Loc<1, F>, F) { |
| 0 | 319 | self.minimise_edge(x0, x1) |
| 320 | } | |
| 321 | } | |
| 322 | ||
| 323 | #[replace_float_literals(F::cast_from(literal))] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
324 | impl<F: Float> P2LocalModel<F, 2, 3 /*, 3, 3*/> { |
| 5 | 325 | /// Minimise the 2D model along the edge `[x0, x1] = {x0 + t(x1 - x0) | t ∈ [0, 1] }`. |
| 0 | 326 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
327 | fn minimise_edge( |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
328 | &self, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
329 | x0: &Loc<2, F>, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
330 | x1: &Loc<2, F>, /*, v0 : F, v1 : F*/ |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
331 | ) -> (Loc<2, F>, F) { |
| 171 | 332 | let &P2LocalModel { a0, a1: Loc([a1, a2]), a2: Loc([a11, a12, a22]), .. } = self; |
| 0 | 333 | let &Loc([x00, x01]) = x0; |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
334 | let d @ Loc([d0, d1]) = x1 - x0; |
|
208
6be69f736c79
Possible p2 model solution fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
206
diff
changeset
|
335 | let b0 = |
|
6be69f736c79
Possible p2 model solution fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
206
diff
changeset
|
336 | a0 + a1 * x00 + a2 * x01 + a11 * x00 * x00 + 2.0 * a12 * x00 * x01 + a22 * x01 * x01; |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
337 | let b1 = a1 * d0 |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
338 | + a2 * d1 |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
339 | + 2.0 * a11 * d0 * x00 |
|
208
6be69f736c79
Possible p2 model solution fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
206
diff
changeset
|
340 | + 2.0 * a12 * (d0 * x01 + d1 * x00) |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
341 | + 2.0 * a22 * d1 * x01; |
|
208
6be69f736c79
Possible p2 model solution fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
206
diff
changeset
|
342 | let b11 = a11 * d0 * d0 + 2.0 * a12 * d0 * d1 + a22 * d1 * d1; |
| 0 | 343 | let edge_1d_model = P2LocalModel { |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
344 | a0: b0, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
345 | a1: Loc([b1]), |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
346 | a2: Loc([b11]), |
| 0 | 347 | //node_values : Loc([v0, v1]), |
| 348 | }; | |
| 349 | let (Loc([t]), v) = edge_1d_model.minimise_edge(0.0.into(), 1.0.into()); | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
350 | (x0 + d * t, v) |
| 0 | 351 | } |
| 352 | } | |
| 353 | ||
| 354 | #[replace_float_literals(F::cast_from(literal))] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
355 | impl<'a, F: Float> RealLocalModel<PlanarSimplex<F>, Loc<2, F>, F> |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
356 | for P2LocalModel<F, 2, 3 /*, 3, 3*/> |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
357 | { |
| 0 | 358 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
359 | fn minimise(&self, el: &PlanarSimplex<F>) -> (Loc<2, F>, F) { |
| 0 | 360 | let &P2LocalModel { |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
361 | a1: Loc([a1, a2]), |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
362 | a2: Loc([a11, a12, a22]), |
| 0 | 363 | //node_values : Loc([v0, v1, v2]), |
| 364 | .. | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
365 | } = self; |
| 0 | 366 | |
| 367 | // We do this in cases, first trying for an interior solution, then edges. | |
| 368 | // For interior solution, first check determinant; no point trying if non-positive | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
369 | let r = 2.0 * (a11 * a22 - a12 * a12); |
| 0 | 370 | if r > 0.0 { |
| 371 | // An interior solution (x[1], x[2]) has to satisfy | |
|
208
6be69f736c79
Possible p2 model solution fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
206
diff
changeset
|
372 | // 2a₁₁*x[1] + 2a₁₂*x[2]+a₁ =0 and 2a₂₂*x[2] + 2a₁₂*x[1]+a₂=0 |
| 0 | 373 | // This gives |
|
208
6be69f736c79
Possible p2 model solution fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
206
diff
changeset
|
374 | let x = [(a22 * a1 - a12 * a2) / r, (a11 * a2 - a12 * a1) / r].into(); |
| 0 | 375 | if el.contains(&x) { |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
376 | return (x, self.value(&x)); |
| 0 | 377 | } |
| 378 | } | |
| 379 | ||
| 380 | let &[ref x0, ref x1, ref x2] = &el.0; | |
| 381 | let mut min_edge = self.minimise_edge(x0, x1); | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
382 | let more_edge = [self.minimise_edge(x1, x2), self.minimise_edge(x2, x0)]; |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
383 | |
| 0 | 384 | for edge in more_edge { |
| 385 | if edge.1 < min_edge.1 { | |
| 386 | min_edge = edge; | |
| 387 | } | |
| 388 | } | |
| 389 | ||
| 390 | min_edge | |
| 391 | } | |
| 392 | } | |
| 393 | ||
| 394 | #[replace_float_literals(F::cast_from(literal))] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
395 | impl<'a, F: Float> RealLocalModel<Cube<2, F>, Loc<2, F>, F> |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
396 | for P2LocalModel<F, 2, 3 /*, 3, 3*/> |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
397 | { |
| 0 | 398 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
399 | fn minimise(&self, el: &Cube<2, F>) -> (Loc<2, F>, F) { |
| 0 | 400 | let &P2LocalModel { |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
401 | a1: Loc([a1, a2]), |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
402 | a2: Loc([a11, a12, a22]), |
| 0 | 403 | //node_values : Loc([v0, v1, v2]), |
| 404 | .. | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
405 | } = self; |
| 0 | 406 | |
| 407 | // We do this in cases, first trying for an interior solution, then edges. | |
| 408 | // For interior solution, first check determinant; no point trying if non-positive | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
409 | let r = 2.0 * (a11 * a22 - a12 * a12); |
| 0 | 410 | if r > 0.0 { |
| 411 | // An interior solution (x[1], x[2]) has to satisfy | |
| 412 | // 2a₁₁*x[1] + 2a₁₂*x[2]+a₁ =0 and 2a₂₂*x[1] + 2a₁₂*x[1]+a₂=0 | |
| 413 | // This gives | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
414 | let x = [(a22 * a1 - a12 * a2) / r, (a12 * a1 - a11 * a2) / r].into(); |
| 0 | 415 | if el.contains(&x) { |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
416 | return (x, self.value(&x)); |
| 0 | 417 | } |
| 418 | } | |
| 419 | ||
| 420 | let [x0, x1, x2, x3] = el.corners(); | |
| 421 | let mut min_edge = self.minimise_edge(&x0, &x1); | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
422 | let more_edge = [ |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
423 | self.minimise_edge(&x1, &x2), |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
424 | self.minimise_edge(&x2, &x3), |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
425 | self.minimise_edge(&x3, &x0), |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
426 | ]; |
| 0 | 427 | |
| 428 | for edge in more_edge { | |
| 429 | if edge.1 < min_edge.1 { | |
| 430 | min_edge = edge; | |
| 431 | } | |
| 432 | } | |
| 433 | ||
| 434 | min_edge | |
| 435 | } | |
| 436 | } | |
| 437 | ||
| 438 | #[cfg(test)] | |
| 439 | mod tests { | |
| 440 | use super::*; | |
| 441 | ||
| 442 | #[test] | |
| 443 | fn p2_model_1d_test() { | |
| 444 | let vertices = [Loc([0.0]), Loc([1.0])]; | |
| 445 | let domain = Simplex(vertices); | |
| 446 | // A simple quadratic function for which the approximation is exact on reals, | |
| 447 | // and appears exact on f64 as well. | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
448 | let f = |&Loc([x]): &Loc<1, f64>| x * x + x + 1.0; |
| 0 | 449 | let model = domain.p2_model(f); |
| 450 | let xs = [Loc([0.5]), Loc([0.25])]; | |
| 451 | ||
| 452 | for x in vertices.iter().chain(xs.iter()) { | |
| 453 | assert_eq!(model.value(&x), f(&x)); | |
| 454 | } | |
| 455 | ||
| 456 | assert_eq!(model.minimise(&domain), (Loc([0.0]), 1.0)); | |
| 457 | } | |
| 458 | ||
| 459 | #[test] | |
| 460 | fn p2_model_2d_test() { | |
| 461 | let vertices = [Loc([0.0, 0.0]), Loc([1.0, 0.0]), Loc([1.0, 1.0])]; | |
| 462 | let domain = Simplex(vertices); | |
| 463 | // A simple quadratic function for which the approximation is exact on reals, | |
| 464 | // and appears exact on f64 as well. | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
465 | let f = |&Loc([x, y]): &Loc<2, f64>| -(x * x + x * y + x - 2.0 * y + 1.0); |
| 0 | 466 | let model = domain.p2_model(f); |
| 467 | let xs = [Loc([0.5, 0.5]), Loc([0.25, 0.25])]; | |
| 468 | ||
| 469 | for x in vertices.iter().chain(xs.iter()) { | |
| 470 | assert_eq!(model.value(&x), f(&x)); | |
| 471 | } | |
| 472 | ||
|
1
df3901ec2f5d
Fix some unit tests after fundamental changes that made them invalid
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
473 | assert_eq!(model.minimise(&domain), (Loc([1.0, 0.0]), -3.0)); |
| 0 | 474 | } |
| 475 | } |