Skip to content

Commit

Permalink
bugfix: matrix/row alloc and svd qr algo pre-normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-quinones committed Sep 23, 2024
1 parent bb213d1 commit 988acab
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/col/colown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,8 @@ impl<E: Entity> Clone for Col<E> {
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(),
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1788,5 +1788,5 @@ mod tests {
}
}

#[path = "krylov_schur.rs"]
mod krylov_schur_prototype;
// #[path = "krylov_schur.rs"]
// mod krylov_schur_prototype;
2 changes: 0 additions & 2 deletions src/linalg/svd/bidiag_real_svd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,6 @@ fn bidiag_svd_qr_algorithm_impl<E: RealField>(
}
}

let max_val = E::faer_one();

if max_val == E::faer_zero() {
return;
}
Expand Down
8 changes: 5 additions & 3 deletions src/mat/matown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ impl<E: Entity> Mat<E> {
.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;
Expand Down Expand Up @@ -1044,7 +1046,7 @@ impl<E: Entity> Mat<E> {
this: &mut Mat<E>,
other: MatRef<'_, ViewE>,
) {
let (rows, cols)=other.shape();
let (rows, cols) = other.shape();
this.resize_with(0, 0, |_, _| E::zeroed());
this.resize_with(
rows,
Expand Down Expand Up @@ -2070,9 +2072,9 @@ impl<E: Entity> Clone for Mat<E> {
})
}
}

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,
Expand Down
8 changes: 8 additions & 0 deletions src/mat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,12 @@ mod tests {
from_mut::<f64>(&mut c).fill(3.0);
assert!(c == 3.0);
}

#[test]
fn test_alloc() {
let mut a = crate::Mat::<f64>::zeros(2, 2);

a.reserve_exact(128, 0);
a.reserve_exact(129, 1);
}
}
8 changes: 4 additions & 4 deletions src/row/rowown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ impl<E: Entity> Row<E> {
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| {
Expand Down Expand Up @@ -1030,8 +1030,8 @@ impl<E: Entity> Clone for Row<E> {
})
}
}
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(),
Expand Down
9 changes: 6 additions & 3 deletions src/sparse/linalg/solvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ pub trait SpSolverLstsqCore<E: Entity>: SpSolverCore<E> {
pub trait SpSolver<E: ComplexField>: SpSolverCore<E> {
/// Solves the equation `self * X = rhs` when self is square, and stores the result in `rhs`.
fn solve_in_place(&self, rhs: impl ColBatchMut<E>);
/// 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<E>);
/// 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<E>);
/// 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<E>);
/// Solves the equation `self * X = rhs` when self is square, and returns the result.
fn solve<ViewE: Conjugate<Canonical = E>, B: ColBatch<ViewE>>(&self, rhs: B) -> B::Owned;
Expand Down

0 comments on commit 988acab

Please sign in to comment.