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