| 157 // TODO: should not turn non-owned matrices into owned |
157 // TODO: should not turn non-owned matrices into owned |
| 158 f(self.into_owned()) |
158 f(self.into_owned()) |
| 159 } |
159 } |
| 160 |
160 |
| 161 #[inline] |
161 #[inline] |
| 162 fn eval_decompose<'b, R>(self, f: impl FnOnce(OMatrix<E, M, K>) -> R) -> R |
162 fn eval_ref<'b, R>( |
| 163 where |
|
| 164 Self: 'b, |
|
| 165 { |
|
| 166 f(self.into_owned()) |
|
| 167 } |
|
| 168 |
|
| 169 #[inline] |
|
| 170 fn eval_ref_decompose<'b, R>( |
|
| 171 &'b self, |
163 &'b self, |
| 172 f: impl FnOnce(<MatrixDecomposition as Decomposition<Matrix<E, M, K, S1>>>::Reference<'b>) -> R, |
164 f: impl FnOnce(<MatrixDecomposition as Decomposition<Matrix<E, M, K, S1>>>::Reference<'b>) -> R, |
| 173 ) -> R |
165 ) -> R |
| 174 where |
166 where |
| 175 Self: 'b, |
167 Self: 'b, |
| 187 fn cow<'b>(self) -> MyCow<'b, OMatrix<E, M, K>> |
179 fn cow<'b>(self) -> MyCow<'b, OMatrix<E, M, K>> |
| 188 where |
180 where |
| 189 Self: 'b, |
181 Self: 'b, |
| 190 { |
182 { |
| 191 self.cow_owned() |
183 self.cow_owned() |
| |
184 } |
| |
185 |
| |
186 #[inline] |
| |
187 fn decompose<'b>(self) -> OMatrix<E, M, K> |
| |
188 where |
| |
189 Self: 'b, |
| |
190 { |
| |
191 self.into_owned() |
| 192 } |
192 } |
| 193 } |
193 } |
| 194 |
194 |
| 195 impl<'a, S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> |
195 impl<'a, S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> |
| 196 for &'a Matrix<E, M, K, S2> |
196 for &'a Matrix<E, M, K, S2> |
| 213 Self: 'b, |
213 Self: 'b, |
| 214 { |
214 { |
| 215 g(self.as_view()) |
215 g(self.as_view()) |
| 216 } |
216 } |
| 217 |
217 |
| 218 fn eval_decompose<'b, R>(self, f: impl FnOnce(OMatrix<E, M, K>) -> R) -> R |
218 fn eval_ref<'b, R>( |
| 219 where |
|
| 220 Self: 'b, |
|
| 221 { |
|
| 222 f(self.into_owned()) |
|
| 223 } |
|
| 224 |
|
| 225 fn eval_ref_decompose<'b, R>( |
|
| 226 &'b self, |
219 &'b self, |
| 227 f: impl FnOnce(<MatrixDecomposition as Decomposition<Matrix<E, M, K, S1>>>::Reference<'b>) -> R, |
220 f: impl FnOnce(<MatrixDecomposition as Decomposition<Matrix<E, M, K, S1>>>::Reference<'b>) -> R, |
| 228 ) -> R |
221 ) -> R |
| 229 where |
222 where |
| 230 Self: 'b, |
223 Self: 'b, |
| 242 fn cow<'b>(self) -> MyCow<'b, OMatrix<E, M, K>> |
235 fn cow<'b>(self) -> MyCow<'b, OMatrix<E, M, K>> |
| 243 where |
236 where |
| 244 Self: 'b, |
237 Self: 'b, |
| 245 { |
238 { |
| 246 self.cow_owned() |
239 self.cow_owned() |
| |
240 } |
| |
241 |
| |
242 #[inline] |
| |
243 fn decompose<'b>(self) -> OMatrix<E, M, K> |
| |
244 where |
| |
245 Self: 'b, |
| |
246 { |
| |
247 self.into_owned() |
| 247 } |
248 } |
| 248 } |
249 } |
| 249 |
250 |
| 250 impl<SM, N, M, K, E> Mapping<OMatrix<E, M, K>> for Matrix<E, N, M, SM> |
251 impl<SM, N, M, K, E> Mapping<OMatrix<E, M, K>> for Matrix<E, N, M, SM> |
| 251 where |
252 where |
| 342 }) |
343 }) |
| 343 } |
344 } |
| 344 |
345 |
| 345 #[inline] |
346 #[inline] |
| 346 fn copy_from<I: Instance<Matrix<E, M, N, SV1>>>(&mut self, y: I) { |
347 fn copy_from<I: Instance<Matrix<E, M, N, SV1>>>(&mut self, y: I) { |
| 347 y.eval(|ỹ| Matrix::copy_from(self, ỹ)) |
348 y.eval_ref(|ỹ| Matrix::copy_from(self, &ỹ)) |
| 348 } |
349 } |
| 349 |
350 |
| 350 #[inline] |
351 #[inline] |
| 351 fn set_zero(&mut self) { |
352 fn set_zero(&mut self) { |
| 352 self.iter_mut().for_each(|e| *e = E::ZERO); |
353 self.iter_mut().for_each(|e| *e = E::ZERO); |
| 456 { |
457 { |
| 457 type PrincipalE = OVector<E, M>; |
458 type PrincipalE = OVector<E, M>; |
| 458 |
459 |
| 459 #[inline] |
460 #[inline] |
| 460 fn dot<I: Instance<Self>>(&self, other: I) -> E { |
461 fn dot<I: Instance<Self>>(&self, other: I) -> E { |
| 461 other.eval_ref_decompose(|ref r| Vector::<E, M, S>::dot(self, r)) |
462 other.eval_ref(|ref r| Vector::<E, M, S>::dot(self, r)) |
| 462 } |
463 } |
| 463 |
464 |
| 464 #[inline] |
465 #[inline] |
| 465 fn norm2_squared(&self) -> E { |
466 fn norm2_squared(&self) -> E { |
| 466 Vector::<E, M, S>::norm_squared(self) |
467 Vector::<E, M, S>::norm_squared(self) |
| 467 } |
468 } |
| 468 |
469 |
| 469 #[inline] |
470 #[inline] |
| 470 fn dist2_squared<I: Instance<Self>>(&self, other: I) -> E { |
471 fn dist2_squared<I: Instance<Self>>(&self, other: I) -> E { |
| 471 other.eval_ref_decompose(|ref r| metric_distance_squared(self, r)) |
472 other.eval_ref(|ref r| metric_distance_squared(self, r)) |
| 472 } |
473 } |
| 473 } |
474 } |
| 474 |
475 |
| 475 impl<E, M, S> StaticEuclidean<E> for Vector<E, M, S> |
476 impl<E, M, S> StaticEuclidean<E> for Vector<E, M, S> |
| 476 where |
477 where |
| 545 DefaultAllocator: Allocator<M>, |
546 DefaultAllocator: Allocator<M>, |
| 546 ShapeConstraint: StridesOk<E, M, U1, S>, |
547 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 547 { |
548 { |
| 548 #[inline] |
549 #[inline] |
| 549 fn dist<I: Instance<Self>>(&self, other: I, _: L1) -> E { |
550 fn dist<I: Instance<Self>>(&self, other: I, _: L1) -> E { |
| 550 other.eval_ref_decompose(|ref r| nalgebra::Norm::metric_distance(&LpNorm(1), self, r)) |
551 other.eval_ref(|ref r| nalgebra::Norm::metric_distance(&LpNorm(1), self, r)) |
| 551 } |
552 } |
| 552 } |
553 } |
| 553 |
554 |
| 554 impl<E, M, S> Norm<L2, E> for Vector<E, M, S> |
555 impl<E, M, S> Norm<L2, E> for Vector<E, M, S> |
| 555 where |
556 where |
| 573 DefaultAllocator: Allocator<M>, |
574 DefaultAllocator: Allocator<M>, |
| 574 ShapeConstraint: StridesOk<E, M, U1, S>, |
575 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 575 { |
576 { |
| 576 #[inline] |
577 #[inline] |
| 577 fn dist<I: Instance<Self>>(&self, other: I, _: L2) -> E { |
578 fn dist<I: Instance<Self>>(&self, other: I, _: L2) -> E { |
| 578 other.eval_ref_decompose(|ref r| nalgebra::Norm::metric_distance(&LpNorm(2), self, r)) |
579 other.eval_ref(|ref r| nalgebra::Norm::metric_distance(&LpNorm(2), self, r)) |
| 579 } |
580 } |
| 580 } |
581 } |
| 581 |
582 |
| 582 impl<E, M, S> Norm<Linfinity, E> for Vector<E, M, S> |
583 impl<E, M, S> Norm<Linfinity, E> for Vector<E, M, S> |
| 583 where |
584 where |
| 601 DefaultAllocator: Allocator<M>, |
602 DefaultAllocator: Allocator<M>, |
| 602 ShapeConstraint: StridesOk<E, M, U1, S>, |
603 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 603 { |
604 { |
| 604 #[inline] |
605 #[inline] |
| 605 fn dist<I: Instance<Self>>(&self, other: I, _: Linfinity) -> E { |
606 fn dist<I: Instance<Self>>(&self, other: I, _: Linfinity) -> E { |
| 606 other.eval_ref_decompose(|ref r| nalgebra::Norm::metric_distance(&UniformNorm, self, r)) |
607 other.eval_ref(|ref r| nalgebra::Norm::metric_distance(&UniformNorm, self, r)) |
| 607 } |
608 } |
| 608 } |
609 } |
| 609 |
610 |
| 610 /// Helper trait to hide the symbols of [`nalgebra::RealField`]. |
611 /// Helper trait to hide the symbols of [`nalgebra::RealField`]. |
| 611 /// |
612 /// |