| 92 } |
92 } |
| 93 |
93 |
| 94 #[derive(Copy, Clone, Debug)] |
94 #[derive(Copy, Clone, Debug)] |
| 95 pub struct MatrixDecomposition; |
95 pub struct MatrixDecomposition; |
| 96 |
96 |
| 97 /// nalgebra [`Storage`] that's convertible to dynamic strides (practically all, but we need this |
97 impl<E, M, K, S> Decomposition<Matrix<E, M, K, S>> for MatrixDecomposition |
| 98 /// to work around the type system). |
|
| 99 trait ViewableStorage<E, M, K = U1>: Storage<E, M, K> |
|
| 100 where |
|
| 101 M: Dim, |
|
| 102 K: Dim, |
|
| 103 E: Scalar, |
|
| 104 ShapeConstraint: StridesOk<E, M, K, Self>, |
|
| 105 DefaultAllocator: Allocator<M, K>, |
|
| 106 { |
|
| 107 } |
|
| 108 |
|
| 109 impl<M, K, E, S> ViewableStorage<E, M, K> for S |
|
| 110 where |
98 where |
| 111 S: Storage<E, M, K>, |
99 S: Storage<E, M, K>, |
| 112 M: Dim, |
|
| 113 K: Dim, |
|
| 114 E: Scalar, |
|
| 115 ShapeConstraint: StridesOk<E, M, K, Self>, |
|
| 116 DefaultAllocator: Allocator<M, K>, |
|
| 117 { |
|
| 118 } |
|
| 119 |
|
| 120 /// nalgebra [`StorageMut`] that's convertible to dynamic strides (practically all, but we need this |
|
| 121 /// to work around the type system). |
|
| 122 trait ViewableStorageMut<E, M, K = U1>: StorageMut<E, M, K> |
|
| 123 where |
|
| 124 M: Dim, |
|
| 125 K: Dim, |
|
| 126 E: Scalar, |
|
| 127 ShapeConstraint: StridesOk<E, M, K, Self>, |
|
| 128 DefaultAllocator: Allocator<M, K>, |
|
| 129 { |
|
| 130 } |
|
| 131 |
|
| 132 impl<M, K, E, S> ViewableStorageMut<E, M, K> for S |
|
| 133 where |
|
| 134 S: StorageMut<E, M, K>, |
|
| 135 M: Dim, |
|
| 136 K: Dim, |
|
| 137 E: Scalar, |
|
| 138 ShapeConstraint: StridesOk<E, M, K, Self>, |
|
| 139 DefaultAllocator: Allocator<M, K>, |
|
| 140 { |
|
| 141 } |
|
| 142 |
|
| 143 impl<E, M, K, S> Decomposition<Matrix<E, M, K, S>> for MatrixDecomposition |
|
| 144 where |
|
| 145 S: ViewableStorage<E, M, K>, |
|
| 146 M: Dim, |
100 M: Dim, |
| 147 K: Dim, |
101 K: Dim, |
| 148 E: Scalar + Zero + One, |
102 E: Scalar + Zero + One, |
| 149 DefaultAllocator: Allocator<M, K>, |
103 DefaultAllocator: Allocator<M, K>, |
| 150 ShapeConstraint: StridesOk<E, M, K, S> + StridesOk<E, M, K>, |
104 ShapeConstraint: StridesOk<E, M, K, S> + StridesOk<E, M, K>, |
| 169 } |
123 } |
| 170 } |
124 } |
| 171 |
125 |
| 172 impl<S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> for Matrix<E, M, K, S2> |
126 impl<S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> for Matrix<E, M, K, S2> |
| 173 where |
127 where |
| 174 S1: ViewableStorage<E, M, K>, |
128 S1: Storage<E, M, K>, |
| 175 S2: ViewableStorage<E, M, K>, |
129 S2: Storage<E, M, K>, |
| 176 M: Dim, |
130 M: Dim, |
| 177 K: Dim, |
131 K: Dim, |
| 178 E: Scalar + Zero + One, |
132 E: Scalar + Zero + One, |
| 179 DefaultAllocator: Allocator<M, K>, |
133 DefaultAllocator: Allocator<M, K>, |
| 180 ShapeConstraint: StridesOk<E, M, K, S1> + StridesOk<E, M, K, S2>, |
134 ShapeConstraint: StridesOk<E, M, K, S1> + StridesOk<E, M, K, S2>, |
| 204 } |
158 } |
| 205 |
159 |
| 206 impl<'a, S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> |
160 impl<'a, S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> |
| 207 for &'a Matrix<E, M, K, S2> |
161 for &'a Matrix<E, M, K, S2> |
| 208 where |
162 where |
| 209 S1: ViewableStorage<E, M, K>, |
163 S1: Storage<E, M, K>, |
| 210 S2: ViewableStorage<E, M, K>, |
164 S2: Storage<E, M, K>, |
| 211 M: Dim, |
165 M: Dim, |
| 212 K: Dim, |
166 K: Dim, |
| 213 E: Scalar + Zero + One, |
167 E: Scalar + Zero + One, |
| 214 DefaultAllocator: Allocator<M, K>, |
168 DefaultAllocator: Allocator<M, K>, |
| 215 ShapeConstraint: StridesOk<E, M, K, S1> + StridesOk<E, M, K, S2>, |
169 ShapeConstraint: StridesOk<E, M, K, S1> + StridesOk<E, M, K, S2>, |
| 238 } |
192 } |
| 239 } |
193 } |
| 240 |
194 |
| 241 impl<SM, SV, N, M, K, E> Mapping<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM> |
195 impl<SM, SV, N, M, K, E> Mapping<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM> |
| 242 where |
196 where |
| 243 SM: ViewableStorage<E, N, M>, |
197 SM: Storage<E, N, M>, |
| 244 SV: ViewableStorage<E, M, K> + Clone, |
198 SV: Storage<E, M, K> + Clone, |
| 245 N: Dim, |
199 N: Dim, |
| 246 M: Dim, |
200 M: Dim, |
| 247 K: Dim, |
201 K: Dim, |
| 248 E: Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, |
202 E: Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, |
| 249 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
203 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
| 257 } |
211 } |
| 258 } |
212 } |
| 259 |
213 |
| 260 impl<'a, SM, SV, N, M, K, E> Linear<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM> |
214 impl<'a, SM, SV, N, M, K, E> Linear<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM> |
| 261 where |
215 where |
| 262 SM: ViewableStorage<E, N, M>, |
216 SM: Storage<E, N, M>, |
| 263 SV: ViewableStorage<E, M, K> + Clone, |
217 SV: Storage<E, M, K> + Clone, |
| 264 N: Dim, |
218 N: Dim, |
| 265 M: Dim, |
219 M: Dim, |
| 266 K: Dim, |
220 K: Dim, |
| 267 E: Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, |
221 E: Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, |
| 268 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
222 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
| 271 } |
225 } |
| 272 |
226 |
| 273 impl<SM, SV1, SV2, N, M, K, E> GEMV<E, Matrix<E, M, K, SV1>, Matrix<E, N, K, SV2>> |
227 impl<SM, SV1, SV2, N, M, K, E> GEMV<E, Matrix<E, M, K, SV1>, Matrix<E, N, K, SV2>> |
| 274 for Matrix<E, N, M, SM> |
228 for Matrix<E, N, M, SM> |
| 275 where |
229 where |
| 276 SM: ViewableStorage<E, N, M>, |
230 SM: Storage<E, N, M>, |
| 277 SV1: ViewableStorage<E, M, K> + Clone, |
231 SV1: Storage<E, M, K> + Clone, |
| 278 SV2: ViewableStorageMut<E, N, K>, |
232 SV2: StorageMut<E, N, K>, |
| 279 N: Dim, |
233 N: Dim, |
| 280 M: Dim, |
234 M: Dim, |
| 281 K: Dim, |
235 K: Dim, |
| 282 E: Scalar + Zero + One + Float, |
236 E: Scalar + Zero + One + Float, |
| 283 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
237 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
| 300 } |
254 } |
| 301 } |
255 } |
| 302 |
256 |
| 303 impl<S, M, N, E> VectorSpace for Matrix<E, M, N, S> |
257 impl<S, M, N, E> VectorSpace for Matrix<E, M, N, S> |
| 304 where |
258 where |
| 305 S: ViewableStorage<E, M, N>, |
259 S: Storage<E, M, N>, |
| 306 M: Dim, |
260 M: Dim, |
| 307 N: Dim, |
261 N: Dim, |
| 308 E: Scalar + Zero + One + Float, |
262 E: Scalar + Zero + One + Float, |
| 309 DefaultAllocator: Allocator<M, N>, |
263 DefaultAllocator: Allocator<M, N>, |
| 310 ShapeConstraint: StridesOk<E, M, N, S>, |
264 ShapeConstraint: StridesOk<E, M, N, S>, |
| 319 } |
273 } |
| 320 } |
274 } |
| 321 |
275 |
| 322 impl<SM, SV1, M, N, E> AXPY<Matrix<E, M, N, SV1>> for Matrix<E, M, N, SM> |
276 impl<SM, SV1, M, N, E> AXPY<Matrix<E, M, N, SV1>> for Matrix<E, M, N, SM> |
| 323 where |
277 where |
| 324 SM: ViewableStorageMut<E, M, N>, |
278 SM: StorageMut<E, M, N>, |
| 325 SV1: ViewableStorage<E, M, N>, |
279 SV1: Storage<E, M, N>, |
| 326 M: Dim, |
280 M: Dim, |
| 327 N: Dim, |
281 N: Dim, |
| 328 E: Scalar + Zero + One + Float, |
282 E: Scalar + Zero + One + Float, |
| 329 DefaultAllocator: Allocator<M, N>, |
283 DefaultAllocator: Allocator<M, N>, |
| 330 ShapeConstraint: StridesOk<E, M, N, SM> + StridesOk<E, M, N, SV1>, |
284 ShapeConstraint: StridesOk<E, M, N, SM> + StridesOk<E, M, N, SV1>, |
| 366 } |
320 } |
| 367 }*/ |
321 }*/ |
| 368 |
322 |
| 369 impl<SM, M, E> Projection<E, Linfinity> for Vector<E, M, SM> |
323 impl<SM, M, E> Projection<E, Linfinity> for Vector<E, M, SM> |
| 370 where |
324 where |
| 371 SM: ViewableStorageMut<E, M> + Clone, |
325 SM: StorageMut<E, M> + Clone, |
| 372 M: Dim, |
326 M: Dim, |
| 373 E: Scalar + Zero + One + Float + RealField, |
327 E: Scalar + Zero + One + Float + RealField, |
| 374 DefaultAllocator: Allocator<M>, |
328 DefaultAllocator: Allocator<M>, |
| 375 ShapeConstraint: StridesOk<E, M, U1, SM>, |
329 ShapeConstraint: StridesOk<E, M, U1, SM>, |
| 376 { |
330 { |
| 382 } |
336 } |
| 383 } |
337 } |
| 384 |
338 |
| 385 impl<SM, M, E> ProjectionMut<E, Linfinity> for Vector<E, M, SM> |
339 impl<SM, M, E> ProjectionMut<E, Linfinity> for Vector<E, M, SM> |
| 386 where |
340 where |
| 387 SM: ViewableStorageMut<E, M> + Clone, |
341 SM: StorageMut<E, M> + Clone, |
| 388 M: Dim, |
342 M: Dim, |
| 389 E: Scalar + Zero + One + Float + RealField, |
343 E: Scalar + Zero + One + Float + RealField, |
| 390 DefaultAllocator: Allocator<M>, |
344 DefaultAllocator: Allocator<M>, |
| 391 ShapeConstraint: StridesOk<E, M, U1, SM>, |
345 ShapeConstraint: StridesOk<E, M, U1, SM>, |
| 392 { |
346 { |
| 398 } |
352 } |
| 399 |
353 |
| 400 impl<'own, SV1, SV2, SM, N, M, K, E> Adjointable<Matrix<E, M, K, SV1>, Matrix<E, N, K, SV2>> |
354 impl<'own, SV1, SV2, SM, N, M, K, E> Adjointable<Matrix<E, M, K, SV1>, Matrix<E, N, K, SV2>> |
| 401 for Matrix<E, N, M, SM> |
355 for Matrix<E, N, M, SM> |
| 402 where |
356 where |
| 403 SM: ViewableStorage<E, N, M>, |
357 SM: Storage<E, N, M>, |
| 404 SV1: ViewableStorage<E, M, K> + Clone, |
358 SV1: Storage<E, M, K> + Clone, |
| 405 SV2: ViewableStorage<E, N, K> + Clone, |
359 SV2: Storage<E, N, K> + Clone, |
| 406 N: Dim, |
360 N: Dim, |
| 407 M: Dim, |
361 M: Dim, |
| 408 K: Dim, |
362 K: Dim, |
| 409 E: Scalar + Zero + One + SimdComplexField, |
363 E: Scalar + Zero + One + SimdComplexField, |
| 410 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
364 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
| 451 // TODO: should allow different input storages in `Euclidean`. |
405 // TODO: should allow different input storages in `Euclidean`. |
| 452 |
406 |
| 453 impl<E, M, S> Euclidean<E> for Vector<E, M, S> |
407 impl<E, M, S> Euclidean<E> for Vector<E, M, S> |
| 454 where |
408 where |
| 455 M: Dim, |
409 M: Dim, |
| 456 S: ViewableStorage<E, M>, |
410 S: Storage<E, M>, |
| 457 E: Float + Scalar + Zero + One + RealField, |
411 E: Float + Scalar + Zero + One + RealField, |
| 458 DefaultAllocator: Allocator<M>, |
412 DefaultAllocator: Allocator<M>, |
| 459 ShapeConstraint: StridesOk<E, M, U1, S>, |
413 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 460 { |
414 { |
| 461 type OwnedEuclidean = OVector<E, M>; |
415 type OwnedEuclidean = OVector<E, M>; |
| 477 } |
431 } |
| 478 |
432 |
| 479 impl<E, M, S> StaticEuclidean<E> for Vector<E, M, S> |
433 impl<E, M, S> StaticEuclidean<E> for Vector<E, M, S> |
| 480 where |
434 where |
| 481 M: DimName, |
435 M: DimName, |
| 482 S: ViewableStorage<E, M>, |
436 S: Storage<E, M>, |
| 483 E: Float + Scalar + Zero + One + RealField, |
437 E: Float + Scalar + Zero + One + RealField, |
| 484 DefaultAllocator: Allocator<M>, |
438 DefaultAllocator: Allocator<M>, |
| 485 ShapeConstraint: StridesOk<E, M, U1, S>, |
439 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 486 { |
440 { |
| 487 #[inline] |
441 #[inline] |
| 492 |
446 |
| 493 /// The default norm for `Vector` is [`L2`]. |
447 /// The default norm for `Vector` is [`L2`]. |
| 494 impl<E, M, S> Normed<E> for Vector<E, M, S> |
448 impl<E, M, S> Normed<E> for Vector<E, M, S> |
| 495 where |
449 where |
| 496 M: Dim, |
450 M: Dim, |
| 497 S: ViewableStorage<E, M>, |
451 S: Storage<E, M>, |
| 498 E: Float + Scalar + Zero + One + RealField, |
452 E: Float + Scalar + Zero + One + RealField, |
| 499 DefaultAllocator: Allocator<M>, |
453 DefaultAllocator: Allocator<M>, |
| 500 ShapeConstraint: StridesOk<E, M, U1, S>, |
454 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 501 { |
455 { |
| 502 type NormExp = L2; |
456 type NormExp = L2; |
| 513 } |
467 } |
| 514 |
468 |
| 515 impl<E, M, S> HasDual<E> for Vector<E, M, S> |
469 impl<E, M, S> HasDual<E> for Vector<E, M, S> |
| 516 where |
470 where |
| 517 M: Dim, |
471 M: Dim, |
| 518 S: ViewableStorage<E, M>, |
472 S: Storage<E, M>, |
| 519 E: Float + Scalar + Zero + One + RealField, |
473 E: Float + Scalar + Zero + One + RealField, |
| 520 DefaultAllocator: Allocator<M>, |
474 DefaultAllocator: Allocator<M>, |
| 521 ShapeConstraint: StridesOk<E, M, U1, S>, |
475 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 522 { |
476 { |
| 523 type DualSpace = OVector<E, M>; |
477 type DualSpace = OVector<E, M>; |
| 528 } |
482 } |
| 529 |
483 |
| 530 impl<E, M, S> Norm<L1, E> for Vector<E, M, S> |
484 impl<E, M, S> Norm<L1, E> for Vector<E, M, S> |
| 531 where |
485 where |
| 532 M: Dim, |
486 M: Dim, |
| 533 S: ViewableStorage<E, M>, |
487 S: Storage<E, M>, |
| 534 E: Float + Scalar + Zero + One + RealField, |
488 E: Float + Scalar + Zero + One + RealField, |
| 535 DefaultAllocator: Allocator<M>, |
489 DefaultAllocator: Allocator<M>, |
| 536 ShapeConstraint: StridesOk<E, M, U1, S>, |
490 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 537 { |
491 { |
| 538 #[inline] |
492 #[inline] |
| 542 } |
496 } |
| 543 |
497 |
| 544 impl<E, M, S> Dist<L1, E> for Vector<E, M, S> |
498 impl<E, M, S> Dist<L1, E> for Vector<E, M, S> |
| 545 where |
499 where |
| 546 M: Dim, |
500 M: Dim, |
| 547 S: ViewableStorage<E, M> + Clone, |
501 S: Storage<E, M> + Clone, |
| 548 E: Float + Scalar + Zero + One + RealField, |
502 E: Float + Scalar + Zero + One + RealField, |
| 549 DefaultAllocator: Allocator<M>, |
503 DefaultAllocator: Allocator<M>, |
| 550 ShapeConstraint: StridesOk<E, M, U1, S>, |
504 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 551 { |
505 { |
| 552 #[inline] |
506 #[inline] |
| 556 } |
510 } |
| 557 |
511 |
| 558 impl<E, M, S> Norm<L2, E> for Vector<E, M, S> |
512 impl<E, M, S> Norm<L2, E> for Vector<E, M, S> |
| 559 where |
513 where |
| 560 M: Dim, |
514 M: Dim, |
| 561 S: ViewableStorage<E, M>, |
515 S: Storage<E, M>, |
| 562 E: Float + Scalar + Zero + One + RealField, |
516 E: Float + Scalar + Zero + One + RealField, |
| 563 DefaultAllocator: Allocator<M>, |
517 DefaultAllocator: Allocator<M>, |
| 564 ShapeConstraint: StridesOk<E, M, U1, S>, |
518 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 565 { |
519 { |
| 566 #[inline] |
520 #[inline] |
| 570 } |
524 } |
| 571 |
525 |
| 572 impl<E, M, S> Dist<L2, E> for Vector<E, M, S> |
526 impl<E, M, S> Dist<L2, E> for Vector<E, M, S> |
| 573 where |
527 where |
| 574 M: Dim, |
528 M: Dim, |
| 575 S: ViewableStorage<E, M> + Clone, |
529 S: Storage<E, M> + Clone, |
| 576 E: Float + Scalar + Zero + One + RealField, |
530 E: Float + Scalar + Zero + One + RealField, |
| 577 DefaultAllocator: Allocator<M>, |
531 DefaultAllocator: Allocator<M>, |
| 578 ShapeConstraint: StridesOk<E, M, U1, S>, |
532 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 579 { |
533 { |
| 580 #[inline] |
534 #[inline] |
| 584 } |
538 } |
| 585 |
539 |
| 586 impl<E, M, S> Norm<Linfinity, E> for Vector<E, M, S> |
540 impl<E, M, S> Norm<Linfinity, E> for Vector<E, M, S> |
| 587 where |
541 where |
| 588 M: Dim, |
542 M: Dim, |
| 589 S: ViewableStorage<E, M>, |
543 S: Storage<E, M>, |
| 590 E: Float + Scalar + Zero + One + RealField, |
544 E: Float + Scalar + Zero + One + RealField, |
| 591 DefaultAllocator: Allocator<M>, |
545 DefaultAllocator: Allocator<M>, |
| 592 ShapeConstraint: StridesOk<E, M, U1, S>, |
546 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 593 { |
547 { |
| 594 #[inline] |
548 #[inline] |
| 598 } |
552 } |
| 599 |
553 |
| 600 impl<E, M, S> Dist<Linfinity, E> for Vector<E, M, S> |
554 impl<E, M, S> Dist<Linfinity, E> for Vector<E, M, S> |
| 601 where |
555 where |
| 602 M: Dim, |
556 M: Dim, |
| 603 S: ViewableStorage<E, M> + Clone, |
557 S: Storage<E, M> + Clone, |
| 604 E: Float + Scalar + Zero + One + RealField, |
558 E: Float + Scalar + Zero + One + RealField, |
| 605 DefaultAllocator: Allocator<M>, |
559 DefaultAllocator: Allocator<M>, |
| 606 ShapeConstraint: StridesOk<E, M, U1, S>, |
560 ShapeConstraint: StridesOk<E, M, U1, S>, |
| 607 { |
561 { |
| 608 #[inline] |
562 #[inline] |