From 988acab18173f9f934b11d51bb5f31e0afb74df0 Mon Sep 17 00:00:00 2001 From: sarah Date: Mon, 23 Sep 2024 05:23:50 +0000 Subject: [PATCH] bugfix: matrix/row alloc and svd qr algo pre-normalization --- src/col/colown.rs | 3 ++- src/lib.rs | 4 ++-- src/linalg/svd/bidiag_real_svd.rs | 2 -- src/mat/matown.rs | 8 +++++--- src/mat/mod.rs | 8 ++++++++ src/row/rowown.rs | 8 ++++---- src/sparse/linalg/solvers.rs | 9 ++++++--- 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/col/colown.rs b/src/col/colown.rs index 50565610..9248cca6 100644 --- a/src/col/colown.rs +++ b/src/col/colown.rs @@ -1069,7 +1069,8 @@ impl Clone for Col { E::faer_from_units(E::faer_deref(this.get_unchecked(i))) }) } - }fn clone_from(&mut self,other:&Self){ + } + fn clone_from(&mut self, other: &Self) { self.resize_with(0, |_| E::zeroed()); self.resize_with( other.nrows(), diff --git a/src/lib.rs b/src/lib.rs index f578082f..8cc42259 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1788,5 +1788,5 @@ mod tests { } } -#[path = "krylov_schur.rs"] -mod krylov_schur_prototype; +// #[path = "krylov_schur.rs"] +// mod krylov_schur_prototype; diff --git a/src/linalg/svd/bidiag_real_svd.rs b/src/linalg/svd/bidiag_real_svd.rs index 53e355b2..c8048e95 100644 --- a/src/linalg/svd/bidiag_real_svd.rs +++ b/src/linalg/svd/bidiag_real_svd.rs @@ -1187,8 +1187,6 @@ fn bidiag_svd_qr_algorithm_impl( } } - let max_val = E::faer_one(); - if max_val == E::faer_zero() { return; } diff --git a/src/mat/matown.rs b/src/mat/matown.rs index 3f7fc3be..5c1c6e58 100644 --- a/src/mat/matown.rs +++ b/src/mat/matown.rs @@ -309,6 +309,8 @@ impl Mat { .msrv_checked_next_multiple_of(align_factor) .unwrap(); } + let new_row_capacity = Ord::max(new_row_capacity, self.inner.nrows); + let new_col_capacity = Ord::max(new_col_capacity, self.inner.ncols); let nrows = self.inner.nrows; let ncols = self.inner.ncols; @@ -1044,7 +1046,7 @@ impl Mat { this: &mut Mat, other: MatRef<'_, ViewE>, ) { - let (rows, cols)=other.shape(); + let (rows, cols) = other.shape(); this.resize_with(0, 0, |_, _| E::zeroed()); this.resize_with( rows, @@ -2070,9 +2072,9 @@ impl Clone for Mat { }) } } - + fn clone_from(&mut self, other: &Self) { - let (rows, cols)=other.shape(); + let (rows, cols) = other.shape(); self.resize_with(0, 0, |_, _| E::zeroed()); self.resize_with( rows, diff --git a/src/mat/mod.rs b/src/mat/mod.rs index bef1ed82..2dda76fa 100644 --- a/src/mat/mod.rs +++ b/src/mat/mod.rs @@ -232,4 +232,12 @@ mod tests { from_mut::(&mut c).fill(3.0); assert!(c == 3.0); } + + #[test] + fn test_alloc() { + let mut a = crate::Mat::::zeros(2, 2); + + a.reserve_exact(128, 0); + a.reserve_exact(129, 1); + } } diff --git a/src/row/rowown.rs b/src/row/rowown.rs index 5b5f9d57..407bfa07 100644 --- a/src/row/rowown.rs +++ b/src/row/rowown.rs @@ -307,8 +307,8 @@ impl Row { row_capacity: old_col_capacity, col_capacity: 1, }, - ncols, - nrows: 1, + nrows: ncols, + ncols: 1, }); E::faer_map(E::faer_as_mut(&mut this_group), |mat_unit| { @@ -1030,8 +1030,8 @@ impl Clone for Row { }) } } - - fn clone_from(&mut self, other: &Self){ + + fn clone_from(&mut self, other: &Self) { self.resize_with(0, |_| E::zeroed()); self.resize_with( other.nrows(), diff --git a/src/sparse/linalg/solvers.rs b/src/sparse/linalg/solvers.rs index ce7c2df7..a853f7ab 100644 --- a/src/sparse/linalg/solvers.rs +++ b/src/sparse/linalg/solvers.rs @@ -27,11 +27,14 @@ pub trait SpSolverLstsqCore: SpSolverCore { pub trait SpSolver: SpSolverCore { /// Solves the equation `self * X = rhs` when self is square, and stores the result in `rhs`. fn solve_in_place(&self, rhs: impl ColBatchMut); - /// Solves the equation `conjugate(self) * X = rhs` when self is square, and stores the result in `rhs`. + /// Solves the equation `conjugate(self) * X = rhs` when self is square, and stores the result + /// in `rhs`. fn solve_conj_in_place(&self, rhs: impl ColBatchMut); - /// Solves the equation `transpose(self) * X = rhs` when self is square, and stores the result in `rhs`. + /// Solves the equation `transpose(self) * X = rhs` when self is square, and stores the result + /// in `rhs`. fn solve_transpose_in_place(&self, rhs: impl ColBatchMut); - /// Solves the equation `adjoint(self) * X = rhs` when self is square, and stores the result in `rhs`. + /// Solves the equation `adjoint(self) * X = rhs` when self is square, and stores the result in + /// `rhs`. fn solve_conj_transpose_in_place(&self, rhs: impl ColBatchMut); /// Solves the equation `self * X = rhs` when self is square, and returns the result. fn solve, B: ColBatch>(&self, rhs: B) -> B::Owned;