src/nalgebra_support.rs

Tue, 31 Dec 2024 09:12:43 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Tue, 31 Dec 2024 09:12:43 -0500
branch
dev
changeset 81
d2acaaddd9af
parent 13
465fa2121ccb
permissions
-rw-r--r--

Try to have Field as member type in Mappings etc.

5
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
1 /*!
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
2 Integration with nalgebra.
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
3
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
4 This module mainly implements [`Euclidean`], [`Norm`], [`Dot`], [`Linear`], etc. for [`nalgebra`]
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
5 matrices and vectors.
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
6 It also provides [`ToNalgebraRealField`] as a vomit-inducingly ugly workaround to nalgebra
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
7 force-feeding its own versions of the same basic mathematical methods on `f32` and `f64` as
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
8 [`num_traits`] does.
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
9 */
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
11 use nalgebra::{
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12 Matrix, Storage, StorageMut, OMatrix, Dim, DefaultAllocator, Scalar,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13 ClosedMul, ClosedAdd, SimdComplexField, Vector, OVector, RealField,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14 LpNorm, UniformNorm
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
15 };
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
16 use nalgebra::Norm as NalgebraNorm;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
17 use nalgebra::base::constraint::{
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18 ShapeConstraint, SameNumberOfRows, SameNumberOfColumns
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19 };
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
20 use nalgebra::base::dimension::*;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21 use nalgebra::base::allocator::Allocator;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
22 use std::ops::Mul;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
23 use num_traits::identities::{Zero, One};
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
24 use crate::linops::*;
5
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
25 use crate::euclidean::*;
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26 use crate::types::Float;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27 use crate::norms::*;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
28
13
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
29 impl<SM,SV,N,M,K,E> Apply<Matrix<E,M,K,SV>> for Matrix<E,N,M,SM>
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
30 where SM: Storage<E,N,M>, SV: Storage<E,M,K>,
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
31 N : Dim, M : Dim, K : Dim, E : Scalar + ClosedMul + ClosedAdd + Zero + One,
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
32 DefaultAllocator : Allocator<E,N,K>,
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
33 DefaultAllocator : Allocator<E,M,K>,
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
34 DefaultAllocator : Allocator<E,N,M>,
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
35 DefaultAllocator : Allocator<E,M,N> {
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
36 type Output = OMatrix<E,N,K>;
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
37
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
38 #[inline]
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
39 fn apply(&self, x : Matrix<E,M,K,SV>) -> Self::Output {
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
40 self.mul(x)
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
41 }
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
42 }
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
43
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
44 impl<'a, SM,SV,N,M,K,E> Apply<&'a Matrix<E,M,K,SV>> for Matrix<E,N,M,SM>
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
45 where SM: Storage<E,N,M>, SV: Storage<E,M,K>,
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
46 N : Dim, M : Dim, K : Dim, E : Scalar + ClosedMul + ClosedAdd + Zero + One,
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
47 DefaultAllocator : Allocator<E,N,K>,
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
48 DefaultAllocator : Allocator<E,M,K>,
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
49 DefaultAllocator : Allocator<E,N,M>,
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
50 DefaultAllocator : Allocator<E,M,N> {
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
51 type Output = OMatrix<E,N,K>;
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
52
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
53 #[inline]
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
54 fn apply(&self, x : &'a Matrix<E,M,K,SV>) -> Self::Output {
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
55 self.mul(x)
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
56 }
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
57 }
465fa2121ccb Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents: 5
diff changeset
58
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
59 impl<SM,SV,N,M,K,E> Linear<Matrix<E,M,K,SV>> for Matrix<E,N,M,SM>
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
60 where SM: Storage<E,N,M>, SV: Storage<E,M,K>,
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
61 N : Dim, M : Dim, K : Dim, E : Float + Scalar + ClosedMul + ClosedAdd + Zero + One,
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
62 DefaultAllocator : Allocator<E,N,K>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
63 DefaultAllocator : Allocator<E,M,K>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
64 DefaultAllocator : Allocator<E,N,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
65 DefaultAllocator : Allocator<E,M,N> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
66 type Codomain = OMatrix<E,N,K>;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
67 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
68
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
69 impl<SM,SV1,SV2,N,M,K,E> GEMV<E, Matrix<E,M,K,SV1>, Matrix<E,N,K,SV2>> for Matrix<E,N,M,SM>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
70 where SM: Storage<E,N,M>, SV1: Storage<E,M,K>, SV2: StorageMut<E,N,K>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
71 N : Dim, M : Dim, K : Dim, E : Scalar + ClosedMul + ClosedAdd + Zero + One + Float,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
72 DefaultAllocator : Allocator<E,N,K>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
73 DefaultAllocator : Allocator<E,M,K>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
74 DefaultAllocator : Allocator<E,N,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
75 DefaultAllocator : Allocator<E,M,N> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
76
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
77 #[inline]
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
78 fn gemv(&self, y : &mut Matrix<E,N,K,SV2>, α : E, x : Matrix<E,M,K,SV1>, β : E) {
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
79 Matrix::gemm(y, α, self, &x, β)
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
80 }
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
82 #[inline]
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
83 fn apply_mut(&self, y : &mut Matrix<E,N,K,SV2>, x : Matrix<E,M,K,SV1>) {
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
84 self.mul_to(&x, y)
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
85 }
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
86 }
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
87
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
88 impl<'a, SM,SV1,SV2,N,M,K,E> GEMV<E, &'a Matrix<E,M,K,SV1>, Matrix<E,N,K,SV2>> for Matrix<E,N,M,SM>
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
89 where SM: Storage<E,N,M>, SV1: Storage<E,M,K>, SV2: StorageMut<E,N,K>,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
90 N : Dim, M : Dim, K : Dim, E : Scalar + ClosedMul + ClosedAdd + Zero + One + Float,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
91 DefaultAllocator : Allocator<E,N,K>,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
92 DefaultAllocator : Allocator<E,M,K>,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
93 DefaultAllocator : Allocator<E,N,M>,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
94 DefaultAllocator : Allocator<E,M,N> {
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
95
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
96 #[inline]
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
97 fn gemv(&self, y : &mut Matrix<E,N,K,SV2>, α : E, x : &'a Matrix<E,M,K,SV1>, β : E) {
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
98 Matrix::gemm(y, α, self, x, β)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
99 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
100
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
101 #[inline]
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
102 fn apply_mut(&self, y : &mut Matrix<E,N,K,SV2>, x : &'a Matrix<E,M,K,SV1>) {
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
103 self.mul_to(x, y)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
104 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
105 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
106
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
107 impl<SM,SV1,M,E> AXPY<E, Vector<E,M,SV1>> for Vector<E,M,SM>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
108 where SM: StorageMut<E,M>, SV1: Storage<E,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
109 M : Dim, E : Scalar + ClosedMul + ClosedAdd + Zero + One + Float,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
110 DefaultAllocator : Allocator<E,M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
111
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
112 #[inline]
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
113 fn axpy(&mut self, α : E, x : Vector<E,M,SV1>, β : E) {
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
114 Matrix::axpy(self, α, &x, β)
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
115 }
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
116
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
117 #[inline]
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
118 fn copy_from(&mut self, y : Vector<E,M,SV1>) {
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
119 Matrix::copy_from(self, &y)
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
120 }
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
121 }
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
122
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
123 impl<'a, SM,SV1,M,E> AXPY<E, &'a Vector<E,M,SV1>> for Vector<E,M,SM>
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
124 where SM: StorageMut<E,M>, SV1: Storage<E,M>,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
125 M : Dim, E : Scalar + ClosedMul + ClosedAdd + Zero + One + Float,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
126 DefaultAllocator : Allocator<E,M> {
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
127
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
128 #[inline]
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
129 fn axpy(&mut self, α : E, x : &'a Vector<E,M,SV1>, β : E) {
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
130 Matrix::axpy(self, α, x, β)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
131 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
132
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
133 #[inline]
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
134 fn copy_from(&mut self, y : &'a Vector<E,M,SV1>) {
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
135 Matrix::copy_from(self, y)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
136 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
137 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
138
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
139 impl<SM,M,E> Projection<Linfinity> for Vector<E,M,SM>
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
140 where SM: StorageMut<E,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
141 M : Dim, E : Scalar + ClosedMul + ClosedAdd + Zero + One + Float + RealField,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
142 DefaultAllocator : Allocator<E,M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
143 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
144 fn proj_ball_mut(&mut self, ρ : E, _ : Linfinity) {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
145 self.iter_mut().for_each(|v| *v = num_traits::clamp(*v, -ρ, ρ))
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
146 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
147 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
148
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
149 impl<'own,SV1,SV2,SM,N,M,K,E> Adjointable<Matrix<E,M,K,SV1>,Matrix<E,N,K,SV2>>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
150 for Matrix<E,N,M,SM>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
151 where SM: Storage<E,N,M>, SV1: Storage<E,M,K>, SV2: Storage<E,N,K>,
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
152 N : Dim, M : Dim, K : Dim,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
153 E : Float + Scalar + ClosedMul + ClosedAdd + Zero + One + SimdComplexField,
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
154 DefaultAllocator : Allocator<E,N,K>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
155 DefaultAllocator : Allocator<E,M,K>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
156 DefaultAllocator : Allocator<E,N,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
157 DefaultAllocator : Allocator<E,M,N> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
158 type AdjointCodomain = OMatrix<E,M,K>;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
159 type Adjoint<'a> = OMatrix<E,M,N> where SM : 'a;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
160
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
161 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
162 fn adjoint(&self) -> Self::Adjoint<'_> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
163 Matrix::adjoint(self)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
164 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
165 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
166
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
167 impl<E,M,S,Si> Dot<Vector<E,M,Si>>
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
168 for Vector<E,M,S>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
169 where M : Dim,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
170 E : Float + Scalar + ClosedMul + ClosedAdd + Zero + One,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
171 S : Storage<E,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
172 Si : Storage<E,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
173 DefaultAllocator : Allocator<E,M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
174
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
175 #[inline]
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
176 fn dot(&self, other : Vector<E,M,Si>) -> E {
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
177 Vector::<E,M,S>::dot(self, &other)
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
178 }
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
179 }
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
180
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
181 impl<'a, E,M,S,Si> Dot<&'a Vector<E,M,Si>>
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
182 for Vector<E,M,S>
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
183 where M : Dim,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
184 E : Float + Scalar + ClosedMul + ClosedAdd + Zero + One,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
185 S : Storage<E,M>,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
186 Si : Storage<E,M>,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
187 DefaultAllocator : Allocator<E,M> {
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
188
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
189 #[inline]
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
190 fn dot(&self, other : &'a Vector<E,M,Si>) -> E {
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
191 Vector::<E,M,S>::dot(self, other)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
192 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
193 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
194
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
195 /// This function is [`nalgebra::EuclideanNorm::metric_distance`] without the `sqrt`.
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
196 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
197 fn metric_distance_squared<T, R1, C1, S1, R2, C2, S2>(
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
198 /*ed: &EuclideanNorm,*/
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
199 m1: &Matrix<T, R1, C1, S1>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
200 m2: &Matrix<T, R2, C2, S2>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
201 ) -> T::SimdRealField
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
202 where
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
203 T: SimdComplexField,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
204 R1: Dim,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
205 C1: Dim,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
206 S1: Storage<T, R1, C1>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
207 R2: Dim,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
208 C2: Dim,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
209 S2: Storage<T, R2, C2>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
210 ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
211 {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
212 m1.zip_fold(m2, T::SimdRealField::zero(), |acc, a, b| {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
213 let diff = a - b;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
214 acc + diff.simd_modulus_squared()
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
215 })
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
216 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
217
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
218 // TODO: should allow different input storages in `Euclidean`.
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
219
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
220 impl<E,M,K,S> HasScalarField
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
221 for Matrix<E,M,K,S>
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
222 where M : Dim, K : Dim,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
223 S : Storage<E,M,K>,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
224 E : Float + Scalar,
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
225 DefaultAllocator : Allocator<E,M,K> {
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
226 type Field = E;
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
227 }
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
228
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
229 impl<E,M,S> Euclidean
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
230 for Vector<E,M,S>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
231 where M : Dim,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
232 S : StorageMut<E,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
233 E : Float + Scalar + ClosedMul + ClosedAdd + Zero + One + RealField,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
234 DefaultAllocator : Allocator<E,M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
235
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
236 type Output = OVector<E, M>;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
237
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
238 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
239 fn similar_origin(&self) -> OVector<E, M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
240 OVector::zeros_generic(M::from_usize(self.len()), Const)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
241 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
242
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
243 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
244 fn norm2_squared(&self) -> E {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
245 Vector::<E,M,S>::norm_squared(self)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
246 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
247
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
248 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
249 fn dist2_squared(&self, other : &Self) -> E {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
250 metric_distance_squared(self, other)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
251 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
252 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
253
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
254 impl<E,M,S> StaticEuclidean
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
255 for Vector<E,M,S>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
256 where M : DimName,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
257 S : StorageMut<E,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
258 E : Float + Scalar + ClosedMul + ClosedAdd + Zero + One + RealField,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
259 DefaultAllocator : Allocator<E,M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
260
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
261 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
262 fn origin() -> OVector<E, M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
263 OVector::zeros()
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
264 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
265 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
266
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
267 impl<E,M,S> Norm<L1>
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
268 for Vector<E,M,S>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
269 where M : Dim,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
270 S : StorageMut<E,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
271 E : Float + Scalar + ClosedMul + ClosedAdd + Zero + One + RealField,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
272 DefaultAllocator : Allocator<E,M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
273
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
274 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
275 fn norm(&self, _ : L1) -> E {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
276 LpNorm(1).norm(self)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
277 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
278 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
279
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
280 impl<E,M,S> Dist<L1>
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
281 for Vector<E,M,S>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
282 where M : Dim,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
283 S : StorageMut<E,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
284 E : Float + Scalar + ClosedMul + ClosedAdd + Zero + One + RealField,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
285 DefaultAllocator : Allocator<E,M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
286 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
287 fn dist(&self, other : &Self, _ : L1) -> E {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
288 LpNorm(1).metric_distance(self, other)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
289 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
290 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
291
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
292 impl<E,M,S> Norm<L2>
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
293 for Vector<E,M,S>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
294 where M : Dim,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
295 S : StorageMut<E,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
296 E : Float + Scalar + ClosedMul + ClosedAdd + Zero + One + RealField,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
297 DefaultAllocator : Allocator<E,M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
298
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
299 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
300 fn norm(&self, _ : L2) -> E {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
301 LpNorm(2).norm(self)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
302 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
303 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
304
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
305 impl<E,M,S> Dist<L2>
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
306 for Vector<E,M,S>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
307 where M : Dim,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
308 S : StorageMut<E,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
309 E : Float + Scalar + ClosedMul + ClosedAdd + Zero + One + RealField,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
310 DefaultAllocator : Allocator<E,M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
311 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
312 fn dist(&self, other : &Self, _ : L2) -> E {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
313 LpNorm(2).metric_distance(self, other)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
314 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
315 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
316
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
317 impl<E,M,S> Norm<Linfinity>
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
318 for Vector<E,M,S>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
319 where M : Dim,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
320 S : StorageMut<E,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
321 E : Float + Scalar + ClosedMul + ClosedAdd + Zero + One + RealField,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
322 DefaultAllocator : Allocator<E,M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
323
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
324 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
325 fn norm(&self, _ : Linfinity) -> E {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
326 UniformNorm.norm(self)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
327 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
328 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
329
81
d2acaaddd9af Try to have Field as member type in Mappings etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
330 impl<E,M,S> Dist<Linfinity>
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
331 for Vector<E,M,S>
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
332 where M : Dim,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
333 S : StorageMut<E,M>,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
334 E : Float + Scalar + ClosedMul + ClosedAdd + Zero + One + RealField,
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
335 DefaultAllocator : Allocator<E,M> {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
336 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
337 fn dist(&self, other : &Self, _ : Linfinity) -> E {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
338 UniformNorm.metric_distance(self, other)
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
339 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
340 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
341
5
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
342 /// Helper trait to hide the symbols of [`nalgebra::RealField`].
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
343 ///
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
344 /// By assuming `ToNalgebraRealField` intead of `nalgebra::RealField` as a trait bound,
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
345 /// functions can piggyback `nalgebra::RealField` without exponsing themselves to it.
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
346 /// Thus methods from [`num_traits`] can be used directly without similarly named methods
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
347 /// from [`nalgebra`] conflicting with them. Only when absolutely necessary to work with
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
348 /// nalgebra, one can convert to the nalgebra view of the same type using the methods of
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
349 /// this trait.
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
350 pub trait ToNalgebraRealField : Float {
5
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
351 /// The nalgebra type corresponding to this type. Usually same as `Self`.
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
352 ///
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
353 /// This type only carries `nalgebra` traits.
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
354 type NalgebraType : RealField;
5
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
355 /// The “mixed” type corresponding to this type. Usually same as `Self`.
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
356 ///
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
357 /// This type carries both `num_traits` and `nalgebra` traits.
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
358 type MixedType : RealField + Float;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
359
5
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
360 /// Convert to the nalgebra view of `self`.
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
361 fn to_nalgebra(self) -> Self::NalgebraType;
5
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
362
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
363 /// Convert to the mixed (nalgebra and num_traits) view of `self`.
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
364 fn to_nalgebra_mixed(self) -> Self::MixedType;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
365
5
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
366 /// Convert from the nalgebra view of `self`.
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
367 fn from_nalgebra(t : Self::NalgebraType) -> Self;
5
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
368
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
369 /// Convert from the mixed (nalgebra and num_traits) view to `self`.
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
370 fn from_nalgebra_mixed(t : Self::MixedType) -> Self;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
371 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
372
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
373 impl ToNalgebraRealField for f32 {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
374 type NalgebraType = f32;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
375 type MixedType = f32;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
376
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
377 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
378 fn to_nalgebra(self) -> Self::NalgebraType { self }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
379
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
380 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
381 fn to_nalgebra_mixed(self) -> Self::MixedType { self }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
382
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
383 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
384 fn from_nalgebra(t : Self::NalgebraType) -> Self { t }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
385
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
386 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
387 fn from_nalgebra_mixed(t : Self::MixedType) -> Self { t }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
388
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
389 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
390
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
391 impl ToNalgebraRealField for f64 {
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
392 type NalgebraType = f64;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
393 type MixedType = f64;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
394
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
395 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
396 fn to_nalgebra(self) -> Self::NalgebraType { self }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
397
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
398 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
399 fn to_nalgebra_mixed(self) -> Self::MixedType { self }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
400
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
401 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
402 fn from_nalgebra(t : Self::NalgebraType) -> Self { t }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
403
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
404 #[inline]
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
405 fn from_nalgebra_mixed(t : Self::MixedType) -> Self { t }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
406 }
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
407

mercurial