| 7 force-feeding its own versions of the same basic mathematical methods on `f32` and `f64` as |
7 force-feeding its own versions of the same basic mathematical methods on `f32` and `f64` as |
| 8 [`num_traits`] does. |
8 [`num_traits`] does. |
| 9 */ |
9 */ |
| 10 |
10 |
| 11 use crate::euclidean::*; |
11 use crate::euclidean::*; |
| 12 use crate::instance::{Instance, Ownable}; |
12 use crate::instance::{Decomposition, Instance, Ownable, Space}; |
| 13 use crate::linops::*; |
13 use crate::linops::*; |
| 14 use crate::mapping::{BasicDecomposition, Space}; |
|
| 15 use crate::norms::*; |
14 use crate::norms::*; |
| 16 use crate::types::Float; |
15 use crate::types::Float; |
| 17 use nalgebra::base::allocator::Allocator; |
16 use nalgebra::base::allocator::Allocator; |
| 18 use nalgebra::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; |
17 use nalgebra::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; |
| 19 use nalgebra::base::dimension::*; |
18 use nalgebra::base::dimension::*; |
| 20 use nalgebra::{ |
19 use nalgebra::{ |
| 21 ClosedAddAssign, ClosedMulAssign, DefaultAllocator, Dim, LpNorm, Matrix, OMatrix, OVector, |
20 ClosedAddAssign, ClosedMulAssign, DefaultAllocator, Dim, LpNorm, Matrix, MatrixView, OMatrix, |
| 22 RealField, Scalar, SimdComplexField, Storage, StorageMut, UniformNorm, Vector, |
21 OVector, RealField, Scalar, SimdComplexField, Storage, StorageMut, UniformNorm, Vector, |
| 23 }; |
22 }; |
| 24 use num_traits::identities::{One, Zero}; |
23 use num_traits::identities::{One, Zero}; |
| 25 use std::ops::Mul; |
24 use std::ops::Mul; |
| 26 |
25 |
| 27 impl<S, M, N, E> Ownable for Matrix<E, M, N, S> |
26 impl<S, M, N, E> Ownable for Matrix<E, M, N, S> |
| 52 M: Dim, |
51 M: Dim, |
| 53 E: Scalar + Zero + One, |
52 E: Scalar + Zero + One, |
| 54 DefaultAllocator: Allocator<N, M>, |
53 DefaultAllocator: Allocator<N, M>, |
| 55 { |
54 { |
| 56 type OwnedSpace = OMatrix<E, N, M>; |
55 type OwnedSpace = OMatrix<E, N, M>; |
| 57 type Decomp = BasicDecomposition; |
56 type Decomp = MatrixDecomposition; |
| |
57 } |
| |
58 |
| |
59 #[derive(Copy, Clone, Debug)] |
| |
60 pub struct MatrixDecomposition; |
| |
61 |
| |
62 impl<E, M, K, S> Decomposition<Matrix<E, M, K, S>> for MatrixDecomposition |
| |
63 where |
| |
64 S: Storage<E, M, K>, |
| |
65 M: Dim, |
| |
66 K: Dim, |
| |
67 E: Scalar + Zero + One, |
| |
68 DefaultAllocator: Allocator<M, K>, |
| |
69 { |
| |
70 type OwnedInstance = OMatrix<E, M, K>; |
| |
71 |
| |
72 type Decomposition<'b> |
| |
73 = OMatrix<E, M, K> |
| |
74 where |
| |
75 Matrix<E, M, K, S>: 'b; |
| |
76 type Reference<'b> |
| |
77 = &'b MatrixView<'b, E, M, K, Dyn, Dyn> |
| |
78 where |
| |
79 Matrix<E, M, K, S>: 'b; |
| |
80 |
| |
81 #[inline] |
| |
82 fn lift<'b>(r: Self::Reference<'b>) -> Self::Decomposition<'b> { |
| |
83 r.into_owned() |
| |
84 } |
| |
85 } |
| |
86 |
| |
87 impl<SM, SV, M, K, E> Instance<Matrix<E, M, K, SM>> for Matrix<E, M, K, SV> |
| |
88 where |
| |
89 SM: Storage<E, M, K>, |
| |
90 SV: Storage<E, M, K>, |
| |
91 M: Dim, |
| |
92 K: Dim, |
| |
93 E: Scalar + Zero + One, |
| |
94 DefaultAllocator: Allocator<M, K>, |
| |
95 { |
| |
96 fn eval_decompose<'b, R>(self, f: impl FnOnce(OMatrix<E, M, K>) -> R) -> R |
| |
97 where |
| |
98 Self: 'b, |
| |
99 { |
| |
100 f(self.into_owned()) |
| |
101 } |
| |
102 |
| |
103 fn eval_ref_decompose<'b, R>( |
| |
104 &'b self, |
| |
105 f: impl FnOnce(&'b MatrixView<'b, E, M, K, Dyn, Dyn>) -> R, |
| |
106 ) -> R |
| |
107 where |
| |
108 Self: 'b, |
| |
109 Matrix<E, M, K, SM>: 'b, |
| |
110 { |
| |
111 f(&self.as_view::<M, K, Dyn, Dyn>()) |
| |
112 } |
| |
113 |
| |
114 #[inline] |
| |
115 fn own(self) -> OMatrix<E, M, K> { |
| |
116 self.into_owned() |
| |
117 } |
| 58 } |
118 } |
| 59 |
119 |
| 60 impl<SM, SV, N, M, K, E> Mapping<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM> |
120 impl<SM, SV, N, M, K, E> Mapping<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM> |
| 61 where |
121 where |
| 62 SM: Storage<E, N, M>, |
122 SM: Storage<E, N, M>, |