Fri, 28 Nov 2025 13:28:17 -0500
Bump nalgebra version to 0.34.0
| 5 | 1 | /*! |
| 2 | Integration with nalgebra. | |
| 3 | ||
|
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
4 | This module mainly implements [`Euclidean`], [`Norm`], [`Linear`], etc. for [`nalgebra`] |
| 5 | 5 | matrices and vectors. |
| 6 | It also provides [`ToNalgebraRealField`] as a vomit-inducingly ugly workaround to nalgebra | |
| 7 | force-feeding its own versions of the same basic mathematical methods on `f32` and `f64` as | |
| 8 | [`num_traits`] does. | |
| 9 | */ | |
| 0 | 10 | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
11 | use crate::euclidean::*; |
| 162 | 12 | use crate::instance::{Decomposition, Instance, MyCow, Ownable, Space}; |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
13 | use crate::linops::*; |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
14 | use crate::norms::*; |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
15 | use crate::types::Float; |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
16 | use nalgebra::base::allocator::Allocator; |
| 158 | 17 | use nalgebra::base::constraint::{DimEq, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
18 | use nalgebra::base::dimension::*; |
| 0 | 19 | use nalgebra::{ |
| 176 | 20 | ArrayStorage, ClosedAddAssign, ClosedMulAssign, DefaultAllocator, Dim, LpNorm, Matrix, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
21 | MatrixView, OMatrix, OVector, RawStorage, RealField, SimdComplexField, Storage, StorageMut, |
|
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
22 | UniformNorm, VecStorage, Vector, ViewStorage, ViewStorageMut, U1, |
| 0 | 23 | }; |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
24 | use num_traits::identities::Zero; |
| 0 | 25 | use std::ops::Mul; |
| 26 | ||
| 150 | 27 | impl<S, M, N, E> Ownable for Matrix<E, M, N, S> |
| 28 | where | |
| 29 | S: Storage<E, M, N>, | |
| 30 | M: Dim, | |
| 31 | N: Dim, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
32 | E: Float, |
| 150 | 33 | DefaultAllocator: Allocator<M, N>, |
| 34 | { | |
| 35 | type OwnedVariant = OMatrix<E, M, N>; | |
| 36 | ||
| 37 | #[inline] | |
| 38 | fn into_owned(self) -> Self::OwnedVariant { | |
| 39 | Matrix::into_owned(self) | |
| 40 | } | |
| 41 | ||
| 42 | /// Returns an owned instance of a reference. | |
| 43 | fn clone_owned(&self) -> Self::OwnedVariant { | |
| 44 | Matrix::clone_owned(self) | |
| 45 | } | |
| 162 | 46 | |
| 47 | fn cow_owned<'b>(self) -> MyCow<'b, Self::OwnedVariant> | |
| 48 | where | |
| 49 | Self: 'b, | |
| 50 | { | |
| 166 | 51 | MyCow::Owned(self.into_owned()) |
| 52 | } | |
| 53 | ||
| 54 | fn ref_cow_owned<'b>(&'b self) -> MyCow<'b, Self::OwnedVariant> | |
| 55 | where | |
| 56 | Self: 'b, | |
| 57 | { | |
| 58 | MyCow::Owned(self.clone_owned()) | |
| 162 | 59 | } |
| 150 | 60 | } |
| 61 | ||
| 159 | 62 | trait StridesOk<E, N, M = U1, S = <DefaultAllocator as Allocator<N, M>>::Buffer<E>>: |
| 176 | 63 | DimEq<Dyn, S::RStride> + DimEq<Dyn, S::CStride> |
| 159 | 64 | where |
| 65 | S: RawStorage<E, N, M>, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
66 | E: Float, |
| 159 | 67 | N: Dim, |
| 68 | M: Dim, | |
| 69 | DefaultAllocator: Allocator<N, M>, | |
| 70 | { | |
| 71 | } | |
| 72 | ||
| 176 | 73 | impl<E, M> StridesOk<E, Dyn, M, VecStorage<E, Dyn, M>> for ShapeConstraint |
| 159 | 74 | where |
| 176 | 75 | M: Dim, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
76 | E: Float, |
| 176 | 77 | DefaultAllocator: Allocator<Dyn, M>, |
| 78 | { | |
| 79 | } | |
| 80 | ||
| 81 | impl<E, const N: usize, const M: usize> StridesOk<E, Const<N>, Const<M>, ArrayStorage<E, N, M>> | |
| 82 | for ShapeConstraint | |
| 83 | where | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
84 | E: Float, |
| 159 | 85 | { |
| 86 | } | |
| 87 | ||
| 176 | 88 | macro_rules! strides_ok { |
| 89 | ($R:ty, $C:ty where $($qual:tt)*) => { | |
| 90 | impl<'a, E, N, M, $($qual)*> StridesOk<E, N, M, ViewStorage<'a, E, N, M, $R, $C>> for ShapeConstraint | |
| 91 | where | |
| 92 | N: Dim, | |
| 93 | M: Dim, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
94 | E: Float, |
|
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
95 | DefaultAllocator: Allocator<N, M>, |
| 176 | 96 | { |
| 97 | } | |
| 98 | impl<'a, E, N, M, $($qual)*> StridesOk<E, N, M, ViewStorageMut<'a, E, N, M, $R, $C>> for ShapeConstraint | |
| 99 | where | |
| 100 | N: Dim, | |
| 101 | M: Dim, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
102 | E: Float, |
|
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
103 | DefaultAllocator: Allocator<N, M>, |
| 176 | 104 | { |
| 105 | } | |
| 106 | }; | |
| 107 | } | |
| 108 | ||
| 109 | strides_ok!(Dyn, Dyn where ); | |
| 110 | strides_ok!(Dyn, Const<C> where const C : usize); | |
| 111 | strides_ok!(Const<R>, Dyn where const R : usize); | |
| 112 | strides_ok!(Const<R>, Const<C> where const R : usize, const C : usize); | |
| 113 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
114 | impl<SM, N, M, E> Space for Matrix<E, N, M, SM> |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
56
diff
changeset
|
115 | where |
| 150 | 116 | SM: Storage<E, N, M>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
117 | N: Dim, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
118 | M: Dim, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
119 | E: Float, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
120 | DefaultAllocator: Allocator<N, M>, |
| 176 | 121 | ShapeConstraint: StridesOk<E, N, M>, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
56
diff
changeset
|
122 | { |
| 164 | 123 | type Principal = OMatrix<E, N, M>; |
| 156 | 124 | type Decomp = MatrixDecomposition; |
| 125 | } | |
| 126 | ||
| 127 | #[derive(Copy, Clone, Debug)] | |
| 128 | pub struct MatrixDecomposition; | |
| 129 | ||
|
160
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
130 | impl<E, M, K, S> Decomposition<Matrix<E, M, K, S>> for MatrixDecomposition |
| 156 | 131 | where |
| 158 | 132 | S: Storage<E, M, K>, |
| 156 | 133 | M: Dim, |
| 134 | K: Dim, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
135 | E: Float, |
| 156 | 136 | DefaultAllocator: Allocator<M, K>, |
| 176 | 137 | ShapeConstraint: StridesOk<E, M, K>, |
| 156 | 138 | { |
| 139 | type Decomposition<'b> | |
| 172 | 140 | = MyCow<'b, OMatrix<E, M, K>> |
| 156 | 141 | where |
| 142 | Matrix<E, M, K, S>: 'b; | |
| 143 | type Reference<'b> | |
| 158 | 144 | = MatrixView<'b, E, M, K, Dyn, Dyn> |
| 156 | 145 | where |
| 146 | Matrix<E, M, K, S>: 'b; | |
| 147 | ||
| 148 | #[inline] | |
| 157 | 149 | fn lift<'b>(r: Self::Reference<'b>) -> Self::Decomposition<'b> |
| 150 | where | |
| 151 | S: 'b, | |
| 152 | { | |
| 172 | 153 | MyCow::Owned(r.into_owned()) |
| 156 | 154 | } |
| 155 | } | |
| 156 | ||
| 159 | 157 | impl<S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> for Matrix<E, M, K, S2> |
| 158 | where | |
|
160
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
159 | S1: Storage<E, M, K>, |
|
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
160 | S2: Storage<E, M, K>, |
| 159 | 161 | M: Dim, |
| 162 | K: Dim, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
163 | E: Float, |
| 159 | 164 | DefaultAllocator: Allocator<M, K>, |
| 176 | 165 | ShapeConstraint: StridesOk<E, M, K, S2> + StridesOk<E, M, K>, |
| 159 | 166 | { |
| 168 | 167 | #[inline] |
| 171 | 168 | fn eval_ref<'b, R>( |
| 159 | 169 | &'b self, |
| 170 | f: impl FnOnce(<MatrixDecomposition as Decomposition<Matrix<E, M, K, S1>>>::Reference<'b>) -> R, | |
| 171 | ) -> R | |
| 172 | where | |
| 173 | Self: 'b, | |
| 174 | Matrix<E, M, K, S1>: 'b, | |
| 175 | { | |
| 176 | f(self.as_view::<M, K, Dyn, Dyn>()) | |
| 177 | } | |
| 156 | 178 | |
| 159 | 179 | #[inline] |
| 180 | fn own(self) -> OMatrix<E, M, K> { | |
| 181 | self.into_owned() | |
| 182 | } | |
| 168 | 183 | |
| 184 | #[inline] | |
| 185 | fn cow<'b>(self) -> MyCow<'b, OMatrix<E, M, K>> | |
| 186 | where | |
| 187 | Self: 'b, | |
| 188 | { | |
| 189 | self.cow_owned() | |
| 190 | } | |
| 171 | 191 | |
| 192 | #[inline] | |
| 172 | 193 | fn decompose<'b>(self) -> MyCow<'b, OMatrix<E, M, K>> |
| 171 | 194 | where |
| 195 | Self: 'b, | |
| 196 | { | |
| 172 | 197 | self.cow_owned() |
| 171 | 198 | } |
|
13
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
199 | } |
|
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
200 | |
| 159 | 201 | impl<'a, S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> |
| 202 | for &'a Matrix<E, M, K, S2> | |
| 203 | where | |
|
160
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
204 | S1: Storage<E, M, K>, |
|
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
205 | S2: Storage<E, M, K>, |
| 159 | 206 | M: Dim, |
| 207 | K: Dim, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
208 | E: Float, |
| 159 | 209 | DefaultAllocator: Allocator<M, K>, |
| 176 | 210 | ShapeConstraint: StridesOk<E, M, K, S2> + StridesOk<E, M, K>, |
| 159 | 211 | { |
| 171 | 212 | fn eval_ref<'b, R>( |
| 159 | 213 | &'b self, |
| 214 | f: impl FnOnce(<MatrixDecomposition as Decomposition<Matrix<E, M, K, S1>>>::Reference<'b>) -> R, | |
| 215 | ) -> R | |
| 216 | where | |
| 217 | Self: 'b, | |
| 218 | Matrix<E, M, K, S1>: 'b, | |
| 219 | { | |
| 220 | f((*self).as_view::<M, K, Dyn, Dyn>()) | |
| 221 | } | |
| 222 | ||
| 223 | #[inline] | |
| 224 | fn own(self) -> OMatrix<E, M, K> { | |
| 225 | self.into_owned() | |
| 226 | } | |
| 168 | 227 | |
| 228 | #[inline] | |
| 229 | fn cow<'b>(self) -> MyCow<'b, OMatrix<E, M, K>> | |
| 230 | where | |
| 231 | Self: 'b, | |
| 232 | { | |
| 233 | self.cow_owned() | |
| 234 | } | |
| 171 | 235 | |
| 236 | #[inline] | |
| 172 | 237 | fn decompose<'b>(self) -> MyCow<'b, OMatrix<E, M, K>> |
| 238 | where | |
| 239 | Self: 'b, | |
| 240 | { | |
| 241 | self.cow_owned() | |
| 242 | } | |
| 243 | } | |
| 244 | ||
| 178 | 245 | impl<'a, S1, M, SM, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> |
| 246 | for MyCow<'a, Matrix<E, M, K, SM>> | |
| 172 | 247 | where |
| 248 | S1: Storage<E, M, K>, | |
| 178 | 249 | SM: Storage<E, M, K>, |
| 172 | 250 | M: Dim, |
| 251 | K: Dim, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
252 | E: Float, |
| 172 | 253 | DefaultAllocator: Allocator<M, K>, |
| 178 | 254 | ShapeConstraint: StridesOk<E, M, K, SM> + StridesOk<E, M, K>, |
| 172 | 255 | { |
| 256 | #[inline] | |
| 257 | fn eval_ref<'b, R>( | |
| 258 | &'b self, | |
| 259 | f: impl FnOnce(<MatrixDecomposition as Decomposition<Matrix<E, M, K, S1>>>::Reference<'b>) -> R, | |
| 260 | ) -> R | |
| 261 | where | |
| 262 | Self: 'b, | |
| 263 | Matrix<E, M, K, S1>: 'b, | |
| 264 | { | |
| 265 | f(self.as_view::<M, K, Dyn, Dyn>()) | |
| 266 | } | |
| 267 | ||
| 268 | #[inline] | |
| 269 | fn own(self) -> OMatrix<E, M, K> { | |
| 171 | 270 | self.into_owned() |
| 271 | } | |
| 172 | 272 | |
| 273 | #[inline] | |
| 274 | fn cow<'b>(self) -> MyCow<'b, OMatrix<E, M, K>> | |
| 275 | where | |
| 276 | Self: 'b, | |
| 277 | { | |
| 178 | 278 | self.cow_owned() |
| 172 | 279 | } |
| 280 | ||
| 281 | #[inline] | |
| 282 | fn decompose<'b>(self) -> MyCow<'b, OMatrix<E, M, K>> | |
| 283 | where | |
| 284 | Self: 'b, | |
| 285 | { | |
| 178 | 286 | self.cow_owned() |
| 172 | 287 | } |
| 159 | 288 | } |
| 158 | 289 | |
|
169
114ecdf63ce5
Can only do nalgebra matrix ops for OMatrix (but ok through Instance) to avoid having to specify types
Tuomo Valkonen <tuomov@iki.fi>
parents:
168
diff
changeset
|
290 | impl<SM, N, M, K, E> Mapping<OMatrix<E, M, K>> for Matrix<E, N, M, SM> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
291 | where |
|
160
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
292 | SM: Storage<E, N, M>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
293 | N: Dim, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
294 | M: Dim, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
295 | K: Dim, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
296 | E: Float, |
|
180
ec5a811eab09
Less DefaultAllocate trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
178
diff
changeset
|
297 | DefaultAllocator: Allocator<M, K> + Allocator<N, K>, |
| 176 | 298 | ShapeConstraint: StridesOk<E, M, K> + StridesOk<E, N, K>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
299 | { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
300 | type Codomain = OMatrix<E, N, K>; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
56
diff
changeset
|
301 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
56
diff
changeset
|
302 | #[inline] |
|
169
114ecdf63ce5
Can only do nalgebra matrix ops for OMatrix (but ok through Instance) to avoid having to specify types
Tuomo Valkonen <tuomov@iki.fi>
parents:
168
diff
changeset
|
303 | fn apply<I: Instance<OMatrix<E, M, K>>>(&self, x: I) -> Self::Codomain { |
| 172 | 304 | x.eval_ref(|refr| self.mul(refr)) |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
56
diff
changeset
|
305 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
56
diff
changeset
|
306 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
56
diff
changeset
|
307 | |
|
169
114ecdf63ce5
Can only do nalgebra matrix ops for OMatrix (but ok through Instance) to avoid having to specify types
Tuomo Valkonen <tuomov@iki.fi>
parents:
168
diff
changeset
|
308 | impl<'a, SM, N, M, K, E> Linear<OMatrix<E, M, K>> for Matrix<E, N, M, SM> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
309 | where |
|
160
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
310 | SM: Storage<E, N, M>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
311 | N: Dim, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
312 | M: Dim, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
313 | K: Dim, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
314 | E: Float + ClosedMulAssign + ClosedAddAssign, |
|
180
ec5a811eab09
Less DefaultAllocate trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
178
diff
changeset
|
315 | DefaultAllocator: Allocator<N, K> + Allocator<M, K>, |
| 176 | 316 | ShapeConstraint: StridesOk<E, M, K> + StridesOk<E, N, K>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
317 | { |
| 0 | 318 | } |
| 319 | ||
|
169
114ecdf63ce5
Can only do nalgebra matrix ops for OMatrix (but ok through Instance) to avoid having to specify types
Tuomo Valkonen <tuomov@iki.fi>
parents:
168
diff
changeset
|
320 | impl<SM, SV2, N, M, K, E> GEMV<E, OMatrix<E, M, K>, Matrix<E, N, K, SV2>> for Matrix<E, N, M, SM> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
321 | where |
|
160
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
322 | SM: Storage<E, N, M>, |
|
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
323 | SV2: StorageMut<E, N, K>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
324 | N: Dim, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
325 | M: Dim, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
326 | K: Dim, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
327 | E: Float, |
|
180
ec5a811eab09
Less DefaultAllocate trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
178
diff
changeset
|
328 | DefaultAllocator: Allocator<N, K> + Allocator<M, K>, |
| 176 | 329 | ShapeConstraint: StridesOk<E, M, K> + StridesOk<E, N, K>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
330 | { |
| 0 | 331 | #[inline] |
|
169
114ecdf63ce5
Can only do nalgebra matrix ops for OMatrix (but ok through Instance) to avoid having to specify types
Tuomo Valkonen <tuomov@iki.fi>
parents:
168
diff
changeset
|
332 | fn gemv<I: Instance<OMatrix<E, M, K>>>( |
|
114ecdf63ce5
Can only do nalgebra matrix ops for OMatrix (but ok through Instance) to avoid having to specify types
Tuomo Valkonen <tuomov@iki.fi>
parents:
168
diff
changeset
|
333 | &self, y: &mut Matrix<E, N, K, SV2>, α: E, x: I, β: E |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
56
diff
changeset
|
334 | ) { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
56
diff
changeset
|
335 | x.eval(|x̃| Matrix::gemm(y, α, self, x̃, β)) |
| 0 | 336 | } |
| 337 | ||
| 338 | #[inline] | |
|
169
114ecdf63ce5
Can only do nalgebra matrix ops for OMatrix (but ok through Instance) to avoid having to specify types
Tuomo Valkonen <tuomov@iki.fi>
parents:
168
diff
changeset
|
339 | fn apply_mut<'a, I: Instance<OMatrix<E, M, K>>>(&self, y: &mut Matrix<E, N, K, SV2>, x: I) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
56
diff
changeset
|
340 | x.eval(|x̃| self.mul_to(x̃, y)) |
| 0 | 341 | } |
| 342 | } | |
| 343 | ||
| 150 | 344 | impl<S, M, N, E> VectorSpace for Matrix<E, M, N, S> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
345 | where |
|
160
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
346 | S: Storage<E, M, N>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
347 | M: Dim, |
|
148
26ef556870fd
AXPY for nalgebra matrices, not just vectors
Tuomo Valkonen <tuomov@iki.fi>
parents:
145
diff
changeset
|
348 | N: Dim, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
349 | E: Float, |
|
148
26ef556870fd
AXPY for nalgebra matrices, not just vectors
Tuomo Valkonen <tuomov@iki.fi>
parents:
145
diff
changeset
|
350 | DefaultAllocator: Allocator<M, N>, |
| 176 | 351 | ShapeConstraint: StridesOk<E, M, N>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
352 | { |
|
129
d2994e34a5f5
Simplify ZeroOp to SimpleZeroOp, only from X to X. Add Prox for ZeroIndicator. Move F parameter to AXPY::Field.
Tuomo Valkonen <tuomov@iki.fi>
parents:
124
diff
changeset
|
353 | type Field = E; |
| 164 | 354 | type PrincipalV = OMatrix<E, M, N>; |
| 0 | 355 | |
| 356 | #[inline] | |
| 164 | 357 | fn similar_origin(&self) -> Self::PrincipalV { |
| 150 | 358 | let (n, m) = self.shape_generic(); |
| 359 | OMatrix::zeros_generic(n, m) | |
| 360 | } | |
| 361 | } | |
| 362 | ||
|
177
b071a1b484f8
AXPY implementation reductions
Tuomo Valkonen <tuomov@iki.fi>
parents:
176
diff
changeset
|
363 | // This can only be implemented for the “principal” OMatrix as parameter, as otherwise |
|
b071a1b484f8
AXPY implementation reductions
Tuomo Valkonen <tuomov@iki.fi>
parents:
176
diff
changeset
|
364 | // we run into problems of multiple implementations when calling the methods. |
|
b071a1b484f8
AXPY implementation reductions
Tuomo Valkonen <tuomov@iki.fi>
parents:
176
diff
changeset
|
365 | impl<M, N, E, S> AXPY<OMatrix<E, M, N>> for Matrix<E, M, N, S> |
| 150 | 366 | where |
|
177
b071a1b484f8
AXPY implementation reductions
Tuomo Valkonen <tuomov@iki.fi>
parents:
176
diff
changeset
|
367 | S: StorageMut<E, M, N>, |
| 150 | 368 | M: Dim, |
| 369 | N: Dim, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
370 | E: Float, |
| 150 | 371 | DefaultAllocator: Allocator<M, N>, |
| 176 | 372 | ShapeConstraint: StridesOk<E, M, N>, |
| 150 | 373 | { |
| 374 | #[inline] | |
|
177
b071a1b484f8
AXPY implementation reductions
Tuomo Valkonen <tuomov@iki.fi>
parents:
176
diff
changeset
|
375 | fn axpy<I: Instance<OMatrix<E, M, N>>>(&mut self, α: E, x: I, β: E) { |
|
148
26ef556870fd
AXPY for nalgebra matrices, not just vectors
Tuomo Valkonen <tuomov@iki.fi>
parents:
145
diff
changeset
|
376 | x.eval(|x̃| { |
|
26ef556870fd
AXPY for nalgebra matrices, not just vectors
Tuomo Valkonen <tuomov@iki.fi>
parents:
145
diff
changeset
|
377 | assert_eq!(self.ncols(), x̃.ncols()); |
|
26ef556870fd
AXPY for nalgebra matrices, not just vectors
Tuomo Valkonen <tuomov@iki.fi>
parents:
145
diff
changeset
|
378 | // nalgebra does not implement axpy for matrices, and flattenining |
|
26ef556870fd
AXPY for nalgebra matrices, not just vectors
Tuomo Valkonen <tuomov@iki.fi>
parents:
145
diff
changeset
|
379 | // also seems difficult, so loop over columns. |
|
26ef556870fd
AXPY for nalgebra matrices, not just vectors
Tuomo Valkonen <tuomov@iki.fi>
parents:
145
diff
changeset
|
380 | for (mut y, ỹ) in self.column_iter_mut().zip(x̃.column_iter()) { |
|
26ef556870fd
AXPY for nalgebra matrices, not just vectors
Tuomo Valkonen <tuomov@iki.fi>
parents:
145
diff
changeset
|
381 | Vector::axpy(&mut y, α, &ỹ, β) |
|
26ef556870fd
AXPY for nalgebra matrices, not just vectors
Tuomo Valkonen <tuomov@iki.fi>
parents:
145
diff
changeset
|
382 | } |
|
26ef556870fd
AXPY for nalgebra matrices, not just vectors
Tuomo Valkonen <tuomov@iki.fi>
parents:
145
diff
changeset
|
383 | }) |
| 0 | 384 | } |
| 385 | ||
| 386 | #[inline] | |
|
177
b071a1b484f8
AXPY implementation reductions
Tuomo Valkonen <tuomov@iki.fi>
parents:
176
diff
changeset
|
387 | fn copy_from<I: Instance<OMatrix<E, M, N>>>(&mut self, y: I) { |
| 171 | 388 | y.eval_ref(|ỹ| Matrix::copy_from(self, &ỹ)) |
| 0 | 389 | } |
|
62
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
390 | |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
391 | #[inline] |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
392 | fn set_zero(&mut self) { |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
393 | self.iter_mut().for_each(|e| *e = E::ZERO); |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
394 | } |
| 0 | 395 | } |
| 396 | ||
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
397 | /* Implemented automatically as Euclidean. |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
398 | impl<SM,M,E> Projection<E, L2> for Vector<E,M,SM> |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
399 | where SM: StorageMut<E,M> + Clone, |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
400 | M : Dim, E : Scalar + Zero + One + Float + RealField, |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
401 | DefaultAllocator : Allocator<M> { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
402 | #[inline] |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
403 | fn proj_ball_mut(&mut self, ρ : E, _ : L2) { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
404 | let n = self.norm(L2); |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
405 | if n > ρ { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
406 | self.iter_mut().for_each(|v| *v *= ρ/n) |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
407 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
408 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
409 | }*/ |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
410 | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
411 | impl<SM, M, E> Projection<E, Linfinity> for Vector<E, M, SM> |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
412 | where |
| 174 | 413 | SM: StorageMut<E, M>, |
| 150 | 414 | M: Dim, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
415 | E: Float + RealField, |
| 150 | 416 | DefaultAllocator: Allocator<M>, |
| 176 | 417 | ShapeConstraint: StridesOk<E, M>, |
| 150 | 418 | { |
| 419 | #[inline] | |
| 164 | 420 | fn proj_ball(self, ρ: E, exp: Linfinity) -> <Self as Space>::Principal { |
| 150 | 421 | let mut owned = self.into_owned(); |
| 422 | owned.proj_ball_mut(ρ, exp); | |
| 423 | owned | |
| 424 | } | |
| 425 | } | |
| 426 | ||
| 427 | impl<SM, M, E> ProjectionMut<E, Linfinity> for Vector<E, M, SM> | |
| 428 | where | |
| 174 | 429 | SM: StorageMut<E, M>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
430 | M: Dim, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
431 | E: Float + RealField, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
432 | DefaultAllocator: Allocator<M>, |
| 176 | 433 | ShapeConstraint: StridesOk<E, M>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
434 | { |
| 0 | 435 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
436 | fn proj_ball_mut(&mut self, ρ: E, _: Linfinity) { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
437 | self.iter_mut() |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
438 | .for_each(|v| *v = num_traits::clamp(*v, -ρ, ρ)) |
| 0 | 439 | } |
| 440 | } | |
| 441 | ||
|
169
114ecdf63ce5
Can only do nalgebra matrix ops for OMatrix (but ok through Instance) to avoid having to specify types
Tuomo Valkonen <tuomov@iki.fi>
parents:
168
diff
changeset
|
442 | impl<'own, SM, N, M, K, E> Adjointable<OMatrix<E, M, K>, OMatrix<E, N, K>> for Matrix<E, N, M, SM> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
443 | where |
|
160
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
444 | SM: Storage<E, N, M>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
445 | N: Dim, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
446 | M: Dim, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
447 | K: Dim, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
448 | E: Float + RealField, |
|
180
ec5a811eab09
Less DefaultAllocate trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
178
diff
changeset
|
449 | DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<M, N>, |
| 176 | 450 | ShapeConstraint: StridesOk<E, N, K> + StridesOk<E, M, K>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
451 | { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
452 | type AdjointCodomain = OMatrix<E, M, K>; |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
453 | type Adjoint<'a> |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
454 | = OMatrix<E, M, N> |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
455 | where |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
456 | SM: 'a; |
| 0 | 457 | |
| 458 | #[inline] | |
| 459 | fn adjoint(&self) -> Self::Adjoint<'_> { | |
| 460 | Matrix::adjoint(self) | |
| 461 | } | |
| 462 | } | |
| 463 | ||
|
184
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
464 | impl<'own, SM, N, M, K, E> SimplyAdjointable<OMatrix<E, M, K>, OMatrix<E, N, K>> |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
465 | for Matrix<E, N, M, SM> |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
466 | where |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
467 | SM: Storage<E, N, M>, |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
468 | N: Dim, |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
469 | M: Dim, |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
470 | K: Dim, |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
471 | E: Float + RealField, |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
472 | DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<M, N>, |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
473 | ShapeConstraint: StridesOk<E, N, K> + StridesOk<E, M, K>, |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
474 | { |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
475 | type AdjointCodomain = OMatrix<E, M, K>; |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
476 | type SimpleAdjoint = OMatrix<E, M, N>; |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
477 | |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
478 | #[inline] |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
479 | fn adjoint(&self) -> Self::SimpleAdjoint { |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
480 | Matrix::adjoint(self) |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
481 | } |
|
b7b60b3b3eff
SimplyAdjointable to avoid type system limitations
Tuomo Valkonen <tuomov@iki.fi>
parents:
181
diff
changeset
|
482 | } |
| 0 | 483 | /// This function is [`nalgebra::EuclideanNorm::metric_distance`] without the `sqrt`. |
| 484 | #[inline] | |
| 485 | fn metric_distance_squared<T, R1, C1, S1, R2, C2, S2>( | |
| 486 | /*ed: &EuclideanNorm,*/ | |
| 487 | m1: &Matrix<T, R1, C1, S1>, | |
| 488 | m2: &Matrix<T, R2, C2, S2>, | |
| 489 | ) -> T::SimdRealField | |
| 490 | where | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
491 | T: SimdComplexField, |
| 0 | 492 | R1: Dim, |
| 493 | C1: Dim, | |
| 494 | S1: Storage<T, R1, C1>, | |
| 495 | R2: Dim, | |
| 496 | C2: Dim, | |
| 497 | S2: Storage<T, R2, C2>, | |
| 498 | ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>, | |
| 499 | { | |
| 500 | m1.zip_fold(m2, T::SimdRealField::zero(), |acc, a, b| { | |
| 501 | let diff = a - b; | |
| 502 | acc + diff.simd_modulus_squared() | |
| 503 | }) | |
| 504 | } | |
| 505 | ||
| 174 | 506 | impl<E, M, N, S> Euclidean<E> for Matrix<E, M, N, S> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
507 | where |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
508 | M: Dim, |
| 174 | 509 | N: Dim, |
| 510 | S: Storage<E, M, N>, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
511 | E: Float + RealField, |
| 174 | 512 | DefaultAllocator: Allocator<M, N>, |
| 176 | 513 | ShapeConstraint: StridesOk<E, M, N>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
514 | { |
| 174 | 515 | type PrincipalE = OMatrix<E, M, N>; |
| 151 | 516 | |
|
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
517 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
518 | fn dot<I: Instance<Self>>(&self, other: I) -> E { |
| 174 | 519 | other.eval_ref(|ref r| Matrix::<E, M, N, S>::dot(self, r)) |
|
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
520 | } |
|
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
521 | |
| 0 | 522 | #[inline] |
| 523 | fn norm2_squared(&self) -> E { | |
| 174 | 524 | Matrix::<E, M, N, S>::norm_squared(self) |
| 0 | 525 | } |
| 526 | ||
| 527 | #[inline] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
528 | fn dist2_squared<I: Instance<Self>>(&self, other: I) -> E { |
| 171 | 529 | other.eval_ref(|ref r| metric_distance_squared(self, r)) |
| 0 | 530 | } |
| 531 | } | |
| 532 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
533 | impl<E, M, S> StaticEuclidean<E> for Vector<E, M, S> |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
534 | where |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
535 | M: DimName, |
|
160
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
536 | S: Storage<E, M>, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
537 | E: Float + RealField, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
538 | DefaultAllocator: Allocator<M>, |
| 176 | 539 | ShapeConstraint: StridesOk<E, M>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
540 | { |
| 0 | 541 | #[inline] |
| 542 | fn origin() -> OVector<E, M> { | |
| 543 | OVector::zeros() | |
| 544 | } | |
| 545 | } | |
| 546 | ||
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
547 | /// The default norm for `Vector` is [`L2`]. |
| 174 | 548 | impl<E, M, N, S> Normed<E> for Matrix<E, M, N, S> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
549 | where |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
550 | M: Dim, |
| 174 | 551 | N: Dim, |
| 552 | S: Storage<E, M, N>, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
553 | E: Float + RealField, |
| 174 | 554 | DefaultAllocator: Allocator<M, N>, |
| 176 | 555 | ShapeConstraint: StridesOk<E, M, N>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
556 | { |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
557 | type NormExp = L2; |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
558 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
559 | #[inline] |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
560 | fn norm_exponent(&self) -> Self::NormExp { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
561 | L2 |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
562 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
563 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
564 | #[inline] |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
565 | fn is_zero(&self) -> bool { |
| 174 | 566 | Matrix::<E, M, N, S>::norm_squared(self) == E::ZERO |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
567 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
568 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
569 | |
| 174 | 570 | impl<E, M, N, S> HasDual<E> for Matrix<E, M, N, S> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
571 | where |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
572 | M: Dim, |
| 174 | 573 | N: Dim, |
| 574 | S: Storage<E, M, N>, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
575 | E: Float + RealField, |
| 174 | 576 | DefaultAllocator: Allocator<M, N>, |
| 176 | 577 | ShapeConstraint: StridesOk<E, M, N>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
578 | { |
| 174 | 579 | type DualSpace = OMatrix<E, M, N>; |
| 138 | 580 | |
| 174 | 581 | fn dual_origin(&self) -> OMatrix<E, M, N> { |
| 582 | let (m, n) = self.shape_generic(); | |
| 583 | OMatrix::zeros_generic(m, n) | |
| 138 | 584 | } |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
585 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
586 | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
587 | impl<E, M, S> Norm<L1, E> for Vector<E, M, S> |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
588 | where |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
589 | M: Dim, |
|
160
e7920e205785
Viewable hack not needed now
Tuomo Valkonen <tuomov@iki.fi>
parents:
159
diff
changeset
|
590 | S: Storage<E, M>, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
591 | E: Float + RealField, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
592 | { |
| 0 | 593 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
594 | fn norm(&self, _: L1) -> E { |
| 70 | 595 | nalgebra::Norm::norm(&LpNorm(1), self) |
| 0 | 596 | } |
| 597 | } | |
| 598 | ||
|
145
0b9aecd7bb76
Dist argument order changed to reflect other changes
Tuomo Valkonen <tuomov@iki.fi>
parents:
138
diff
changeset
|
599 | impl<E, M, S> Dist<L1, E> for Vector<E, M, S> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
600 | where |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
601 | M: Dim, |
| 174 | 602 | S: Storage<E, M>, |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
603 | E: Float + RealField, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
604 | DefaultAllocator: Allocator<M>, |
| 176 | 605 | ShapeConstraint: StridesOk<E, M>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
606 | { |
| 0 | 607 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
608 | fn dist<I: Instance<Self>>(&self, other: I, _: L1) -> E { |
| 171 | 609 | other.eval_ref(|ref r| nalgebra::Norm::metric_distance(&LpNorm(1), self, r)) |
| 0 | 610 | } |
| 611 | } | |
| 612 | ||
| 174 | 613 | impl<E, M, N, S> Norm<L2, E> for Matrix<E, M, N, S> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
614 | where |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
615 | M: Dim, |
| 174 | 616 | N: Dim, |
| 617 | S: Storage<E, M, N>, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
618 | E: Float + RealField, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
619 | { |
| 0 | 620 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
621 | fn norm(&self, _: L2) -> E { |
| 70 | 622 | nalgebra::Norm::norm(&LpNorm(2), self) |
| 0 | 623 | } |
| 624 | } | |
| 625 | ||
| 174 | 626 | impl<E, M, N, S> Dist<L2, E> for Matrix<E, M, N, S> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
627 | where |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
628 | M: Dim, |
| 174 | 629 | N: Dim, |
| 630 | S: Storage<E, M, N>, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
631 | E: Float + RealField, |
| 174 | 632 | DefaultAllocator: Allocator<M, N>, |
| 176 | 633 | ShapeConstraint: StridesOk<E, M, N>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
634 | { |
| 0 | 635 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
636 | fn dist<I: Instance<Self>>(&self, other: I, _: L2) -> E { |
| 171 | 637 | other.eval_ref(|ref r| nalgebra::Norm::metric_distance(&LpNorm(2), self, r)) |
| 0 | 638 | } |
| 639 | } | |
| 640 | ||
| 174 | 641 | impl<E, M, N, S> Norm<Linfinity, E> for Matrix<E, M, N, S> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
642 | where |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
643 | M: Dim, |
| 174 | 644 | N: Dim, |
| 645 | S: Storage<E, M, N>, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
646 | E: Float + RealField, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
647 | { |
| 0 | 648 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
649 | fn norm(&self, _: Linfinity) -> E { |
| 70 | 650 | nalgebra::Norm::norm(&UniformNorm, self) |
| 0 | 651 | } |
| 652 | } | |
| 653 | ||
| 174 | 654 | impl<E, M, N, S> Dist<Linfinity, E> for Matrix<E, M, N, S> |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
655 | where |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
656 | M: Dim, |
| 174 | 657 | N: Dim, |
| 658 | S: Storage<E, M, N>, | |
|
181
f159287bc191
Simplify nalgebra trait bounds further
Tuomo Valkonen <tuomov@iki.fi>
parents:
180
diff
changeset
|
659 | E: Float + RealField, |
| 174 | 660 | DefaultAllocator: Allocator<M, N>, |
| 176 | 661 | ShapeConstraint: StridesOk<E, M, N>, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
662 | { |
| 0 | 663 | #[inline] |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
664 | fn dist<I: Instance<Self>>(&self, other: I, _: Linfinity) -> E { |
| 171 | 665 | other.eval_ref(|ref r| nalgebra::Norm::metric_distance(&UniformNorm, self, r)) |
| 0 | 666 | } |
| 667 | } | |
| 668 | ||
| 5 | 669 | /// Helper trait to hide the symbols of [`nalgebra::RealField`]. |
| 670 | /// | |
| 671 | /// By assuming `ToNalgebraRealField` intead of `nalgebra::RealField` as a trait bound, | |
| 672 | /// functions can piggyback `nalgebra::RealField` without exponsing themselves to it. | |
| 673 | /// Thus methods from [`num_traits`] can be used directly without similarly named methods | |
| 674 | /// from [`nalgebra`] conflicting with them. Only when absolutely necessary to work with | |
| 675 | /// nalgebra, one can convert to the nalgebra view of the same type using the methods of | |
| 676 | /// this trait. | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
677 | pub trait ToNalgebraRealField: Float { |
| 5 | 678 | /// The nalgebra type corresponding to this type. Usually same as `Self`. |
| 679 | /// | |
| 680 | /// This type only carries `nalgebra` traits. | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
681 | type NalgebraType: RealField; |
| 5 | 682 | /// The “mixed” type corresponding to this type. Usually same as `Self`. |
| 683 | /// | |
| 684 | /// This type carries both `num_traits` and `nalgebra` traits. | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
685 | type MixedType: RealField + Float; |
| 0 | 686 | |
| 5 | 687 | /// Convert to the nalgebra view of `self`. |
| 0 | 688 | fn to_nalgebra(self) -> Self::NalgebraType; |
| 5 | 689 | |
| 690 | /// Convert to the mixed (nalgebra and num_traits) view of `self`. | |
| 0 | 691 | fn to_nalgebra_mixed(self) -> Self::MixedType; |
| 692 | ||
| 5 | 693 | /// Convert from the nalgebra view of `self`. |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
694 | fn from_nalgebra(t: Self::NalgebraType) -> Self; |
| 5 | 695 | |
| 696 | /// Convert from the mixed (nalgebra and num_traits) view to `self`. | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
697 | fn from_nalgebra_mixed(t: Self::MixedType) -> Self; |
| 0 | 698 | } |
| 699 | ||
| 700 | impl ToNalgebraRealField for f32 { | |
| 701 | type NalgebraType = f32; | |
| 702 | type MixedType = f32; | |
| 703 | ||
| 704 | #[inline] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
705 | fn to_nalgebra(self) -> Self::NalgebraType { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
706 | self |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
707 | } |
| 0 | 708 | |
| 709 | #[inline] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
710 | fn to_nalgebra_mixed(self) -> Self::MixedType { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
711 | self |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
712 | } |
| 0 | 713 | |
| 714 | #[inline] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
715 | fn from_nalgebra(t: Self::NalgebraType) -> Self { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
716 | t |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
717 | } |
| 0 | 718 | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
719 | #[inline] |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
720 | fn from_nalgebra_mixed(t: Self::MixedType) -> Self { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
721 | t |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
722 | } |
| 0 | 723 | } |
| 724 | ||
| 725 | impl ToNalgebraRealField for f64 { | |
| 726 | type NalgebraType = f64; | |
| 727 | type MixedType = f64; | |
| 728 | ||
| 729 | #[inline] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
730 | fn to_nalgebra(self) -> Self::NalgebraType { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
731 | self |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
732 | } |
| 0 | 733 | |
| 734 | #[inline] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
735 | fn to_nalgebra_mixed(self) -> Self::MixedType { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
736 | self |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
737 | } |
| 0 | 738 | |
| 739 | #[inline] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
740 | fn from_nalgebra(t: Self::NalgebraType) -> Self { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
741 | t |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
742 | } |
| 0 | 743 | |
| 744 | #[inline] | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
745 | fn from_nalgebra_mixed(t: Self::MixedType) -> Self { |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
746 | t |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
747 | } |
| 0 | 748 | } |