| 17 use nalgebra::base::constraint::{DimEq, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; |
17 use nalgebra::base::constraint::{DimEq, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; |
| 18 use nalgebra::base::dimension::*; |
18 use nalgebra::base::dimension::*; |
| 19 use nalgebra::{ |
19 use nalgebra::{ |
| 20 ClosedAddAssign, ClosedMulAssign, DefaultAllocator, Dim, LpNorm, Matrix, MatrixView, OMatrix, |
20 ClosedAddAssign, ClosedMulAssign, DefaultAllocator, Dim, LpNorm, Matrix, MatrixView, OMatrix, |
| 21 OVector, RawStorage, RealField, Scalar, SimdComplexField, Storage, StorageMut, UniformNorm, |
21 OVector, RawStorage, RealField, Scalar, SimdComplexField, Storage, StorageMut, UniformNorm, |
| 22 Vector, |
22 Vector, U1, |
| 23 }; |
23 }; |
| 24 use num_traits::identities::{One, Zero}; |
24 use num_traits::identities::{One, Zero}; |
| 25 use std::ops::Mul; |
25 use std::ops::Mul; |
| 26 |
26 |
| 27 impl<S, M, N, E> Ownable for Matrix<E, M, N, S> |
27 impl<S, M, N, E> Ownable for Matrix<E, M, N, S> |
| 43 fn clone_owned(&self) -> Self::OwnedVariant { |
43 fn clone_owned(&self) -> Self::OwnedVariant { |
| 44 Matrix::clone_owned(self) |
44 Matrix::clone_owned(self) |
| 45 } |
45 } |
| 46 } |
46 } |
| 47 |
47 |
| |
48 trait StridesOk<E, N, M = U1, S = <DefaultAllocator as Allocator<N, M>>::Buffer<E>>: |
| |
49 DimEq<Dyn, S::RStride> |
| |
50 + DimEq<Dyn, S::CStride> |
| |
51 + DimEq<Dyn, <<DefaultAllocator as Allocator<N, M>>::Buffer<E> as RawStorage<E, N, M>>::RStride> |
| |
52 + DimEq<Dyn, <<DefaultAllocator as Allocator<N, M>>::Buffer<E> as RawStorage<E, N, M>>::CStride> |
| |
53 where |
| |
54 S: RawStorage<E, N, M>, |
| |
55 E: Scalar, |
| |
56 N: Dim, |
| |
57 M: Dim, |
| |
58 DefaultAllocator: Allocator<N, M>, |
| |
59 { |
| |
60 } |
| |
61 |
| |
62 impl<S, E, N, M> StridesOk<E, N, M, S> for ShapeConstraint |
| |
63 where |
| |
64 ShapeConstraint: DimEq<Dyn, S::RStride> |
| |
65 + DimEq<Dyn, S::CStride> |
| |
66 + DimEq< |
| |
67 Dyn, |
| |
68 <<DefaultAllocator as Allocator<N, M>>::Buffer<E> as RawStorage<E, N, M>>::RStride, |
| |
69 > + DimEq< |
| |
70 Dyn, |
| |
71 <<DefaultAllocator as Allocator<N, M>>::Buffer<E> as RawStorage<E, N, M>>::CStride, |
| |
72 >, |
| |
73 S: Storage<E, N, M>, |
| |
74 E: Scalar, |
| |
75 N: Dim, |
| |
76 M: Dim, |
| |
77 DefaultAllocator: Allocator<N, M>, |
| |
78 { |
| |
79 } |
| |
80 |
| 48 impl<SM, N, M, E> Space for Matrix<E, N, M, SM> |
81 impl<SM, N, M, E> Space for Matrix<E, N, M, SM> |
| 49 where |
82 where |
| 50 SM: Storage<E, N, M>, |
83 SM: Storage<E, N, M>, |
| 51 N: Dim, |
84 N: Dim, |
| 52 M: Dim, |
85 M: Dim, |
| 53 E: Scalar + Zero + One, |
86 E: Scalar + Zero + One, |
| 54 DefaultAllocator: Allocator<N, M>, |
87 DefaultAllocator: Allocator<N, M>, |
| |
88 ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, N, M>, |
| 55 { |
89 { |
| 56 type OwnedSpace = OMatrix<E, N, M>; |
90 type OwnedSpace = OMatrix<E, N, M>; |
| 57 type Decomp = MatrixDecomposition; |
91 type Decomp = MatrixDecomposition; |
| 58 } |
92 } |
| 59 |
93 |
| 60 #[derive(Copy, Clone, Debug)] |
94 #[derive(Copy, Clone, Debug)] |
| 61 pub struct MatrixDecomposition; |
95 pub struct MatrixDecomposition; |
| 62 |
96 |
| |
97 /// nalgebra [`Storage`] that's convertible to dynamic strides (practically all, but we need this |
| |
98 /// to work around the type system). |
| |
99 trait ViewableStorage<E, M, K = U1>: Storage<E, M, K> |
| |
100 where |
| |
101 M: Dim, |
| |
102 K: Dim, |
| |
103 E: Scalar, |
| |
104 ShapeConstraint: StridesOk<E, M, K, Self>, |
| |
105 DefaultAllocator: Allocator<M, K>, |
| |
106 { |
| |
107 } |
| |
108 |
| |
109 impl<M, K, E, S> ViewableStorage<E, M, K> for S |
| |
110 where |
| |
111 S: Storage<E, M, K>, |
| |
112 M: Dim, |
| |
113 K: Dim, |
| |
114 E: Scalar, |
| |
115 ShapeConstraint: StridesOk<E, M, K, Self>, |
| |
116 DefaultAllocator: Allocator<M, K>, |
| |
117 { |
| |
118 } |
| |
119 |
| |
120 /// nalgebra [`StorageMut`] that's convertible to dynamic strides (practically all, but we need this |
| |
121 /// to work around the type system). |
| |
122 trait ViewableStorageMut<E, M, K = U1>: StorageMut<E, M, K> |
| |
123 where |
| |
124 M: Dim, |
| |
125 K: Dim, |
| |
126 E: Scalar, |
| |
127 ShapeConstraint: StridesOk<E, M, K, Self>, |
| |
128 DefaultAllocator: Allocator<M, K>, |
| |
129 { |
| |
130 } |
| |
131 |
| |
132 impl<M, K, E, S> ViewableStorageMut<E, M, K> for S |
| |
133 where |
| |
134 S: StorageMut<E, M, K>, |
| |
135 M: Dim, |
| |
136 K: Dim, |
| |
137 E: Scalar, |
| |
138 ShapeConstraint: StridesOk<E, M, K, Self>, |
| |
139 DefaultAllocator: Allocator<M, K>, |
| |
140 { |
| |
141 } |
| |
142 |
| 63 impl<E, M, K, S> Decomposition<Matrix<E, M, K, S>> for MatrixDecomposition |
143 impl<E, M, K, S> Decomposition<Matrix<E, M, K, S>> for MatrixDecomposition |
| 64 where |
144 where |
| 65 S: Storage<E, M, K>, |
145 S: ViewableStorage<E, M, K>, |
| 66 M: Dim, |
146 M: Dim, |
| 67 K: Dim, |
147 K: Dim, |
| 68 E: Scalar + Zero + One, |
148 E: Scalar + Zero + One, |
| 69 DefaultAllocator: Allocator<M, K>, |
149 DefaultAllocator: Allocator<M, K>, |
| |
150 ShapeConstraint: StridesOk<E, M, K, S> + StridesOk<E, M, K>, |
| 70 { |
151 { |
| 71 type OwnedInstance = OMatrix<E, M, K>; |
152 type OwnedInstance = OMatrix<E, M, K>; |
| 72 |
153 |
| 73 type Decomposition<'b> |
154 type Decomposition<'b> |
| 74 = OMatrix<E, M, K> |
155 = OMatrix<E, M, K> |
| 86 { |
167 { |
| 87 r.into_owned() |
168 r.into_owned() |
| 88 } |
169 } |
| 89 } |
170 } |
| 90 |
171 |
| 91 macro_rules! impl_instances { |
172 impl<S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> for Matrix<E, M, K, S2> |
| 92 ($rstride:ty, $cstride:ty where $($qual:tt)*) => { |
173 where |
| 93 impl<$($qual)* S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> for Matrix<E, M, K, S2> |
174 S1: ViewableStorage<E, M, K>, |
| 94 where |
175 S2: ViewableStorage<E, M, K>, |
| 95 S1: Storage<E, M, K>, |
176 M: Dim, |
| 96 S2: RawStorage<E, M, K, RStride=$rstride, CStride=$cstride>, |
177 K: Dim, |
| 97 //ShapeConstraint: DimEq<Dyn, <S2 as RawStorage<E, M, K>>::RStride> |
178 E: Scalar + Zero + One, |
| 98 // + DimEq<Dyn, <S2 as RawStorage<E, M, K>>::CStride>, |
179 DefaultAllocator: Allocator<M, K>, |
| 99 M: Dim, |
180 ShapeConstraint: StridesOk<E, M, K, S1> + StridesOk<E, M, K, S2>, |
| 100 K: Dim, |
181 { |
| 101 E: Scalar + Zero + One, |
182 fn eval_decompose<'b, R>(self, f: impl FnOnce(OMatrix<E, M, K>) -> R) -> R |
| 102 DefaultAllocator: Allocator<M, K>, |
183 where |
| 103 { |
184 Self: 'b, |
| 104 fn eval_decompose<'b, R>(self, f: impl FnOnce(OMatrix<E, M, K>) -> R) -> R |
185 { |
| 105 where |
186 f(self.into_owned()) |
| 106 Self: 'b, |
187 } |
| 107 { |
188 |
| 108 f(self.into_owned()) |
189 fn eval_ref_decompose<'b, R>( |
| 109 } |
190 &'b self, |
| 110 |
191 f: impl FnOnce(<MatrixDecomposition as Decomposition<Matrix<E, M, K, S1>>>::Reference<'b>) -> R, |
| 111 fn eval_ref_decompose<'b, R>( |
192 ) -> R |
| 112 &'b self, |
193 where |
| 113 f: impl FnOnce(<MatrixDecomposition as Decomposition<Matrix<E, M, K, S1>>>::Reference<'b>) -> R, |
194 Self: 'b, |
| 114 ) -> R |
195 Matrix<E, M, K, S1>: 'b, |
| 115 where |
196 { |
| 116 Self: 'b, |
197 f(self.as_view::<M, K, Dyn, Dyn>()) |
| 117 Matrix<E, M, K, S1>: 'b, |
198 } |
| 118 { |
199 |
| 119 f(self.as_view::<M, K, Dyn, Dyn>()) |
200 #[inline] |
| 120 } |
201 fn own(self) -> OMatrix<E, M, K> { |
| 121 |
202 self.into_owned() |
| 122 #[inline] |
203 } |
| 123 fn own(self) -> OMatrix<E, M, K> { |
204 } |
| 124 self.into_owned() |
205 |
| 125 } |
206 impl<'a, S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> |
| 126 } |
207 for &'a Matrix<E, M, K, S2> |
| 127 |
208 where |
| 128 impl<'a, $($qual)* S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> |
209 S1: ViewableStorage<E, M, K>, |
| 129 for &'a Matrix<E, M, K, S2> |
210 S2: ViewableStorage<E, M, K>, |
| 130 where |
211 M: Dim, |
| 131 S1: Storage<E, M, K>, |
212 K: Dim, |
| 132 S2: RawStorage<E, M, K, RStride=$rstride, CStride=$cstride>, |
213 E: Scalar + Zero + One, |
| 133 M: Dim, |
214 DefaultAllocator: Allocator<M, K>, |
| 134 K: Dim, |
215 ShapeConstraint: StridesOk<E, M, K, S1> + StridesOk<E, M, K, S2>, |
| 135 E: Scalar + Zero + One, |
216 { |
| 136 DefaultAllocator: Allocator<M, K>, |
217 fn eval_decompose<'b, R>(self, f: impl FnOnce(OMatrix<E, M, K>) -> R) -> R |
| 137 { |
218 where |
| 138 fn eval_decompose<'b, R>(self, f: impl FnOnce(OMatrix<E, M, K>) -> R) -> R |
219 Self: 'b, |
| 139 where |
220 { |
| 140 Self: 'b, |
221 f(self.into_owned()) |
| 141 { |
222 } |
| 142 f(self.into_owned()) |
223 |
| 143 } |
224 fn eval_ref_decompose<'b, R>( |
| 144 |
225 &'b self, |
| 145 fn eval_ref_decompose<'b, R>( |
226 f: impl FnOnce(<MatrixDecomposition as Decomposition<Matrix<E, M, K, S1>>>::Reference<'b>) -> R, |
| 146 &'b self, |
227 ) -> R |
| 147 f: impl FnOnce(<MatrixDecomposition as Decomposition<Matrix<E, M, K, S1>>>::Reference<'b>) -> R, |
228 where |
| 148 ) -> R |
229 Self: 'b, |
| 149 where |
230 Matrix<E, M, K, S1>: 'b, |
| 150 Self: 'b, |
231 { |
| 151 Matrix<E, M, K, S1>: 'b, |
232 f((*self).as_view::<M, K, Dyn, Dyn>()) |
| 152 { |
233 } |
| 153 f((*self).as_view::<M, K, Dyn, Dyn>()) |
234 |
| 154 } |
235 #[inline] |
| 155 |
236 fn own(self) -> OMatrix<E, M, K> { |
| 156 #[inline] |
237 self.into_owned() |
| 157 fn own(self) -> OMatrix<E, M, K> { |
238 } |
| 158 self.into_owned() |
239 } |
| 159 } |
|
| 160 } |
|
| 161 }; |
|
| 162 } |
|
| 163 |
|
| 164 impl_instances!(Dyn, Dyn where ); |
|
| 165 impl_instances!(Const<RS>, Dyn where const RS : usize,); |
|
| 166 impl_instances!(Dyn, Const<CS> where const CS : usize,); |
|
| 167 impl_instances!(Const<RS>, Const<CS> where const RS : usize, const CS : usize,); |
|
| 168 |
240 |
| 169 impl<SM, SV, N, M, K, E> Mapping<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM> |
241 impl<SM, SV, N, M, K, E> Mapping<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM> |
| 170 where |
242 where |
| 171 SM: Storage<E, N, M>, |
243 SM: ViewableStorage<E, N, M>, |
| 172 SV: Storage<E, M, K> + Clone, |
244 SV: ViewableStorage<E, M, K> + Clone, |
| 173 N: Dim, |
245 N: Dim, |
| 174 M: Dim, |
246 M: Dim, |
| 175 K: Dim, |
247 K: Dim, |
| 176 E: Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, |
248 E: Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, |
| 177 DefaultAllocator: Allocator<N, K>, |
249 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
| 178 DefaultAllocator: Allocator<M, K>, |
250 ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, M, K, SV> + StridesOk<E, N, K>, |
| 179 DefaultAllocator: Allocator<N, M>, |
|
| 180 DefaultAllocator: Allocator<M, N>, |
|
| 181 { |
251 { |
| 182 type Codomain = OMatrix<E, N, K>; |
252 type Codomain = OMatrix<E, N, K>; |
| 183 |
253 |
| 184 #[inline] |
254 #[inline] |
| 185 fn apply<I: Instance<Matrix<E, M, K, SV>>>(&self, x: I) -> Self::Codomain { |
255 fn apply<I: Instance<Matrix<E, M, K, SV>>>(&self, x: I) -> Self::Codomain { |
| 187 } |
257 } |
| 188 } |
258 } |
| 189 |
259 |
| 190 impl<'a, SM, SV, N, M, K, E> Linear<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM> |
260 impl<'a, SM, SV, N, M, K, E> Linear<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM> |
| 191 where |
261 where |
| 192 SM: Storage<E, N, M>, |
262 SM: ViewableStorage<E, N, M>, |
| 193 SV: Storage<E, M, K> + Clone, |
263 SV: ViewableStorage<E, M, K> + Clone, |
| 194 N: Dim, |
264 N: Dim, |
| 195 M: Dim, |
265 M: Dim, |
| 196 K: Dim, |
266 K: Dim, |
| 197 E: Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, |
267 E: Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, |
| 198 DefaultAllocator: Allocator<N, K>, |
268 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
| 199 DefaultAllocator: Allocator<M, K>, |
269 ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, M, K, SV> + StridesOk<E, N, K>, |
| 200 DefaultAllocator: Allocator<N, M>, |
|
| 201 DefaultAllocator: Allocator<M, N>, |
|
| 202 { |
270 { |
| 203 } |
271 } |
| 204 |
272 |
| 205 impl<SM, SV1, SV2, N, M, K, E> GEMV<E, Matrix<E, M, K, SV1>, Matrix<E, N, K, SV2>> |
273 impl<SM, SV1, SV2, N, M, K, E> GEMV<E, Matrix<E, M, K, SV1>, Matrix<E, N, K, SV2>> |
| 206 for Matrix<E, N, M, SM> |
274 for Matrix<E, N, M, SM> |
| 207 where |
275 where |
| 208 SM: Storage<E, N, M>, |
276 SM: ViewableStorage<E, N, M>, |
| 209 SV1: Storage<E, M, K> + Clone, |
277 SV1: ViewableStorage<E, M, K> + Clone, |
| 210 SV2: StorageMut<E, N, K>, |
278 SV2: ViewableStorageMut<E, N, K>, |
| 211 N: Dim, |
279 N: Dim, |
| 212 M: Dim, |
280 M: Dim, |
| 213 K: Dim, |
281 K: Dim, |
| 214 E: Scalar + Zero + One + Float, |
282 E: Scalar + Zero + One + Float, |
| 215 DefaultAllocator: Allocator<N, K>, |
283 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
| 216 DefaultAllocator: Allocator<M, K>, |
284 ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, M, K, SV1> + StridesOk<E, N, K, SV2>, |
| 217 DefaultAllocator: Allocator<N, M>, |
|
| 218 DefaultAllocator: Allocator<M, N>, |
|
| 219 { |
285 { |
| 220 #[inline] |
286 #[inline] |
| 221 fn gemv<I: Instance<Matrix<E, M, K, SV1>>>( |
287 fn gemv<I: Instance<Matrix<E, M, K, SV1>>>( |
| 222 &self, |
288 &self, |
| 223 y: &mut Matrix<E, N, K, SV2>, |
289 y: &mut Matrix<E, N, K, SV2>, |
| 252 } |
319 } |
| 253 } |
320 } |
| 254 |
321 |
| 255 impl<SM, SV1, M, N, E> AXPY<Matrix<E, M, N, SV1>> for Matrix<E, M, N, SM> |
322 impl<SM, SV1, M, N, E> AXPY<Matrix<E, M, N, SV1>> for Matrix<E, M, N, SM> |
| 256 where |
323 where |
| 257 SM: StorageMut<E, M, N>, |
324 SM: ViewableStorageMut<E, M, N>, |
| 258 SV1: Storage<E, M, N>, |
325 SV1: ViewableStorage<E, M, N>, |
| 259 M: Dim, |
326 M: Dim, |
| 260 N: Dim, |
327 N: Dim, |
| 261 E: Scalar + Zero + One + Float, |
328 E: Scalar + Zero + One + Float, |
| 262 DefaultAllocator: Allocator<M, N>, |
329 DefaultAllocator: Allocator<M, N>, |
| |
330 ShapeConstraint: StridesOk<E, M, N, SM> + StridesOk<E, M, N, SV1>, |
| 263 { |
331 { |
| 264 #[inline] |
332 #[inline] |
| 265 fn axpy<I: Instance<Matrix<E, M, N, SV1>>>(&mut self, α: E, x: I, β: E) { |
333 fn axpy<I: Instance<Matrix<E, M, N, SV1>>>(&mut self, α: E, x: I, β: E) { |
| 266 x.eval(|x̃| { |
334 x.eval(|x̃| { |
| 267 assert_eq!(self.ncols(), x̃.ncols()); |
335 assert_eq!(self.ncols(), x̃.ncols()); |
| 328 } |
398 } |
| 329 |
399 |
| 330 impl<'own, SV1, SV2, SM, N, M, K, E> Adjointable<Matrix<E, M, K, SV1>, Matrix<E, N, K, SV2>> |
400 impl<'own, SV1, SV2, SM, N, M, K, E> Adjointable<Matrix<E, M, K, SV1>, Matrix<E, N, K, SV2>> |
| 331 for Matrix<E, N, M, SM> |
401 for Matrix<E, N, M, SM> |
| 332 where |
402 where |
| 333 SM: Storage<E, N, M>, |
403 SM: ViewableStorage<E, N, M>, |
| 334 SV1: Storage<E, M, K> + Clone, |
404 SV1: ViewableStorage<E, M, K> + Clone, |
| 335 SV2: Storage<E, N, K> + Clone, |
405 SV2: ViewableStorage<E, N, K> + Clone, |
| 336 N: Dim, |
406 N: Dim, |
| 337 M: Dim, |
407 M: Dim, |
| 338 K: Dim, |
408 K: Dim, |
| 339 E: Scalar + Zero + One + SimdComplexField, |
409 E: Scalar + Zero + One + SimdComplexField, |
| 340 DefaultAllocator: Allocator<N, K>, |
410 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
| 341 DefaultAllocator: Allocator<M, K>, |
411 ShapeConstraint: StridesOk<E, N, M, SM> |
| 342 DefaultAllocator: Allocator<N, M>, |
412 + StridesOk<E, M, K, SV1> |
| 343 DefaultAllocator: Allocator<M, N>, |
413 + StridesOk<E, N, K, SV2> |
| |
414 + StridesOk<E, M, N>, |
| 344 { |
415 { |
| 345 type AdjointCodomain = OMatrix<E, M, K>; |
416 type AdjointCodomain = OMatrix<E, M, K>; |
| 346 type Adjoint<'a> |
417 type Adjoint<'a> |
| 347 = OMatrix<E, M, N> |
418 = OMatrix<E, M, N> |
| 348 where |
419 where |
| 453 } |
528 } |
| 454 |
529 |
| 455 impl<E, M, S> Norm<L1, E> for Vector<E, M, S> |
530 impl<E, M, S> Norm<L1, E> for Vector<E, M, S> |
| 456 where |
531 where |
| 457 M: Dim, |
532 M: Dim, |
| 458 S: Storage<E, M>, |
533 S: ViewableStorage<E, M>, |
| 459 E: Float + Scalar + Zero + One + RealField, |
534 E: Float + Scalar + Zero + One + RealField, |
| 460 DefaultAllocator: Allocator<M>, |
535 DefaultAllocator: Allocator<M>, |
| |
536 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 461 { |
537 { |
| 462 #[inline] |
538 #[inline] |
| 463 fn norm(&self, _: L1) -> E { |
539 fn norm(&self, _: L1) -> E { |
| 464 nalgebra::Norm::norm(&LpNorm(1), self) |
540 nalgebra::Norm::norm(&LpNorm(1), self) |
| 465 } |
541 } |
| 466 } |
542 } |
| 467 |
543 |
| 468 impl<E, M, S> Dist<L1, E> for Vector<E, M, S> |
544 impl<E, M, S> Dist<L1, E> for Vector<E, M, S> |
| 469 where |
545 where |
| 470 M: Dim, |
546 M: Dim, |
| 471 S: Storage<E, M> + Clone, |
547 S: ViewableStorage<E, M> + Clone, |
| 472 E: Float + Scalar + Zero + One + RealField, |
548 E: Float + Scalar + Zero + One + RealField, |
| 473 DefaultAllocator: Allocator<M>, |
549 DefaultAllocator: Allocator<M>, |
| |
550 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 474 { |
551 { |
| 475 #[inline] |
552 #[inline] |
| 476 fn dist<I: Instance<Self>>(&self, other: I, _: L1) -> E { |
553 fn dist<I: Instance<Self>>(&self, other: I, _: L1) -> E { |
| 477 other.eval_ref_decompose(|ref r| nalgebra::Norm::metric_distance(&LpNorm(1), self, r)) |
554 other.eval_ref_decompose(|ref r| nalgebra::Norm::metric_distance(&LpNorm(1), self, r)) |
| 478 } |
555 } |
| 479 } |
556 } |
| 480 |
557 |
| 481 impl<E, M, S> Norm<L2, E> for Vector<E, M, S> |
558 impl<E, M, S> Norm<L2, E> for Vector<E, M, S> |
| 482 where |
559 where |
| 483 M: Dim, |
560 M: Dim, |
| 484 S: Storage<E, M>, |
561 S: ViewableStorage<E, M>, |
| 485 E: Float + Scalar + Zero + One + RealField, |
562 E: Float + Scalar + Zero + One + RealField, |
| 486 DefaultAllocator: Allocator<M>, |
563 DefaultAllocator: Allocator<M>, |
| |
564 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 487 { |
565 { |
| 488 #[inline] |
566 #[inline] |
| 489 fn norm(&self, _: L2) -> E { |
567 fn norm(&self, _: L2) -> E { |
| 490 nalgebra::Norm::norm(&LpNorm(2), self) |
568 nalgebra::Norm::norm(&LpNorm(2), self) |
| 491 } |
569 } |
| 492 } |
570 } |
| 493 |
571 |
| 494 impl<E, M, S> Dist<L2, E> for Vector<E, M, S> |
572 impl<E, M, S> Dist<L2, E> for Vector<E, M, S> |
| 495 where |
573 where |
| 496 M: Dim, |
574 M: Dim, |
| 497 S: Storage<E, M> + Clone, |
575 S: ViewableStorage<E, M> + Clone, |
| 498 E: Float + Scalar + Zero + One + RealField, |
576 E: Float + Scalar + Zero + One + RealField, |
| 499 DefaultAllocator: Allocator<M>, |
577 DefaultAllocator: Allocator<M>, |
| |
578 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 500 { |
579 { |
| 501 #[inline] |
580 #[inline] |
| 502 fn dist<I: Instance<Self>>(&self, other: I, _: L2) -> E { |
581 fn dist<I: Instance<Self>>(&self, other: I, _: L2) -> E { |
| 503 other.eval_ref_decompose(|ref r| nalgebra::Norm::metric_distance(&LpNorm(2), self, r)) |
582 other.eval_ref_decompose(|ref r| nalgebra::Norm::metric_distance(&LpNorm(2), self, r)) |
| 504 } |
583 } |
| 505 } |
584 } |
| 506 |
585 |
| 507 impl<E, M, S> Norm<Linfinity, E> for Vector<E, M, S> |
586 impl<E, M, S> Norm<Linfinity, E> for Vector<E, M, S> |
| 508 where |
587 where |
| 509 M: Dim, |
588 M: Dim, |
| 510 S: Storage<E, M>, |
589 S: ViewableStorage<E, M>, |
| 511 E: Float + Scalar + Zero + One + RealField, |
590 E: Float + Scalar + Zero + One + RealField, |
| 512 DefaultAllocator: Allocator<M>, |
591 DefaultAllocator: Allocator<M>, |
| |
592 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 513 { |
593 { |
| 514 #[inline] |
594 #[inline] |
| 515 fn norm(&self, _: Linfinity) -> E { |
595 fn norm(&self, _: Linfinity) -> E { |
| 516 nalgebra::Norm::norm(&UniformNorm, self) |
596 nalgebra::Norm::norm(&UniformNorm, self) |
| 517 } |
597 } |
| 518 } |
598 } |
| 519 |
599 |
| 520 impl<E, M, S> Dist<Linfinity, E> for Vector<E, M, S> |
600 impl<E, M, S> Dist<Linfinity, E> for Vector<E, M, S> |
| 521 where |
601 where |
| 522 M: Dim, |
602 M: Dim, |
| 523 S: Storage<E, M> + Clone, |
603 S: ViewableStorage<E, M> + Clone, |
| 524 E: Float + Scalar + Zero + One + RealField, |
604 E: Float + Scalar + Zero + One + RealField, |
| 525 DefaultAllocator: Allocator<M>, |
605 DefaultAllocator: Allocator<M>, |
| |
606 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 526 { |
607 { |
| 527 #[inline] |
608 #[inline] |
| 528 fn dist<I: Instance<Self>>(&self, other: I, _: Linfinity) -> E { |
609 fn dist<I: Instance<Self>>(&self, other: I, _: Linfinity) -> E { |
| 529 other.eval_ref_decompose(|ref r| nalgebra::Norm::metric_distance(&UniformNorm, self, r)) |
610 other.eval_ref_decompose(|ref r| nalgebra::Norm::metric_distance(&UniformNorm, self, r)) |
| 530 } |
611 } |