Mon, 23 Dec 2024 23:27:45 -0500
Basic arithmetric opt-in hack attempt: not allowed by Rust.
0 | 1 | /*! |
5 | 2 | Array containers that support vector space operations on floats. |
3 | For working with small vectors in $ℝ^2$ or $ℝ^3$. | |
0 | 4 | */ |
5 | ||
6 | use std::ops::{Add,Sub,AddAssign,SubAssign,Mul,Div,MulAssign,DivAssign,Neg,Index,IndexMut}; | |
7 | use std::slice::{Iter,IterMut}; | |
43 | 8 | use std::fmt::{Display, Formatter}; |
0 | 9 | use crate::types::{Float,Num,SignedNum}; |
10 | use crate::maputil::{FixedLength,FixedLengthMut,map1,map2,map1_mut,map2_mut}; | |
5 | 11 | use crate::euclidean::*; |
0 | 12 | use crate::norms::*; |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
13 | use crate::linops::{AXPY, Mapping, Linear}; |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
14 | use crate::instance::{Instance, BasicDecomposition}; |
80
f802ddbabcfc
Basic arithmetric opt-in hack attempt: not allowed by Rust.
Tuomo Valkonen <tuomov@iki.fi>
parents:
64
diff
changeset
|
15 | use crate::mapping::{Space, ArithmeticFalse}; |
0 | 16 | use serde::ser::{Serialize, Serializer, SerializeSeq}; |
17 | ||
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
18 | |
5 | 19 | /// A container type for (short) `N`-dimensional vectors of element type `F`. |
20 | /// | |
21 | /// Supports basic operations of an [`Euclidean`] space, several [`Norm`]s, and | |
22 | /// fused [`AXPY`] operations, among others. | |
0 | 23 | #[derive(Copy,Clone,Debug,PartialEq,Eq)] |
5 | 24 | pub struct Loc<F, const N : usize>( |
25 | /// An array of the elements of the vector | |
26 | pub [F; N] | |
27 | ); | |
0 | 28 | |
43 | 29 | impl<F : Display, const N : usize> Display for Loc<F, N>{ |
30 | // Required method | |
31 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | |
32 | write!(f, "[")?; | |
33 | let mut comma = ""; | |
34 | for e in self.iter() { | |
35 | write!(f, "{comma}{e}")?; | |
36 | comma = ", "; | |
37 | } | |
38 | write!(f, "]") | |
39 | } | |
40 | } | |
41 | ||
0 | 42 | // Need to manually implement as [F; N] serialisation is provided only for some N. |
43 | impl<F, const N : usize> Serialize for Loc<F, N> | |
44 | where | |
45 | F: Serialize, | |
46 | { | |
47 | fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | |
48 | where | |
49 | S: Serializer, | |
50 | { | |
51 | let mut seq = serializer.serialize_seq(Some(N))?; | |
52 | for e in self.iter() { | |
53 | seq.serialize_element(e)?; | |
54 | } | |
55 | seq.end() | |
56 | } | |
57 | } | |
58 | ||
59 | impl<F, const N : usize> Loc<F, N> { | |
5 | 60 | /// Creates a new `Loc` vector from an array. |
0 | 61 | #[inline] |
62 | pub fn new(arr : [F; N]) -> Self { | |
63 | Loc(arr) | |
64 | } | |
5 | 65 | |
66 | /// Returns an iterator over the elements of the vector | |
0 | 67 | #[inline] |
68 | pub fn iter(&self) -> Iter<'_, F> { | |
69 | self.0.iter() | |
70 | } | |
71 | ||
5 | 72 | /// Returns an iterator over mutable references to the elements of the vector |
0 | 73 | #[inline] |
74 | pub fn iter_mut(&mut self) -> IterMut<'_, F> { | |
75 | self.0.iter_mut() | |
76 | } | |
77 | } | |
78 | ||
79 | impl<F : Copy, const N : usize> Loc<F, N> { | |
5 | 80 | /// Maps `g` over the elements of the vector, returning a new [`Loc`] vector |
0 | 81 | #[inline] |
5 | 82 | pub fn map<H>(&self, g : impl Fn(F) -> H) -> Loc<H, N> { |
0 | 83 | Loc::new(map1(self, |u| g(*u))) |
84 | } | |
85 | ||
5 | 86 | /// Maps `g` over pairs of elements of two vectors, retuning a new one. |
0 | 87 | #[inline] |
5 | 88 | pub fn map2<H>(&self, other : &Self, g : impl Fn(F, F) -> H) -> Loc<H, N> { |
0 | 89 | Loc::new(map2(self, other, |u, v| g(*u, *v))) |
90 | } | |
91 | ||
5 | 92 | /// Maps `g` over mutable references to elements of the vector. |
0 | 93 | #[inline] |
5 | 94 | pub fn map_mut(&mut self, g : impl Fn(&mut F)) { |
0 | 95 | map1_mut(self, g) |
96 | } | |
97 | ||
5 | 98 | /// Maps `g` over pairs of mutable references to elements of `self, and elements |
99 | /// of `other` vector. | |
0 | 100 | #[inline] |
5 | 101 | pub fn map2_mut(&mut self, other : &Self, g : impl Fn(&mut F, F)) { |
0 | 102 | map2_mut(self, other, |u, v| g(u, *v)) |
103 | } | |
104 | ||
5 | 105 | /// Maps `g` over the elements of `self` and returns the product of the results. |
0 | 106 | #[inline] |
5 | 107 | pub fn product_map<A : Num>(&self, g : impl Fn(F) -> A) -> A { |
0 | 108 | match N { |
5 | 109 | 1 => g(unsafe { *self.0.get_unchecked(0) }), |
110 | 2 => g(unsafe { *self.0.get_unchecked(0) }) * | |
111 | g(unsafe { *self.0.get_unchecked(1) }), | |
112 | 3 => g(unsafe { *self.0.get_unchecked(0) }) * | |
113 | g(unsafe { *self.0.get_unchecked(1) }) * | |
114 | g(unsafe { *self.0.get_unchecked(2) }), | |
115 | _ => self.iter().fold(A::ONE, |m, &x| m * g(x)) | |
0 | 116 | } |
117 | } | |
118 | } | |
119 | ||
5 | 120 | /// Construct a [`Loc`]. |
121 | /// | |
122 | /// Use as | |
123 | /// ``` | |
124 | /// # use alg_tools::loc::Loc; | |
125 | /// # use alg_tools::loc; | |
126 | /// let x = loc![1.0, 2.0]; | |
127 | /// ``` | |
0 | 128 | #[macro_export] |
129 | macro_rules! loc { | |
130 | ($($x:expr),+ $(,)?) => { Loc::new([$($x),+]) } | |
131 | } | |
132 | ||
133 | ||
134 | impl<F, const N : usize> From<[F; N]> for Loc<F, N> { | |
135 | #[inline] | |
136 | fn from(other: [F; N]) -> Loc<F, N> { | |
137 | Loc(other) | |
138 | } | |
139 | } | |
140 | ||
141 | /*impl<F : Copy, const N : usize> From<&[F; N]> for Loc<F, N> { | |
142 | #[inline] | |
143 | fn from(other: &[F; N]) -> Loc<F, N> { | |
144 | Loc(*other) | |
145 | } | |
146 | }*/ | |
147 | ||
148 | impl<F> From<F> for Loc<F, 1> { | |
149 | #[inline] | |
150 | fn from(other: F) -> Loc<F, 1> { | |
151 | Loc([other]) | |
152 | } | |
153 | } | |
154 | ||
35
3b82a9d16307
Add Mapping codomain slicing and RealVectorField
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
155 | impl<F> Loc<F, 1> { |
3b82a9d16307
Add Mapping codomain slicing and RealVectorField
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
156 | #[inline] |
3b82a9d16307
Add Mapping codomain slicing and RealVectorField
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
157 | pub fn flatten1d(self) -> F { |
3b82a9d16307
Add Mapping codomain slicing and RealVectorField
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
158 | let Loc([v]) = self; |
3b82a9d16307
Add Mapping codomain slicing and RealVectorField
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
159 | v |
3b82a9d16307
Add Mapping codomain slicing and RealVectorField
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
160 | } |
3b82a9d16307
Add Mapping codomain slicing and RealVectorField
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
161 | } |
3b82a9d16307
Add Mapping codomain slicing and RealVectorField
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
162 | |
0 | 163 | impl<F, const N : usize> From<Loc<F, N>> for [F; N] { |
164 | #[inline] | |
165 | fn from(other : Loc<F, N>) -> [F; N] { | |
166 | other.0 | |
167 | } | |
168 | } | |
169 | ||
170 | /*impl<F : Copy, const N : usize> From<&Loc<F, N>> for [F; N] { | |
171 | #[inline] | |
172 | fn from(other : &Loc<F, N>) -> [F; N] { | |
173 | other.0 | |
174 | } | |
175 | }*/ | |
176 | ||
177 | ||
178 | impl<F, const N : usize> IntoIterator for Loc<F, N> { | |
179 | type Item = <[F; N] as IntoIterator>::Item; | |
180 | type IntoIter = <[F; N] as IntoIterator>::IntoIter; | |
181 | ||
182 | #[inline] | |
183 | fn into_iter(self) -> Self::IntoIter { | |
184 | self.0.into_iter() | |
185 | } | |
186 | } | |
187 | ||
188 | // Indexing | |
189 | ||
190 | impl<F, Ix, const N : usize> Index<Ix> for Loc<F,N> | |
191 | where [F; N] : Index<Ix> { | |
192 | type Output = <[F; N] as Index<Ix>>::Output; | |
193 | ||
194 | #[inline] | |
195 | fn index(&self, ix : Ix) -> &Self::Output { | |
196 | self.0.index(ix) | |
197 | } | |
198 | } | |
199 | ||
200 | impl<F, Ix, const N : usize> IndexMut<Ix> for Loc<F,N> | |
201 | where [F; N] : IndexMut<Ix> { | |
202 | #[inline] | |
203 | fn index_mut(&mut self, ix : Ix) -> &mut Self::Output { | |
204 | self.0.index_mut(ix) | |
205 | } | |
206 | } | |
207 | ||
208 | // Arithmetic | |
209 | ||
210 | macro_rules! make_binop { | |
211 | ($trait:ident, $fn:ident, $trait_assign:ident, $fn_assign:ident) => { | |
212 | impl<F : Num, const N : usize> $trait<Loc<F,N>> for Loc<F, N> { | |
213 | type Output = Loc<F, N>; | |
214 | #[inline] | |
215 | fn $fn(mut self, other : Loc<F, N>) -> Self::Output { | |
216 | self.$fn_assign(other); | |
217 | self | |
218 | } | |
219 | } | |
220 | ||
221 | impl<'a, F : Num, const N : usize> $trait<&'a Loc<F,N>> for Loc<F, N> { | |
222 | type Output = Loc<F, N>; | |
223 | #[inline] | |
224 | fn $fn(mut self, other : &'a Loc<F, N>) -> Self::Output { | |
225 | self.$fn_assign(other); | |
226 | self | |
227 | } | |
228 | } | |
229 | ||
230 | impl<'b, F : Num, const N : usize> $trait<Loc<F,N>> for &'b Loc<F, N> { | |
231 | type Output = Loc<F, N>; | |
232 | #[inline] | |
233 | fn $fn(self, other : Loc<F, N>) -> Self::Output { | |
234 | self.map2(&other, |a, b| a.$fn(b)) | |
235 | } | |
236 | } | |
237 | ||
238 | impl<'a, 'b, F : Num, const N : usize> $trait<&'a Loc<F,N>> for &'b Loc<F, N> { | |
239 | type Output = Loc<F, N>; | |
240 | #[inline] | |
241 | fn $fn(self, other : &'a Loc<F, N>) -> Self::Output { | |
242 | self.map2(other, |a, b| a.$fn(b)) | |
243 | } | |
244 | } | |
245 | ||
246 | impl<F : Num, const N : usize> $trait_assign<Loc<F,N>> for Loc<F, N> { | |
247 | #[inline] | |
248 | fn $fn_assign(&mut self, other : Loc<F, N>) { | |
249 | self.map2_mut(&other, |a, b| a.$fn_assign(b)) | |
250 | } | |
251 | } | |
252 | ||
253 | impl<'a, F : Num, const N : usize> $trait_assign<&'a Loc<F,N>> for Loc<F, N> { | |
254 | #[inline] | |
255 | fn $fn_assign(&mut self, other : &'a Loc<F, N>) { | |
256 | self.map2_mut(other, |a, b| a.$fn_assign(b)) | |
257 | } | |
258 | } | |
259 | } | |
260 | } | |
261 | ||
262 | make_binop!(Add, add, AddAssign, add_assign); | |
263 | make_binop!(Sub, sub, SubAssign, sub_assign); | |
264 | ||
28
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
265 | impl<F : Float, const N : usize> std::iter::Sum for Loc<F, N> { |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
266 | fn sum<I: Iterator<Item = Loc<F, N>>>(mut iter: I) -> Self { |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
267 | match iter.next() { |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
268 | None => Self::ORIGIN, |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
269 | Some(mut v) => { |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
270 | for w in iter { |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
271 | v += w |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
272 | } |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
273 | v |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
274 | } |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
275 | } |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
276 | } |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
277 | } |
331345346e7b
Implement std::iter::Sum for Loc<F, N>
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
278 | |
0 | 279 | macro_rules! make_scalarop_rhs { |
280 | ($trait:ident, $fn:ident, $trait_assign:ident, $fn_assign:ident) => { | |
281 | impl<F : Num, const N : usize> $trait<F> for Loc<F, N> { | |
282 | type Output = Loc<F, N>; | |
283 | #[inline] | |
284 | fn $fn(self, b : F) -> Self::Output { | |
285 | self.map(|a| a.$fn(b)) | |
286 | } | |
287 | } | |
288 | ||
289 | impl<'a, F : Num, const N : usize> $trait<&'a F> for Loc<F, N> { | |
290 | type Output = Loc<F, N>; | |
291 | #[inline] | |
292 | fn $fn(self, b : &'a F) -> Self::Output { | |
293 | self.map(|a| a.$fn(*b)) | |
294 | } | |
295 | } | |
296 | ||
297 | impl<'b, F : Num, const N : usize> $trait<F> for &'b Loc<F, N> { | |
298 | type Output = Loc<F, N>; | |
299 | #[inline] | |
300 | fn $fn(self, b : F) -> Self::Output { | |
301 | self.map(|a| a.$fn(b)) | |
302 | } | |
303 | } | |
304 | ||
305 | impl<'a, 'b, F : Float, const N : usize> $trait<&'a F> for &'b Loc<F, N> { | |
306 | type Output = Loc<F, N>; | |
307 | #[inline] | |
308 | fn $fn(self, b : &'a F) -> Self::Output { | |
309 | self.map(|a| a.$fn(*b)) | |
310 | } | |
311 | } | |
312 | ||
313 | impl<F : Num, const N : usize> $trait_assign<F> for Loc<F, N> { | |
314 | #[inline] | |
315 | fn $fn_assign(&mut self, b : F) { | |
316 | self.map_mut(|a| a.$fn_assign(b)); | |
317 | } | |
318 | } | |
319 | ||
320 | impl<'a, F : Num, const N : usize> $trait_assign<&'a F> for Loc<F, N> { | |
321 | #[inline] | |
322 | fn $fn_assign(&mut self, b : &'a F) { | |
323 | self.map_mut(|a| a.$fn_assign(*b)); | |
324 | } | |
325 | } | |
326 | } | |
327 | } | |
328 | ||
329 | ||
330 | make_scalarop_rhs!(Mul, mul, MulAssign, mul_assign); | |
331 | make_scalarop_rhs!(Div, div, DivAssign, div_assign); | |
332 | ||
333 | macro_rules! make_unaryop { | |
334 | ($trait:ident, $fn:ident) => { | |
335 | impl<F : SignedNum, const N : usize> $trait for Loc<F, N> { | |
336 | type Output = Loc<F, N>; | |
337 | #[inline] | |
338 | fn $fn(mut self) -> Self::Output { | |
339 | self.map_mut(|a| *a = (*a).$fn()); | |
340 | self | |
341 | } | |
342 | } | |
343 | ||
344 | impl<'a, F : SignedNum, const N : usize> $trait for &'a Loc<F, N> { | |
345 | type Output = Loc<F, N>; | |
346 | #[inline] | |
347 | fn $fn(self) -> Self::Output { | |
348 | self.map(|a| a.$fn()) | |
349 | } | |
350 | } | |
351 | } | |
352 | } | |
353 | ||
354 | make_unaryop!(Neg, neg); | |
355 | ||
356 | macro_rules! make_scalarop_lhs { | |
357 | ($trait:ident, $fn:ident; $($f:ident)+) => { $( | |
358 | impl<const N : usize> $trait<Loc<$f,N>> for $f { | |
359 | type Output = Loc<$f, N>; | |
360 | #[inline] | |
361 | fn $fn(self, v : Loc<$f,N>) -> Self::Output { | |
362 | v.map(|b| self.$fn(b)) | |
363 | } | |
364 | } | |
365 | ||
366 | impl<'a, const N : usize> $trait<&'a Loc<$f,N>> for $f { | |
367 | type Output = Loc<$f, N>; | |
368 | #[inline] | |
369 | fn $fn(self, v : &'a Loc<$f,N>) -> Self::Output { | |
370 | v.map(|b| self.$fn(b)) | |
371 | } | |
372 | } | |
373 | ||
374 | impl<'b, const N : usize> $trait<Loc<$f,N>> for &'b $f { | |
375 | type Output = Loc<$f, N>; | |
376 | #[inline] | |
377 | fn $fn(self, v : Loc<$f,N>) -> Self::Output { | |
378 | v.map(|b| self.$fn(b)) | |
379 | } | |
380 | } | |
381 | ||
382 | impl<'a, 'b, const N : usize> $trait<&'a Loc<$f,N>> for &'b $f { | |
383 | type Output = Loc<$f, N>; | |
384 | #[inline] | |
385 | fn $fn(self, v : &'a Loc<$f, N>) -> Self::Output { | |
386 | v.map(|b| self.$fn(b)) | |
387 | } | |
388 | } | |
389 | )+ } | |
390 | } | |
391 | ||
392 | make_scalarop_lhs!(Mul, mul; f32 f64 i8 i16 i32 i64 isize u8 u16 u32 u64 usize); | |
393 | make_scalarop_lhs!(Div, div; f32 f64 i8 i16 i32 i64 isize u8 u16 u32 u64 usize); | |
394 | ||
395 | // Norms | |
396 | ||
397 | macro_rules! domination { | |
398 | ($norm:ident, $dominates:ident) => { | |
399 | impl<F : Float, const N : usize> Dominated<F, $dominates, Loc<F, N>> for $norm { | |
400 | #[inline] | |
401 | fn norm_factor(&self, _p : $dominates) -> F { | |
402 | F::ONE | |
403 | } | |
404 | #[inline] | |
405 | fn from_norm(&self, p_norm : F, _p : $dominates) -> F { | |
406 | p_norm | |
407 | } | |
408 | } | |
409 | }; | |
410 | ($norm:ident, $dominates:ident, $fn:path) => { | |
411 | impl<F : Float, const N : usize> Dominated<F, $dominates, Loc<F, N>> for $norm { | |
412 | #[inline] | |
413 | fn norm_factor(&self, _p : $dominates) -> F { | |
414 | $fn(F::cast_from(N)) | |
415 | } | |
416 | } | |
417 | }; | |
418 | } | |
419 | ||
420 | domination!(L1, L1); | |
421 | domination!(L2, L2); | |
422 | domination!(Linfinity, Linfinity); | |
423 | ||
424 | domination!(L1, L2, F::sqrt); | |
425 | domination!(L2, Linfinity, F::sqrt); | |
426 | domination!(L1, Linfinity, std::convert::identity); | |
427 | ||
428 | domination!(Linfinity, L1); | |
429 | domination!(Linfinity, L2); | |
430 | domination!(L2, L1); | |
431 | ||
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
432 | impl<F : Float,const N : usize> Euclidean<F> for Loc<F, N> { |
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
433 | type Output = Self; |
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
434 | |
0 | 435 | /// This implementation is not stabilised as it's meant to be used for very small vectors. |
436 | /// Use [`nalgebra`] for larger vectors. | |
437 | #[inline] | |
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
438 | fn dot<I : Instance<Self>>(&self, other : I) -> F { |
0 | 439 | self.0.iter() |
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
440 | .zip(other.ref_instance().0.iter()) |
0 | 441 | .fold(F::ZERO, |m, (&v, &w)| m + v * w) |
442 | } | |
443 | ||
444 | /// This implementation is not stabilised as it's meant to be used for very small vectors. | |
445 | /// Use [`nalgebra`] for larger vectors. | |
446 | #[inline] | |
447 | fn norm2_squared(&self) -> F { | |
448 | self.iter().fold(F::ZERO, |m, &v| m + v * v) | |
449 | } | |
450 | ||
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
451 | fn dist2_squared<I : Instance<Self>>(&self, other : I) -> F { |
0 | 452 | self.iter() |
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
453 | .zip(other.ref_instance().iter()) |
0 | 454 | .fold(F::ZERO, |m, (&v, &w)| { let d = v - w; m + d * d }) |
455 | } | |
456 | ||
457 | #[inline] | |
458 | fn norm2(&self) -> F { | |
459 | // Optimisation for N==1 that avoids squaring and square rooting. | |
460 | if N==1 { | |
461 | unsafe { self.0.get_unchecked(0) }.abs() | |
462 | } else { | |
463 | self.norm2_squared().sqrt() | |
464 | } | |
465 | } | |
466 | ||
467 | #[inline] | |
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
468 | fn dist2<I : Instance<Self>>(&self, other : I) -> F { |
0 | 469 | // Optimisation for N==1 that avoids squaring and square rooting. |
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
470 | let otherr = other.ref_instance(); |
0 | 471 | if N==1 { |
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
472 | unsafe { *self.0.get_unchecked(0) - *otherr.0.get_unchecked(0) }.abs() |
0 | 473 | } else { |
474 | self.dist2_squared(other).sqrt() | |
475 | } | |
476 | } | |
477 | } | |
478 | ||
479 | impl<F : Num, const N : usize> Loc<F, N> { | |
52 | 480 | /// Origin point |
0 | 481 | pub const ORIGIN : Self = Loc([F::ZERO; N]); |
482 | } | |
483 | ||
52 | 484 | impl<F : Num + std::ops::Neg<Output=F>, const N : usize> Loc<F, N> { |
485 | /// Reflects along the given coordinate | |
486 | pub fn reflect(mut self, i : usize) -> Self { | |
487 | self[i] = -self[i]; | |
488 | self | |
489 | } | |
490 | ||
491 | /// Reflects along the given coordinate sequences | |
492 | pub fn reflect_many<I : IntoIterator<Item=usize>>(mut self, idxs : I) -> Self { | |
493 | for i in idxs { | |
494 | self[i]=-self[i] | |
495 | } | |
496 | self | |
497 | } | |
498 | } | |
499 | ||
500 | impl<F : std::ops::Neg<Output=F>> Loc<F, 2> { | |
501 | /// Reflect x coordinate | |
502 | pub fn reflect_x(self) -> Self { | |
503 | let Loc([x, y]) = self; | |
504 | [-x, y].into() | |
505 | } | |
506 | ||
507 | /// Reflect y coordinate | |
508 | pub fn reflect_y(self) -> Self { | |
509 | let Loc([x, y]) = self; | |
510 | [x, -y].into() | |
511 | } | |
512 | } | |
513 | ||
514 | impl<F : Float> Loc<F, 2> { | |
515 | /// Rotate by angle φ | |
516 | pub fn rotate(self, φ : F) -> Self { | |
517 | let Loc([x, y]) = self; | |
518 | let sin_φ = φ.sin(); | |
519 | let cos_φ = φ.cos(); | |
520 | [cos_φ * x - sin_φ * y, | |
521 | sin_φ * x + cos_φ * y].into() | |
522 | } | |
523 | } | |
524 | ||
525 | impl<F : std::ops::Neg<Output=F>> Loc<F, 3> { | |
526 | /// Reflect x coordinate | |
527 | pub fn reflect_x(self) -> Self { | |
528 | let Loc([x, y, z]) = self; | |
529 | [-x, y, z].into() | |
530 | } | |
531 | ||
532 | /// Reflect y coordinate | |
533 | pub fn reflect_y(self) -> Self { | |
534 | let Loc([x, y, z]) = self; | |
535 | [x, -y, z].into() | |
536 | } | |
537 | ||
538 | /// Reflect y coordinate | |
539 | pub fn reflect_z(self) -> Self { | |
540 | let Loc([x, y, z]) = self; | |
541 | [x, y, -z].into() | |
542 | } | |
543 | } | |
544 | ||
545 | impl<F : Float> Loc<F, 3> { | |
546 | /// Rotate by angles (yaw, pitch, roll) | |
547 | pub fn rotate(self, Loc([φ, ψ, θ]) : Self) -> Self { | |
548 | let Loc([mut x, mut y, mut z]) = self; | |
549 | let sin_φ = φ.sin(); | |
550 | let cos_φ = φ.cos(); | |
551 | [x, y, z] = [cos_φ * x - sin_φ *y, | |
552 | sin_φ * x + cos_φ * y, | |
553 | z]; | |
554 | let sin_ψ = ψ.sin(); | |
555 | let cos_ψ = ψ.cos(); | |
556 | [x, y, z] = [cos_ψ * x + sin_ψ * z, | |
557 | y, | |
558 | -sin_ψ * x + cos_ψ * z]; | |
559 | let sin_θ = θ.sin(); | |
560 | let cos_θ = θ.cos(); | |
561 | [x, y, z] = [x, | |
562 | cos_θ * y - sin_θ * z, | |
563 | sin_θ * y + cos_θ * z]; | |
564 | [x, y, z].into() | |
565 | } | |
566 | } | |
567 | ||
0 | 568 | impl<F : Float,const N : usize> StaticEuclidean<F> for Loc<F, N> { |
569 | #[inline] | |
570 | fn origin() -> Self { | |
571 | Self::ORIGIN | |
572 | } | |
573 | } | |
574 | ||
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
575 | |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
576 | /// The default norm for `Loc` is [`L2`]. |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
577 | impl<F : Float, const N : usize> Normed<F> for Loc<F, N> { |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
578 | type NormExp = L2; |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
579 | |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
580 | #[inline] |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
581 | fn norm_exponent(&self) -> Self::NormExp { |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
582 | L2 |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
583 | } |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
584 | |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
585 | // #[inline] |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
586 | // fn similar_origin(&self) -> Self { |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
587 | // [F::ZERO; N].into() |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
588 | // } |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
589 | |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
590 | #[inline] |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
591 | fn is_zero(&self) -> bool { |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
592 | self.norm2_squared() == F::ZERO |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
593 | } |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
594 | } |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
595 | |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
596 | impl<F : Float, const N : usize> HasDual<F> for Loc<F, N> { |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
597 | type DualSpace = Self; |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
598 | } |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
599 | |
0 | 600 | impl<F : Float, const N : usize> Norm<F, L2> for Loc<F, N> { |
601 | #[inline] | |
602 | fn norm(&self, _ : L2) -> F { self.norm2() } | |
603 | } | |
604 | ||
605 | impl<F : Float, const N : usize> Dist<F, L2> for Loc<F, N> { | |
606 | #[inline] | |
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
607 | fn dist<I : Instance<Self>>(&self, other : I, _ : L2) -> F { self.dist2(other) } |
0 | 608 | } |
609 | ||
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
610 | /* Implemented automatically as Euclidean. |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
611 | impl<F : Float, const N : usize> Projection<F, L2> for Loc<F, N> { |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
612 | #[inline] |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
613 | fn proj_ball_mut(&mut self, ρ : F, nrm : L2) { |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
614 | let n = self.norm(nrm); |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
615 | if n > ρ { |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
616 | *self *= ρ/n; |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
617 | } |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
618 | } |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
619 | }*/ |
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
620 | |
0 | 621 | impl<F : Float, const N : usize> Norm<F, L1> for Loc<F, N> { |
622 | /// This implementation is not stabilised as it's meant to be used for very small vectors. | |
623 | /// Use [`nalgebra`] for larger vectors. | |
624 | #[inline] | |
625 | fn norm(&self, _ : L1) -> F { | |
626 | self.iter().fold(F::ZERO, |m, v| m + v.abs()) | |
627 | } | |
628 | } | |
629 | ||
630 | impl<F : Float, const N : usize> Dist<F, L1> for Loc<F, N> { | |
631 | #[inline] | |
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
632 | fn dist<I : Instance<Self>>(&self, other : I, _ : L1) -> F { |
0 | 633 | self.iter() |
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
634 | .zip(other.ref_instance().iter()) |
0 | 635 | .fold(F::ZERO, |m, (&v, &w)| m + (v-w).abs() ) |
636 | } | |
637 | } | |
638 | ||
639 | impl<F : Float, const N : usize> Projection<F, Linfinity> for Loc<F, N> { | |
640 | #[inline] | |
641 | fn proj_ball_mut(&mut self, ρ : F, _ : Linfinity) { | |
642 | self.iter_mut().for_each(|v| *v = num_traits::clamp(*v, -ρ, ρ)) | |
643 | } | |
644 | } | |
645 | ||
646 | impl<F : Float, const N : usize> Norm<F, Linfinity> for Loc<F, N> { | |
647 | /// This implementation is not stabilised as it's meant to be used for very small vectors. | |
648 | /// Use [`nalgebra`] for larger vectors. | |
649 | #[inline] | |
650 | fn norm(&self, _ : Linfinity) -> F { | |
651 | self.iter().fold(F::ZERO, |m, v| m.max(v.abs())) | |
652 | } | |
653 | } | |
654 | ||
655 | impl<F : Float, const N : usize> Dist<F, Linfinity> for Loc<F, N> { | |
656 | #[inline] | |
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
657 | fn dist<I : Instance<Self>>(&self, other : I, _ : Linfinity) -> F { |
0 | 658 | self.iter() |
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
659 | .zip(other.ref_instance().iter()) |
0 | 660 | .fold(F::ZERO, |m, (&v, &w)| m.max((v-w).abs())) |
661 | } | |
662 | } | |
663 | ||
664 | ||
665 | // Misc. | |
666 | ||
667 | impl<A, const N : usize> FixedLength<N> for Loc<A,N> { | |
668 | type Iter = std::array::IntoIter<A, N>; | |
669 | type Elem = A; | |
670 | #[inline] | |
671 | fn fl_iter(self) -> Self::Iter { | |
672 | self.into_iter() | |
673 | } | |
674 | } | |
675 | ||
676 | impl<A, const N : usize> FixedLengthMut<N> for Loc<A,N> { | |
677 | type IterMut<'a> = std::slice::IterMut<'a, A> where A : 'a; | |
678 | #[inline] | |
679 | fn fl_iter_mut(&mut self) -> Self::IterMut<'_> { | |
680 | self.iter_mut() | |
681 | } | |
682 | } | |
683 | ||
684 | impl<'a, A, const N : usize> FixedLength<N> for &'a Loc<A,N> { | |
685 | type Iter = std::slice::Iter<'a, A>; | |
686 | type Elem = &'a A; | |
687 | #[inline] | |
688 | fn fl_iter(self) -> Self::Iter { | |
689 | self.iter() | |
690 | } | |
691 | } | |
692 | ||
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
693 | |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
694 | impl<F : Num, const N : usize> Space for Loc<F, N> { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
695 | type Decomp = BasicDecomposition; |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
696 | } |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
697 | |
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
698 | impl<F : Float, const N : usize> Mapping<Loc<F, N>> for Loc<F, N> { |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
699 | type Codomain = F; |
80
f802ddbabcfc
Basic arithmetric opt-in hack attempt: not allowed by Rust.
Tuomo Valkonen <tuomov@iki.fi>
parents:
64
diff
changeset
|
700 | type ArithmeticOptIn = ArithmeticFalse; |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
701 | |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
702 | fn apply<I : Instance<Loc<F, N>>>(&self, x : I) -> Self::Codomain { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
703 | x.eval(|x̃| self.dot(x̃)) |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
704 | } |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
705 | } |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
706 | |
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
707 | impl<F : Float, const N : usize> Linear<Loc<F, N>> for Loc<F, N> { } |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
708 | |
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
709 | impl<F : Float, const N : usize> AXPY<F, Loc<F, N>> for Loc<F, N> { |
62
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
710 | type Owned = Self; |
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
711 | |
0 | 712 | #[inline] |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
713 | fn axpy<I : Instance<Loc<F, N>>>(&mut self, α : F, x : I, β : F) { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
714 | x.eval(|x̃| { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
715 | if β == F::ZERO { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
716 | map2_mut(self, x̃, |yi, xi| { *yi = α * (*xi) }) |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
717 | } else { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
718 | map2_mut(self, x̃, |yi, xi| { *yi = β * (*yi) + α * (*xi) }) |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
719 | } |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
720 | }) |
0 | 721 | } |
722 | ||
723 | #[inline] | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
724 | fn copy_from<I : Instance<Loc<F, N>>>(&mut self, x : I) { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
52
diff
changeset
|
725 | x.eval(|x̃| map2_mut(self, x̃, |yi, xi| *yi = *xi )) |
0 | 726 | } |
62
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
727 | |
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
728 | #[inline] |
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
729 | fn similar_origin(&self) -> Self::Owned { |
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
730 | Self::ORIGIN |
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
731 | } |
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
732 | |
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
733 | #[inline] |
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
734 | fn set_zero(&mut self) { |
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
735 | *self = Self::ORIGIN; |
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
736 | } |
0 | 737 | } |
62
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
738 |