From 70bb2cbe46ddf86cedd465de33d88be5adc4e61b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 13 Aug 2017 19:53:00 +0200 Subject: [PATCH] Implement Clone, Debug, Copy for all linalg structures. --- src/linalg/bidiagonal.rs | 14 ++++++++++++-- src/linalg/cholesky.rs | 5 +++++ src/linalg/eigen.rs | 8 ++++++++ src/linalg/full_piv_lu.rs | 8 ++++++++ src/linalg/hessenberg.rs | 7 +++++++ src/linalg/lu.rs | 7 +++++++ src/linalg/permutation_sequence.rs | 7 ++++++- src/linalg/qr.rs | 8 ++++++++ src/linalg/schur.rs | 7 +++++++ src/linalg/svd.rs | 12 +++++++++++- src/linalg/symmetric_eigen.rs | 7 +++++++ src/linalg/symmetric_tridiagonal.rs | 7 +++++++ 12 files changed, 93 insertions(+), 4 deletions(-) diff --git a/src/linalg/bidiagonal.rs b/src/linalg/bidiagonal.rs index 87d171b2..565dee65 100644 --- a/src/linalg/bidiagonal.rs +++ b/src/linalg/bidiagonal.rs @@ -10,6 +10,7 @@ use geometry::Reflection; /// The bidiagonalization of a general matrix. +#[derive(Clone, Debug)] pub struct Bidiagonal, C: Dim> where DimMinimum: DimSub, DefaultAllocator: Allocator + @@ -17,14 +18,23 @@ pub struct Bidiagonal, C: Dim> Allocator, U1>> { // FIXME: perhaps we should pack the axises into different vectors so that axises for `v_t` are // contiguous. This prevents some useless copies. - uv: MatrixMN, + uv: MatrixMN, /// The diagonal elements of the decomposed matrix. - pub diagonal: VectorN>, + pub diagonal: VectorN>, /// The off-diagonal elements of the decomposed matrix. pub off_diagonal: VectorN, U1>>, upper_diagonal: bool } +impl, C: Dim> Copy for Bidiagonal + where DimMinimum: DimSub, + DefaultAllocator: Allocator + + Allocator> + + Allocator, U1>>, + MatrixMN: Copy, + VectorN>: Copy, + VectorN, U1>>: Copy { } + impl, C: Dim> Bidiagonal where DimMinimum: DimSub, DefaultAllocator: Allocator + diff --git a/src/linalg/cholesky.rs b/src/linalg/cholesky.rs index 90d8db7b..6037cc9f 100644 --- a/src/linalg/cholesky.rs +++ b/src/linalg/cholesky.rs @@ -7,11 +7,16 @@ use allocator::Allocator; use dimension::{Dim, Dynamic, DimSub}; /// The cholesky decomposion of a symmetric-definite-positive matrix. +#[derive(Clone, Debug)] pub struct Cholesky where DefaultAllocator: Allocator { chol: MatrixN } +impl Copy for Cholesky + where DefaultAllocator: Allocator, + MatrixN: Copy { } + impl> Cholesky where DefaultAllocator: Allocator { /// Attempts to compute the sholesky decomposition of `matrix`. diff --git a/src/linalg/eigen.rs b/src/linalg/eigen.rs index 9b6cee30..9d0ec50c 100644 --- a/src/linalg/eigen.rs +++ b/src/linalg/eigen.rs @@ -16,6 +16,7 @@ use geometry::{Reflection, UnitComplex}; /// The eigendecomposition of a matrix with real eigenvalues. +#[derive(Clone, Debug)] pub struct RealEigen where DefaultAllocator: Allocator + Allocator { @@ -23,6 +24,13 @@ pub struct RealEigen pub eigenvalues: VectorN } + +impl Copy for RealEigen + where DefaultAllocator: Allocator + + Allocator, + MatrixN: Copy, + VectorN: Copy { } + impl RealEigen where D: DimSub, // For Hessenberg. ShapeConstraint: DimEq>, // For Hessenberg. diff --git a/src/linalg/full_piv_lu.rs b/src/linalg/full_piv_lu.rs index 39a1c06c..a972efff 100644 --- a/src/linalg/full_piv_lu.rs +++ b/src/linalg/full_piv_lu.rs @@ -11,6 +11,7 @@ use linalg::PermutationSequence; /// LU decomposition with full pivoting. +#[derive(Clone, Debug)] pub struct FullPivLU, C: Dim> where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> { @@ -20,6 +21,13 @@ pub struct FullPivLU, C: Dim> } +impl, C: Dim> Copy for FullPivLU + where DefaultAllocator: Allocator + + Allocator<(usize, usize), DimMinimum>, + MatrixMN: Copy, + PermutationSequence>: Copy { } + + impl, C: Dim> FullPivLU where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> { diff --git a/src/linalg/hessenberg.rs b/src/linalg/hessenberg.rs index 85023854..f8514df6 100644 --- a/src/linalg/hessenberg.rs +++ b/src/linalg/hessenberg.rs @@ -8,6 +8,7 @@ use constraint::{ShapeConstraint, DimEq}; use linalg::householder; /// The Hessenberg decomposition of a general matrix. +#[derive(Clone, Debug)] pub struct Hessenberg> where DefaultAllocator: Allocator + Allocator> { @@ -16,6 +17,12 @@ pub struct Hessenberg> subdiag: VectorN> } +impl> Copy for Hessenberg + where DefaultAllocator: Allocator + + Allocator>, + MatrixN: Copy, + VectorN>: Copy { } + impl> Hessenberg where DefaultAllocator: Allocator + Allocator + diff --git a/src/linalg/lu.rs b/src/linalg/lu.rs index 532c6e32..6236251a 100644 --- a/src/linalg/lu.rs +++ b/src/linalg/lu.rs @@ -11,6 +11,7 @@ use linalg::PermutationSequence; /// LU decomposition with partial (row) pivoting. +#[derive(Clone, Debug)] pub struct LU, C: Dim> where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> { @@ -18,6 +19,12 @@ pub struct LU, C: Dim> p: PermutationSequence> } +impl, C: Dim> Copy for LU + where DefaultAllocator: Allocator + + Allocator<(usize, usize), DimMinimum>, + MatrixMN: Copy, + PermutationSequence>: Copy { } + /// Performs a LU decomposition to overwrite `out` with the inverse of `matrix`. /// /// If `matrix` is not invertible, `false` is returned and `out` may contain invalid data. diff --git a/src/linalg/permutation_sequence.rs b/src/linalg/permutation_sequence.rs index 67dda8d6..6d38be31 100644 --- a/src/linalg/permutation_sequence.rs +++ b/src/linalg/permutation_sequence.rs @@ -8,12 +8,17 @@ use allocator::Allocator; /// A sequence of permutations. +#[derive(Clone, Debug)] pub struct PermutationSequence - where DefaultAllocator: Allocator<(usize, usize), D>{ + where DefaultAllocator: Allocator<(usize, usize), D> { len: usize, ipiv: VectorN<(usize, usize), D> } +impl Copy for PermutationSequence + where DefaultAllocator: Allocator<(usize, usize), D>, + VectorN<(usize, usize), D>: Copy { } + impl PermutationSequence where DefaultAllocator: Allocator<(usize, usize), D> { diff --git a/src/linalg/qr.rs b/src/linalg/qr.rs index b6a7d516..50b4fc19 100644 --- a/src/linalg/qr.rs +++ b/src/linalg/qr.rs @@ -10,6 +10,7 @@ use geometry::Reflection; /// The QR decomposition of a general matrix. +#[derive(Clone, Debug)] pub struct QR, C: Dim> where DefaultAllocator: Allocator + Allocator> { @@ -17,6 +18,13 @@ pub struct QR, C: Dim> diag: VectorN>, } + +impl, C: Dim> Copy for QR + where DefaultAllocator: Allocator + + Allocator>, + MatrixMN: Copy, + VectorN>: Copy { } + impl, C: Dim> QR where DefaultAllocator: Allocator + Allocator + diff --git a/src/linalg/schur.rs b/src/linalg/schur.rs index 4d319679..7b2eb290 100644 --- a/src/linalg/schur.rs +++ b/src/linalg/schur.rs @@ -15,6 +15,7 @@ use geometry::{Reflection, UnitComplex}; /// Real RealSchur decomposition of a square matrix. +#[derive(Clone, Debug)] pub struct RealSchur where DefaultAllocator: Allocator + Allocator { @@ -22,6 +23,12 @@ pub struct RealSchur t: MatrixN } + +impl Copy for RealSchur + where DefaultAllocator: Allocator + + Allocator, + MatrixN: Copy { } + impl RealSchur where D: DimSub, // For Hessenberg. ShapeConstraint: DimEq>, // For Hessenberg. diff --git a/src/linalg/svd.rs b/src/linalg/svd.rs index fd4bd0dc..710d547d 100644 --- a/src/linalg/svd.rs +++ b/src/linalg/svd.rs @@ -16,7 +16,7 @@ use geometry::UnitComplex; /// The Singular Value Decomposition of a real matrix. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct SVD, C: Dim> where DefaultAllocator: Allocator + Allocator, C> + @@ -30,6 +30,16 @@ pub struct SVD, C: Dim> pub singular_values: VectorN>, } + +impl, C: Dim> SVD + where DefaultAllocator: Allocator + + Allocator, C> + + Allocator> + + Allocator>, + MatrixMN>: Copy, + MatrixMN, C>: Copy, + VectorN>: Copy { } + impl, C: Dim> SVD where DimMinimum: DimSub, // for Bidiagonal. DefaultAllocator: Allocator + diff --git a/src/linalg/symmetric_eigen.rs b/src/linalg/symmetric_eigen.rs index 04a00a6a..b66154dd 100644 --- a/src/linalg/symmetric_eigen.rs +++ b/src/linalg/symmetric_eigen.rs @@ -13,6 +13,7 @@ use geometry::UnitComplex; /// The eigendecomposition of a symmetric matrix. +#[derive(Clone, Debug)] pub struct SymmetricEigen where DefaultAllocator: Allocator + Allocator { @@ -23,6 +24,12 @@ pub struct SymmetricEigen pub eigenvalues: VectorN } +impl SymmetricEigen + where DefaultAllocator: Allocator + + Allocator, + MatrixN: Copy, + VectorN: Copy { } + impl SymmetricEigen where DefaultAllocator: Allocator + Allocator { diff --git a/src/linalg/symmetric_tridiagonal.rs b/src/linalg/symmetric_tridiagonal.rs index 9e9713b3..bb922928 100644 --- a/src/linalg/symmetric_tridiagonal.rs +++ b/src/linalg/symmetric_tridiagonal.rs @@ -8,6 +8,7 @@ use linalg::householder; /// The tridiagonalization of a symmetric matrix. +#[derive(Clone, Debug)] pub struct SymmetricTridiagonal> where DefaultAllocator: Allocator + Allocator> { @@ -15,6 +16,12 @@ pub struct SymmetricTridiagonal> off_diagonal: VectorN> } +impl> SymmetricTridiagonal + where DefaultAllocator: Allocator + + Allocator>, + MatrixN: Copy, + VectorN>: Copy { } + impl> SymmetricTridiagonal where DefaultAllocator: Allocator + Allocator> {