diff --git a/README.md b/README.md index a2170e6d..0897a2fb 100644 --- a/README.md +++ b/README.md @@ -298,7 +298,7 @@ fn main() -> Result<(), StrError> { // . -1 -3 2 . // . . 1 . . // . 4 2 . 1 - let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None, false)?; + let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None)?; coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate coo.put(1, 0, 3.0)?; diff --git a/russell_ode/src/euler_backward.rs b/russell_ode/src/euler_backward.rs index b59ac09b..0a6eb880 100644 --- a/russell_ode/src/euler_backward.rs +++ b/russell_ode/src/euler_backward.rs @@ -1,7 +1,7 @@ use crate::StrError; use crate::{OdeSolverTrait, Params, System, Workspace}; use russell_lab::{vec_copy, vec_rms_scaled, vec_update, Vector}; -use russell_sparse::{CooMatrix, Genie, LinSolver, SparseMatrix}; +use russell_sparse::{CooMatrix, LinSolver, SparseMatrix}; /// Implements the backward Euler (implicit) solver pub(crate) struct EulerBackward<'a, F, J, A> @@ -51,7 +51,6 @@ where }; let nnz = jac_nnz + ndim; // +ndim corresponds to the diagonal I matrix let symmetry = Some(system.jac_symmetry); - let one_based = params.newton.genie == Genie::Mumps; EulerBackward { params, system, @@ -59,7 +58,7 @@ where w: Vector::new(ndim), r: Vector::new(ndim), dy: Vector::new(ndim), - kk: SparseMatrix::new_coo(ndim, ndim, nnz, symmetry, one_based).unwrap(), + kk: SparseMatrix::new_coo(ndim, ndim, nnz, symmetry).unwrap(), solver: LinSolver::new(params.newton.genie).unwrap(), } } diff --git a/russell_ode/src/radau5.rs b/russell_ode/src/radau5.rs index 133c3e1a..45a7df06 100644 --- a/russell_ode/src/radau5.rs +++ b/russell_ode/src/radau5.rs @@ -111,7 +111,6 @@ where pub fn new(params: Params, system: &'a System) -> Self { let ndim = system.ndim; let symmetry = Some(system.jac_symmetry); - let one_based = params.newton.genie == Genie::Mumps; let mass_nnz = match system.mass_matrix.as_ref() { Some(mass) => mass.get_info().2, None => ndim, @@ -126,9 +125,9 @@ where Radau5 { params, system, - jj: SparseMatrix::new_coo(ndim, ndim, jac_nnz, symmetry, one_based).unwrap(), - kk_real: SparseMatrix::new_coo(ndim, ndim, nnz, symmetry, one_based).unwrap(), - kk_comp: ComplexSparseMatrix::new_coo(ndim, ndim, nnz, symmetry, one_based).unwrap(), + jj: SparseMatrix::new_coo(ndim, ndim, jac_nnz, symmetry).unwrap(), + kk_real: SparseMatrix::new_coo(ndim, ndim, nnz, symmetry).unwrap(), + kk_comp: ComplexSparseMatrix::new_coo(ndim, ndim, nnz, symmetry).unwrap(), solver_real: LinSolver::new(params.newton.genie).unwrap(), solver_comp: ComplexLinSolver::new(params.newton.genie).unwrap(), reuse_jacobian: false, diff --git a/russell_ode/src/samples.rs b/russell_ode/src/samples.rs index aa09879d..cf3b0841 100644 --- a/russell_ode/src/samples.rs +++ b/russell_ode/src/samples.rs @@ -200,7 +200,7 @@ impl Samples { // mass matrix let mass_nnz = 5; - system.init_mass_matrix(mass_nnz, false).unwrap(); + system.init_mass_matrix(mass_nnz).unwrap(); system.mass_put(0, 0, 1.0).unwrap(); system.mass_put(0, 1, 1.0).unwrap(); system.mass_put(1, 0, 1.0).unwrap(); @@ -751,7 +751,7 @@ impl Samples { const C2: f64 = 2e-6; const C3: f64 = 3e-6; let mass_nnz = 9; - system.init_mass_matrix(mass_nnz, false).unwrap(); + system.init_mass_matrix(mass_nnz).unwrap(); system.mass_put(0, 0, -C1).unwrap(); system.mass_put(0, 1, C1).unwrap(); system.mass_put(1, 0, C1).unwrap(); @@ -836,7 +836,7 @@ mod tests { // compute the analytical Jacobian matrix let symmetry = Some(system.jac_symmetry); - let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry, false).unwrap(); + let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry).unwrap(); (system.jacobian)(&mut jj, data.x0, &data.y0, multiplier, &mut args).unwrap(); // compute the numerical Jacobian matrix @@ -864,7 +864,7 @@ mod tests { // compute the analytical Jacobian matrix let symmetry = Some(system.jac_symmetry); - let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry, false).unwrap(); + let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry).unwrap(); (system.jacobian)(&mut jj, data.x0, &data.y0, multiplier, &mut args).unwrap(); // compute the numerical Jacobian matrix @@ -892,7 +892,7 @@ mod tests { // compute the analytical Jacobian matrix let symmetry = Some(system.jac_symmetry); - let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry, false).unwrap(); + let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry).unwrap(); (system.jacobian)(&mut jj, data.x0, &data.y0, multiplier, &mut args).unwrap(); // compute the numerical Jacobian matrix @@ -920,7 +920,7 @@ mod tests { // compute the analytical Jacobian matrix let symmetry = Some(system.jac_symmetry); - let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry, false).unwrap(); + let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry).unwrap(); (system.jacobian)(&mut jj, data.x0, &data.y0, multiplier, &mut args).unwrap(); // compute the numerical Jacobian matrix @@ -940,7 +940,7 @@ mod tests { // compute the analytical Jacobian matrix let symmetry = Some(system.jac_symmetry); - let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry, false).unwrap(); + let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry).unwrap(); (system.jacobian)(&mut jj, data.x0, &data.y0, multiplier, &mut args).unwrap(); // compute the numerical Jacobian matrix @@ -960,7 +960,7 @@ mod tests { // compute the analytical Jacobian matrix let symmetry = Some(system.jac_symmetry); - let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry, false).unwrap(); + let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry).unwrap(); (system.jacobian)(&mut jj, data.x0, &data.y0, multiplier, &mut args).unwrap(); // compute the numerical Jacobian matrix @@ -980,7 +980,7 @@ mod tests { // compute the analytical Jacobian matrix let symmetry = Some(system.jac_symmetry); - let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry, false).unwrap(); + let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry).unwrap(); (system.jacobian)(&mut jj, data.x0, &data.y0, multiplier, &mut args).unwrap(); // compute the numerical Jacobian matrix @@ -1000,7 +1000,7 @@ mod tests { // compute the analytical Jacobian matrix let symmetry = Some(system.jac_symmetry); - let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry, false).unwrap(); + let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry).unwrap(); (system.jacobian)(&mut jj, data.x0, &data.y0, multiplier, &mut args).unwrap(); // compute the numerical Jacobian matrix @@ -1020,7 +1020,7 @@ mod tests { // compute the analytical Jacobian matrix let symmetry = Some(system.jac_symmetry); - let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry, false).unwrap(); + let mut jj = CooMatrix::new(system.ndim, system.ndim, system.jac_nnz, symmetry).unwrap(); (system.jacobian)(&mut jj, data.x0, &data.y0, multiplier, &mut args).unwrap(); // compute the numerical Jacobian matrix diff --git a/russell_ode/src/system.rs b/russell_ode/src/system.rs index 54dcb67d..2edd5ed4 100644 --- a/russell_ode/src/system.rs +++ b/russell_ode/src/system.rs @@ -131,15 +131,13 @@ where /// # Input /// /// * `max_nnz` -- Max number of non-zero values - /// * `one_based` -- Flag indicating whether the Sparse matrix can be used with Fortran code (e.g., MUMPS) or not. - /// Make sure that this flag is the same used for the Jacobian matrix. - pub fn init_mass_matrix(&mut self, max_nnz: usize, one_based: bool) -> Result<(), StrError> { + pub fn init_mass_matrix(&mut self, max_nnz: usize) -> Result<(), StrError> { let sym = if self.jac_symmetry == Symmetry::No { None } else { Some(self.jac_symmetry) }; - self.mass_matrix = Some(CooMatrix::new(self.ndim, self.ndim, max_nnz, sym, one_based).unwrap()); + self.mass_matrix = Some(CooMatrix::new(self.ndim, self.ndim, max_nnz, sym).unwrap()); Ok(()) } @@ -253,7 +251,7 @@ mod tests { let mut k = Vector::new(2); (ode.function)(&mut k, x, &y, &mut args).unwrap(); // call jacobian function - let mut jj = CooMatrix::new(2, 2, 2, None, false).unwrap(); + let mut jj = CooMatrix::new(2, 2, 2, None).unwrap(); let m = 1.0; assert_eq!( (ode.jacobian)(&mut jj, x, &y, m, &mut args), @@ -303,7 +301,7 @@ mod tests { // analytical_solution: // y[0] = f64::cos(x * x / 2.0) - 2.0 * f64::sin(x * x / 2.0); // y[1] = 2.0 * f64::cos(x * x / 2.0) + f64::sin(x * x / 2.0); - ode.init_mass_matrix(2, false).unwrap(); // diagonal mass matrix => OK, but not needed + ode.init_mass_matrix(2).unwrap(); // diagonal mass matrix => OK, but not needed ode.mass_put(0, 0, 1.0).unwrap(); ode.mass_put(1, 1, 1.0).unwrap(); // call system function @@ -312,7 +310,7 @@ mod tests { let mut k = Vector::new(2); (ode.function)(&mut k, x, &y, &mut args).unwrap(); // call jacobian function - let mut jj = CooMatrix::new(2, 2, 2, None, false).unwrap(); + let mut jj = CooMatrix::new(2, 2, 2, None).unwrap(); let m = 1.0; (ode.jacobian)(&mut jj, x, &y, m, &mut args).unwrap(); // check diff --git a/russell_sparse/README.md b/russell_sparse/README.md index c1ae9108..0b6ecf5e 100644 --- a/russell_sparse/README.md +++ b/russell_sparse/README.md @@ -75,7 +75,7 @@ fn main() -> Result<(), StrError> { let mut umfpack = SolverUMFPACK::new()?; // allocate the coefficient matrix - let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None, false)?; + let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None)?; coo.put(0, 0, 0.2)?; coo.put(0, 1, 0.2)?; coo.put(1, 0, 0.5)?; diff --git a/russell_sparse/examples/complex_system.rs b/russell_sparse/examples/complex_system.rs index 2d040112..79385a0f 100644 --- a/russell_sparse/examples/complex_system.rs +++ b/russell_sparse/examples/complex_system.rs @@ -43,8 +43,7 @@ fn solve(genie: Genie) -> Result<(), StrError> { let nnz = 16; // number of non-zero values, including duplicates // input matrix in Complex Triplet format - let one_based = genie == Genie::Mumps; - let mut coo = ComplexSparseMatrix::new_coo(ndim, ndim, nnz, None, one_based)?; + let mut coo = ComplexSparseMatrix::new_coo(ndim, ndim, nnz, None)?; // first column coo.put(0, 0, cpx!(19.73, 0.00))?; diff --git a/russell_sparse/examples/doc_coo_from_arrays.rs b/russell_sparse/examples/doc_coo_from_arrays.rs index 16c4fd2a..7a468207 100644 --- a/russell_sparse/examples/doc_coo_from_arrays.rs +++ b/russell_sparse/examples/doc_coo_from_arrays.rs @@ -16,7 +16,7 @@ fn main() -> Result<(), StrError> { 1.0, /*dup*/ 1.0, 3.0, 3.0, -1.0, 4.0, 4.0, -3.0, 1.0, 2.0, 2.0, 6.0, 1.0, ]; let symmetry = None; - let coo = CooMatrix::from(nrow, ncol, row_indices, col_indices, values, symmetry, false)?; + let coo = CooMatrix::from(nrow, ncol, row_indices, col_indices, values, symmetry)?; // covert to dense let a = coo.as_dense(); diff --git a/russell_sparse/examples/doc_coo_new_put_reset.rs b/russell_sparse/examples/doc_coo_new_put_reset.rs index 9bc10d5f..272582bf 100644 --- a/russell_sparse/examples/doc_coo_new_put_reset.rs +++ b/russell_sparse/examples/doc_coo_new_put_reset.rs @@ -8,7 +8,7 @@ fn main() -> Result<(), StrError> { // . -1 -3 2 . // . . 1 . . // . 4 2 . 1 - let mut coo = CooMatrix::new(5, 5, 13, None, true)?; + let mut coo = CooMatrix::new(5, 5, 13, None)?; coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate coo.put(1, 0, 3.0)?; diff --git a/russell_sparse/examples/doc_csc_from_coo.rs b/russell_sparse/examples/doc_csc_from_coo.rs index 5817741e..6911072c 100644 --- a/russell_sparse/examples/doc_csc_from_coo.rs +++ b/russell_sparse/examples/doc_csc_from_coo.rs @@ -9,7 +9,7 @@ fn main() -> Result<(), StrError> { // . . 1 . . // . 4 2 . 1 let (nrow, ncol, nnz) = (5, 5, 13); - let mut coo = CooMatrix::new(nrow, ncol, nnz, None, false)?; + let mut coo = CooMatrix::new(nrow, ncol, nnz, None)?; coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate coo.put(1, 0, 3.0)?; diff --git a/russell_sparse/examples/doc_csr_from_coo.rs b/russell_sparse/examples/doc_csr_from_coo.rs index bb36c195..deaac306 100644 --- a/russell_sparse/examples/doc_csr_from_coo.rs +++ b/russell_sparse/examples/doc_csr_from_coo.rs @@ -9,7 +9,7 @@ fn main() -> Result<(), StrError> { // . . 1 . . // . 4 2 . 1 let (nrow, ncol, nnz) = (5, 5, 13); - let mut coo = CooMatrix::new(nrow, ncol, nnz, None, false)?; + let mut coo = CooMatrix::new(nrow, ncol, nnz, None)?; coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate coo.put(1, 0, 3.0)?; diff --git a/russell_sparse/examples/doc_lin_solver_compute.rs b/russell_sparse/examples/doc_lin_solver_compute.rs index 8c95a79c..0e558a9a 100644 --- a/russell_sparse/examples/doc_lin_solver_compute.rs +++ b/russell_sparse/examples/doc_lin_solver_compute.rs @@ -8,7 +8,7 @@ fn main() -> Result<(), StrError> { let nnz = 5; // number of non-zero values // allocate the coefficient matrix - let mut mat = SparseMatrix::new_coo(ndim, ndim, nnz, None, false)?; + let mut mat = SparseMatrix::new_coo(ndim, ndim, nnz, None)?; mat.put(0, 0, 0.2)?; mat.put(0, 1, 0.2)?; mat.put(1, 0, 0.5)?; diff --git a/russell_sparse/examples/doc_lin_solver_umfpack_tiny.rs b/russell_sparse/examples/doc_lin_solver_umfpack_tiny.rs index 03d65c5f..e9ecbdc8 100644 --- a/russell_sparse/examples/doc_lin_solver_umfpack_tiny.rs +++ b/russell_sparse/examples/doc_lin_solver_umfpack_tiny.rs @@ -11,7 +11,7 @@ fn main() -> Result<(), StrError> { let mut solver = LinSolver::new(Genie::Umfpack)?; // allocate the coefficient matrix - let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None, false)?; + let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None)?; coo.put(0, 0, 0.2)?; coo.put(0, 1, 0.2)?; coo.put(1, 0, 0.5)?; diff --git a/russell_sparse/examples/doc_umfpack_quickstart_coo.rs b/russell_sparse/examples/doc_umfpack_quickstart_coo.rs index 94f38c87..d262b5f4 100644 --- a/russell_sparse/examples/doc_umfpack_quickstart_coo.rs +++ b/russell_sparse/examples/doc_umfpack_quickstart_coo.rs @@ -16,7 +16,7 @@ fn main() -> Result<(), StrError> { // . -1 -3 2 . // . . 1 . . // . 4 2 . 1 - let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None, false)?; + let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None)?; coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate coo.put(1, 0, 3.0)?; diff --git a/russell_sparse/examples/doc_umfpack_tiny.rs b/russell_sparse/examples/doc_umfpack_tiny.rs index 6b97bf46..9271822e 100644 --- a/russell_sparse/examples/doc_umfpack_tiny.rs +++ b/russell_sparse/examples/doc_umfpack_tiny.rs @@ -11,7 +11,7 @@ fn main() -> Result<(), StrError> { let mut umfpack = SolverUMFPACK::new()?; // allocate the coefficient matrix - let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None, false)?; + let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None)?; coo.put(0, 0, 0.2)?; coo.put(0, 1, 0.2)?; coo.put(1, 0, 0.5)?; diff --git a/russell_sparse/examples/mumps_solve_small.rs b/russell_sparse/examples/mumps_solve_small.rs index 82a0153b..90635492 100644 --- a/russell_sparse/examples/mumps_solve_small.rs +++ b/russell_sparse/examples/mumps_solve_small.rs @@ -16,7 +16,7 @@ fn main() -> Result<(), StrError> { // . -1 -3 2 . // . . 1 . . // . 4 2 . 1 - let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None, true)?; + let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None)?; coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate coo.put(1, 0, 3.0)?; diff --git a/russell_sparse/examples/nonlinear_system_4eqs.rs b/russell_sparse/examples/nonlinear_system_4eqs.rs index 54086464..270a9461 100644 --- a/russell_sparse/examples/nonlinear_system_4eqs.rs +++ b/russell_sparse/examples/nonlinear_system_4eqs.rs @@ -29,9 +29,8 @@ fn main() -> Result<(), StrError> { let mut solver = LinSolver::new(genie)?; // allocate Jacobian matrix (J) as SparseMatrix - let one_based = if genie == Genie::Mumps { true } else { false }; let (neq, nnz) = (4, 16); - let mut jj = SparseMatrix::new_coo(neq, neq, nnz, None, one_based).unwrap(); + let mut jj = SparseMatrix::new_coo(neq, neq, nnz, None).unwrap(); // allocate residual (rr), vector of unknowns (uu), and minus-uu (mdu) let mut rr = Vector::new(neq); diff --git a/russell_sparse/src/bin/mem_check.rs b/russell_sparse/src/bin/mem_check.rs index eeb07a2f..6bc776a4 100644 --- a/russell_sparse/src/bin/mem_check.rs +++ b/russell_sparse/src/bin/mem_check.rs @@ -20,8 +20,7 @@ fn test_solver(genie: Genie) { } }; - let one_based = genie == Genie::Mumps; - let (coo, _, _, _) = Samples::umfpack_unsymmetric_5x5(one_based); + let (coo, _, _, _) = Samples::umfpack_unsymmetric_5x5(); let mut mat = SparseMatrix::from_coo(coo); match solver.actual.factorize(&mut mat, None) { @@ -73,7 +72,7 @@ fn test_complex_solver(genie: Genie) { }; let coo = match genie { - Genie::Mumps => Samples::complex_symmetric_3x3_lower(true).0, + Genie::Mumps => Samples::complex_symmetric_3x3_lower().0, Genie::Umfpack => Samples::complex_symmetric_3x3_full().0, Genie::IntelDss => panic!("TODO"), }; @@ -129,8 +128,7 @@ fn test_solver_singular(genie: Genie) { } }; - let one_based = if genie == Genie::Mumps { true } else { false }; - let mut coo_singular = match SparseMatrix::new_coo(ndim, ndim, nnz, None, one_based) { + let mut coo_singular = match SparseMatrix::new_coo(ndim, ndim, nnz, None) { Ok(v) => v, Err(e) => { println!("FAIL(new CooMatrix): {}", e); diff --git a/russell_sparse/src/bin/solve_matrix_market.rs b/russell_sparse/src/bin/solve_matrix_market.rs index 9409954f..de0d2208 100644 --- a/russell_sparse/src/bin/solve_matrix_market.rs +++ b/russell_sparse/src/bin/solve_matrix_market.rs @@ -70,10 +70,10 @@ fn main() -> Result<(), StrError> { let genie = Genie::from(&opt.genie); // select the symmetric handling option - let (handling, one_based) = match genie { - Genie::Mumps => (MMsymOption::LeaveAsLower, true), - Genie::Umfpack => (MMsymOption::MakeItFull, false), - Genie::IntelDss => (MMsymOption::SwapToUpper, false), + let handling = match genie { + Genie::Mumps => MMsymOption::LeaveAsLower, + Genie::Umfpack => MMsymOption::MakeItFull, + Genie::IntelDss => MMsymOption::SwapToUpper, }; // configuration parameters @@ -99,7 +99,7 @@ fn main() -> Result<(), StrError> { // read the matrix let mut sw = Stopwatch::new(); - let coo = read_matrix_market(&opt.matrix_market_file, handling, one_based)?; + let coo = read_matrix_market(&opt.matrix_market_file, handling)?; stats.time_nanoseconds.read_matrix = sw.stop(); // save the COO matrix as a generic SparseMatrix diff --git a/russell_sparse/src/complex_coo_matrix.rs b/russell_sparse/src/complex_coo_matrix.rs index a67102f2..629ae12a 100644 --- a/russell_sparse/src/complex_coo_matrix.rs +++ b/russell_sparse/src/complex_coo_matrix.rs @@ -33,9 +33,6 @@ impl ComplexCooMatrix { if other.symmetry != self.symmetry { return Err("matrices must have the same symmetry"); } - if other.one_based != self.one_based { - return Err("matrices must have the same one_based"); - } self.reset(); for p in 0..other.nnz { let i = other.indices_i[p] as usize; @@ -74,9 +71,6 @@ impl ComplexCooMatrix { if other.symmetry != self.symmetry { return Err("matrices must have the same symmetry"); } - if other.one_based != self.one_based { - return Err("matrices must have the same one_based"); - } for p in 0..other.nnz { let i = other.indices_i[p] as usize; let j = other.indices_j[p] as usize; @@ -99,12 +93,11 @@ mod tests { let sym = Some(Symmetry::General(Storage::Full)); let nnz_a = 1; let nnz_b = 2; // wrong: must be ≤ nnz_a - let mut a_1x2 = ComplexCooMatrix::new(1, 2, nnz_a, None, false).unwrap(); - let b_2x1 = CooMatrix::new(2, 1, nnz_b, None, false).unwrap(); - let b_1x3 = CooMatrix::new(1, 3, nnz_b, None, false).unwrap(); - let b_1x2_sym = CooMatrix::new(1, 2, nnz_b, sym, false).unwrap(); - let b_1x2_one = CooMatrix::new(1, 2, nnz_b, None, true).unwrap(); - let mut b_1x2 = CooMatrix::new(1, 2, nnz_b, None, false).unwrap(); + let mut a_1x2 = ComplexCooMatrix::new(1, 2, nnz_a, None).unwrap(); + let b_2x1 = CooMatrix::new(2, 1, nnz_b, None).unwrap(); + let b_1x3 = CooMatrix::new(1, 3, nnz_b, None).unwrap(); + let b_1x2_sym = CooMatrix::new(1, 2, nnz_b, sym).unwrap(); + let mut b_1x2 = CooMatrix::new(1, 2, nnz_b, None).unwrap(); a_1x2.put(0, 0, cpx!(123.0, 321.0)).unwrap(); b_1x2.put(0, 0, 456.0).unwrap(); b_1x2.put(0, 1, 654.0).unwrap(); @@ -120,10 +113,6 @@ mod tests { a_1x2.assign_real(2.0, 3.0, &b_1x2_sym).err(), Some("matrices must have the same symmetry") ); - assert_eq!( - a_1x2.assign_real(2.0, 3.0, &b_1x2_one).err(), - Some("matrices must have the same one_based") - ); assert_eq!( a_1x2.assign_real(2.0, 3.0, &b_1x2).err(), Some("COO matrix: max number of items has been reached") @@ -133,8 +122,8 @@ mod tests { #[test] fn assign_works() { let nnz = 2; - let mut a = ComplexCooMatrix::new(3, 2, nnz, None, false).unwrap(); - let mut b = CooMatrix::new(3, 2, nnz, None, false).unwrap(); + let mut a = ComplexCooMatrix::new(3, 2, nnz, None).unwrap(); + let mut b = CooMatrix::new(3, 2, nnz, None).unwrap(); a.put(2, 1, cpx!(1000.0, 2000.0)).unwrap(); b.put(0, 0, 10.0).unwrap(); b.put(2, 1, 20.0).unwrap(); @@ -162,12 +151,11 @@ mod tests { let sym = Some(Symmetry::General(Storage::Full)); let nnz_a = 1; let nnz_b = 1; - let mut a_1x2 = ComplexCooMatrix::new(1, 2, nnz_a /* + nnz_b */, None, false).unwrap(); - let b_2x1 = CooMatrix::new(2, 1, nnz_b, None, false).unwrap(); - let b_1x3 = CooMatrix::new(1, 3, nnz_b, None, false).unwrap(); - let b_1x2_sym = CooMatrix::new(1, 2, nnz_b, sym, false).unwrap(); - let b_1x2_one = CooMatrix::new(1, 2, nnz_b, None, true).unwrap(); - let mut b_1x2 = CooMatrix::new(1, 2, nnz_b, None, false).unwrap(); + let mut a_1x2 = ComplexCooMatrix::new(1, 2, nnz_a /* + nnz_b */, None).unwrap(); + let b_2x1 = CooMatrix::new(2, 1, nnz_b, None).unwrap(); + let b_1x3 = CooMatrix::new(1, 3, nnz_b, None).unwrap(); + let b_1x2_sym = CooMatrix::new(1, 2, nnz_b, sym).unwrap(); + let mut b_1x2 = CooMatrix::new(1, 2, nnz_b, None).unwrap(); a_1x2.put(0, 0, cpx!(123.0, 321.0)).unwrap(); b_1x2.put(0, 0, 456.0).unwrap(); assert_eq!( @@ -182,10 +170,6 @@ mod tests { a_1x2.augment_real(2.0, 3.0, &b_1x2_sym).err(), Some("matrices must have the same symmetry") ); - assert_eq!( - a_1x2.augment_real(2.0, 3.0, &b_1x2_one).err(), - Some("matrices must have the same one_based") - ); assert_eq!( a_1x2.augment_real(2.0, 3.0, &b_1x2).err(), Some("COO matrix: max number of items has been reached") @@ -196,8 +180,8 @@ mod tests { fn augment_works() { let nnz_a = 1; let nnz_b = 2; - let mut a = ComplexCooMatrix::new(3, 2, nnz_a + nnz_b, None, false).unwrap(); - let mut b = CooMatrix::new(3, 2, nnz_b, None, false).unwrap(); + let mut a = ComplexCooMatrix::new(3, 2, nnz_a + nnz_b, None).unwrap(); + let mut b = CooMatrix::new(3, 2, nnz_b, None).unwrap(); a.put(2, 1, cpx!(1000.0, 2000.0)).unwrap(); b.put(0, 0, 10.0).unwrap(); b.put(2, 1, 20.0).unwrap(); diff --git a/russell_sparse/src/complex_lin_solver.rs b/russell_sparse/src/complex_lin_solver.rs index 8fcf4f99..2db88d93 100644 --- a/russell_sparse/src/complex_lin_solver.rs +++ b/russell_sparse/src/complex_lin_solver.rs @@ -136,7 +136,7 @@ mod tests { #[test] #[serial] fn complex_lin_solver_compute_works_mumps() { - let (coo, _, _, _) = Samples::complex_symmetric_3x3_lower(true); + let (coo, _, _, _) = Samples::complex_symmetric_3x3_lower(); let mut mat = ComplexSparseMatrix::from_coo(coo); let mut x = ComplexVector::new(3); let rhs = ComplexVector::from(&[cpx!(-3.0, 3.0), cpx!(2.0, -2.0), cpx!(9.0, 7.0)]); diff --git a/russell_sparse/src/complex_solver_mumps.rs b/russell_sparse/src/complex_solver_mumps.rs index 55595108..dd8df0eb 100644 --- a/russell_sparse/src/complex_solver_mumps.rs +++ b/russell_sparse/src/complex_solver_mumps.rs @@ -132,6 +132,12 @@ pub struct ComplexSolverMUMPS { /// Time spent on solve in nanoseconds time_solve_ns: u128, + + /// Holds the (one-based/Fortran) row indices i + fortran_indices_i: Vec, + + /// Holds the (one-based/Fortran) column indices j + fortran_indices_j: Vec, } impl Drop for ComplexSolverMUMPS { @@ -170,6 +176,8 @@ impl ComplexSolverMUMPS { time_initialize_ns: 0, time_factorize_ns: 0, time_solve_ns: 0, + fortran_indices_i: Vec::new(), + fortran_indices_j: Vec::new(), }) } } @@ -201,9 +209,6 @@ impl ComplexLinSolTrait for ComplexSolverMUMPS { let coo = mat.get_coo()?; // check the COO matrix - if !coo.one_based { - return Err("the COO matrix must have one-based (FORTRAN) indices as required by MUMPS"); - } if coo.nrow != coo.ncol { return Err("the COO matrix must be square"); } @@ -226,6 +231,12 @@ impl ComplexLinSolTrait for ComplexSolverMUMPS { self.initialized_symmetry = coo.symmetry; self.initialized_ndim = coo.nrow; self.initialized_nnz = coo.nnz; + self.fortran_indices_i = vec![0; coo.nnz]; + self.fortran_indices_j = vec![0; coo.nnz]; + for k in 0..coo.nnz { + self.fortran_indices_i[k] = coo.indices_i[k] + 1; + self.fortran_indices_j[k] = coo.indices_j[k] + 1; + } } // configuration parameters @@ -279,8 +290,8 @@ impl ComplexLinSolTrait for ComplexSolverMUMPS { positive_definite, ndim, nnz, - coo.indices_i.as_ptr(), - coo.indices_j.as_ptr(), + self.fortran_indices_i.as_ptr(), + self.fortran_indices_j.as_ptr(), coo.values.as_ptr(), ); if status != SUCCESSFUL_EXIT { @@ -468,26 +479,20 @@ mod tests { ); // check COO matrix - let coo = ComplexCooMatrix::new(1, 1, 1, None, false).unwrap(); - let mut mat = ComplexSparseMatrix::from_coo(coo); - assert_eq!( - solver.factorize(&mut mat, None).err(), - Some("the COO matrix must have one-based (FORTRAN) indices as required by MUMPS") - ); - let mut coo = ComplexCooMatrix::new(2, 1, 1, None, true).unwrap(); + let mut coo = ComplexCooMatrix::new(2, 1, 1, None).unwrap(); coo.put(0, 0, cpx!(4.0, 4.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); assert_eq!( solver.factorize(&mut mat, None).err(), Some("the COO matrix must be square") ); - let coo = ComplexCooMatrix::new(1, 1, 1, None, true).unwrap(); + let coo = ComplexCooMatrix::new(1, 1, 1, None).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); assert_eq!( solver.factorize(&mut mat, None).err(), Some("the COO matrix must have at least one non-zero value") ); - let mut coo = ComplexCooMatrix::new(1, 1, 1, Some(Symmetry::General(Storage::Full)), true).unwrap(); + let mut coo = ComplexCooMatrix::new(1, 1, 1, Some(Symmetry::General(Storage::Full))).unwrap(); coo.put(0, 0, cpx!(4.0, 4.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); assert_eq!( @@ -496,14 +501,14 @@ mod tests { ); // check already factorized data - let mut coo = ComplexCooMatrix::new(2, 2, 2, None, true).unwrap(); + let mut coo = ComplexCooMatrix::new(2, 2, 2, None).unwrap(); coo.put(0, 0, cpx!(1.0, 0.0)).unwrap(); coo.put(1, 1, cpx!(2.0, 0.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); // ... factorize once => OK solver.factorize(&mut mat, None).unwrap(); // ... change matrix (symmetry) - let mut coo = ComplexCooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full)), true).unwrap(); + let mut coo = ComplexCooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full))).unwrap(); coo.put(0, 0, cpx!(1.0, 0.0)).unwrap(); coo.put(1, 1, cpx!(2.0, 0.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); @@ -512,7 +517,7 @@ mod tests { Some("subsequent factorizations must use the same matrix (symmetry differs)") ); // ... change matrix (ndim) - let mut coo = ComplexCooMatrix::new(1, 1, 1, None, true).unwrap(); + let mut coo = ComplexCooMatrix::new(1, 1, 1, None).unwrap(); coo.put(0, 0, cpx!(1.0, 0.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); assert_eq!( @@ -520,7 +525,7 @@ mod tests { Some("subsequent factorizations must use the same matrix (ndim differs)") ); // ... change matrix (nnz) - let mut coo = ComplexCooMatrix::new(2, 2, 1, None, true).unwrap(); + let mut coo = ComplexCooMatrix::new(2, 2, 1, None).unwrap(); coo.put(0, 0, cpx!(1.0, 0.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); assert_eq!( @@ -532,7 +537,7 @@ mod tests { #[test] #[serial] fn factorize_fails_on_singular_matrix() { - let mut mat_singular = ComplexSparseMatrix::new_coo(3, 3, 2, None, true).unwrap(); + let mut mat_singular = ComplexSparseMatrix::new_coo(3, 3, 2, None).unwrap(); mat_singular.put(0, 0, cpx!(1.0, 0.0)).unwrap(); mat_singular.put(1, 1, cpx!(1.0, 0.0)).unwrap(); let mut solver = ComplexSolverMUMPS::new().unwrap(); @@ -545,7 +550,7 @@ mod tests { #[test] #[serial] fn solve_handles_errors() { - let mut coo = ComplexCooMatrix::new(2, 2, 2, None, true).unwrap(); + let mut coo = ComplexCooMatrix::new(2, 2, 2, None).unwrap(); coo.put(0, 0, cpx!(123.0, 1.0)).unwrap(); coo.put(1, 1, cpx!(456.0, 2.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); @@ -571,7 +576,7 @@ mod tests { ); // wrong symmetry let rhs = ComplexVector::new(2); - let mut coo_wrong = ComplexCooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full)), true).unwrap(); + let mut coo_wrong = ComplexCooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full))).unwrap(); coo_wrong.put(0, 0, cpx!(123.0, 1.0)).unwrap(); coo_wrong.put(1, 1, cpx!(456.0, 2.0)).unwrap(); let mut mat_wrong = ComplexSparseMatrix::from_coo(coo_wrong); @@ -581,7 +586,7 @@ mod tests { Err("solve must use the same matrix (symmetry differs)") ); // wrong ndim - let mut coo_wrong = ComplexCooMatrix::new(1, 1, 1, None, true).unwrap(); + let mut coo_wrong = ComplexCooMatrix::new(1, 1, 1, None).unwrap(); coo_wrong.put(0, 0, cpx!(123.0, 1.0)).unwrap(); let mut mat_wrong = ComplexSparseMatrix::from_coo(coo_wrong); mat_wrong.get_csc_or_from_coo().unwrap(); // make sure to convert to CSC (because we're not calling factorize on this wrong matrix) @@ -590,7 +595,7 @@ mod tests { Err("solve must use the same matrix (ndim differs)") ); // wrong nnz - let mut coo_wrong = ComplexCooMatrix::new(2, 2, 3, None, true).unwrap(); + let mut coo_wrong = ComplexCooMatrix::new(2, 2, 3, None).unwrap(); coo_wrong.put(0, 0, cpx!(123.0, 1.0)).unwrap(); coo_wrong.put(1, 1, cpx!(456.0, 2.0)).unwrap(); coo_wrong.put(0, 1, cpx!(100.0, 1.0)).unwrap(); @@ -615,7 +620,7 @@ mod tests { assert!(!solver.factorized); // sample matrix - let (coo, _, _, _) = Samples::complex_symmetric_3x3_lower(true); + let (coo, _, _, _) = Samples::complex_symmetric_3x3_lower(); let mut mat = ComplexSparseMatrix::from_coo(coo); // set params @@ -656,7 +661,7 @@ mod tests { let sym = Some(Symmetry::PositiveDefinite(Storage::Lower)); let nrow = 5; let ncol = 5; - let mut coo_pd_lower = ComplexCooMatrix::new(nrow, ncol, 9, sym, true).unwrap(); + let mut coo_pd_lower = ComplexCooMatrix::new(nrow, ncol, 9, sym).unwrap(); coo_pd_lower.put(0, 0, cpx!(9.0, 0.0)).unwrap(); coo_pd_lower.put(1, 1, cpx!(0.5, 0.0)).unwrap(); coo_pd_lower.put(2, 2, cpx!(12.0, 0.0)).unwrap(); diff --git a/russell_sparse/src/complex_solver_umfpack.rs b/russell_sparse/src/complex_solver_umfpack.rs index 52372c8f..535b8d49 100644 --- a/russell_sparse/src/complex_solver_umfpack.rs +++ b/russell_sparse/src/complex_solver_umfpack.rs @@ -427,7 +427,7 @@ mod tests { assert!(!solver.factorized); // COO to CSC errors - let coo = ComplexCooMatrix::new(1, 1, 1, None, false).unwrap(); + let coo = ComplexCooMatrix::new(1, 1, 1, None).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); assert_eq!( solver.factorize(&mut mat, None).err(), @@ -441,7 +441,7 @@ mod tests { solver.factorize(&mut mat, None).err(), Some("the matrix must be square") ); - let (coo, _, _, _) = Samples::complex_symmetric_3x3_lower(false); + let (coo, _, _, _) = Samples::complex_symmetric_3x3_lower(); let mut mat = ComplexSparseMatrix::from_coo(coo); assert_eq!( solver.factorize(&mut mat, None).err(), @@ -449,14 +449,14 @@ mod tests { ); // check already factorized data - let mut coo = ComplexCooMatrix::new(2, 2, 2, None, false).unwrap(); + let mut coo = ComplexCooMatrix::new(2, 2, 2, None).unwrap(); coo.put(0, 0, cpx!(1.0, 0.0)).unwrap(); coo.put(1, 1, cpx!(2.0, 0.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); // ... factorize once => OK solver.factorize(&mut mat, None).unwrap(); // ... change matrix (symmetry) - let mut coo = ComplexCooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full)), false).unwrap(); + let mut coo = ComplexCooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full))).unwrap(); coo.put(0, 0, cpx!(1.0, 0.0)).unwrap(); coo.put(1, 1, cpx!(2.0, 0.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); @@ -465,7 +465,7 @@ mod tests { Some("subsequent factorizations must use the same matrix (symmetry differs)") ); // ... change matrix (ndim) - let mut coo = ComplexCooMatrix::new(1, 1, 1, None, false).unwrap(); + let mut coo = ComplexCooMatrix::new(1, 1, 1, None).unwrap(); coo.put(0, 0, cpx!(1.0, 0.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); assert_eq!( @@ -473,7 +473,7 @@ mod tests { Some("subsequent factorizations must use the same matrix (ndim differs)") ); // ... change matrix (nnz) - let mut coo = ComplexCooMatrix::new(2, 2, 1, None, false).unwrap(); + let mut coo = ComplexCooMatrix::new(2, 2, 1, None).unwrap(); coo.put(0, 0, cpx!(1.0, 0.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); assert_eq!( @@ -514,7 +514,7 @@ mod tests { #[test] fn factorize_fails_on_singular_matrix() { let mut solver = ComplexSolverUMFPACK::new().unwrap(); - let mut coo = ComplexCooMatrix::new(2, 2, 2, None, false).unwrap(); + let mut coo = ComplexCooMatrix::new(2, 2, 2, None).unwrap(); coo.put(0, 0, cpx!(1.0, 0.0)).unwrap(); coo.put(1, 1, cpx!(0.0, 0.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); @@ -523,7 +523,7 @@ mod tests { #[test] fn solve_handles_errors() { - let mut coo = ComplexCooMatrix::new(2, 2, 2, None, false).unwrap(); + let mut coo = ComplexCooMatrix::new(2, 2, 2, None).unwrap(); coo.put(0, 0, cpx!(123.0, 1.0)).unwrap(); coo.put(1, 1, cpx!(456.0, 2.0)).unwrap(); let mut mat = ComplexSparseMatrix::from_coo(coo); @@ -549,7 +549,7 @@ mod tests { ); // wrong symmetry let rhs = ComplexVector::new(2); - let mut coo_wrong = ComplexCooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full)), false).unwrap(); + let mut coo_wrong = ComplexCooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full))).unwrap(); coo_wrong.put(0, 0, cpx!(123.0, 1.0)).unwrap(); coo_wrong.put(1, 1, cpx!(456.0, 2.0)).unwrap(); let mut mat_wrong = ComplexSparseMatrix::from_coo(coo_wrong); @@ -559,7 +559,7 @@ mod tests { Err("solve must use the same matrix (symmetry differs)") ); // wrong ndim - let mut coo_wrong = ComplexCooMatrix::new(1, 1, 1, None, false).unwrap(); + let mut coo_wrong = ComplexCooMatrix::new(1, 1, 1, None).unwrap(); coo_wrong.put(0, 0, cpx!(123.0, 1.0)).unwrap(); let mut mat_wrong = ComplexSparseMatrix::from_coo(coo_wrong); mat_wrong.get_csc_or_from_coo().unwrap(); // make sure to convert to CSC (because we're not calling factorize on this wrong matrix) @@ -568,7 +568,7 @@ mod tests { Err("solve must use the same matrix (ndim differs)") ); // wrong nnz - let mut coo_wrong = ComplexCooMatrix::new(2, 2, 3, None, false).unwrap(); + let mut coo_wrong = ComplexCooMatrix::new(2, 2, 3, None).unwrap(); coo_wrong.put(0, 0, cpx!(123.0, 1.0)).unwrap(); coo_wrong.put(1, 1, cpx!(456.0, 2.0)).unwrap(); coo_wrong.put(0, 1, cpx!(100.0, 1.0)).unwrap(); diff --git a/russell_sparse/src/coo_matrix.rs b/russell_sparse/src/coo_matrix.rs index 37b04743..1fc6c702 100644 --- a/russell_sparse/src/coo_matrix.rs +++ b/russell_sparse/src/coo_matrix.rs @@ -70,12 +70,6 @@ where /// ``` #[serde(bound(deserialize = "Vec: Deserialize<'de>"))] pub(crate) values: Vec, - - /// Defines the use of one-based indexing instead of zero-based (default) - /// - /// This option applies to indices_i and indices_j and enables the use of - /// FORTRAN routines such as the ones implemented by the MUMPS solver. - pub(crate) one_based: bool, } impl NumCooMatrix @@ -91,7 +85,6 @@ where /// * `max_nnz` -- (≥ 1) Maximum number of entries ≥ nnz (number of non-zeros), /// including entries with repeated indices. (must be fit i32) /// * `symmetry` -- Defines the symmetry/storage, if any - /// * `one_based` -- Use one-based indices; e.g., for MUMPS or other FORTRAN routines /// /// # Examples /// @@ -106,7 +99,7 @@ where /// // . -1 -3 2 . /// // . . 1 . . /// // . 4 2 . 1 - /// let mut coo = CooMatrix::new(5, 5, 13, None, true)?; + /// let mut coo = CooMatrix::new(5, 5, 13, None)?; /// coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate /// coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate /// coo.put(1, 0, 3.0)?; @@ -174,13 +167,7 @@ where /// Ok(()) /// } /// ``` - pub fn new( - nrow: usize, - ncol: usize, - max_nnz: usize, - symmetry: Option, - one_based: bool, - ) -> Result { + pub fn new(nrow: usize, ncol: usize, max_nnz: usize, symmetry: Option) -> Result { if nrow < 1 { return Err("nrow must be ≥ 1"); } @@ -199,7 +186,6 @@ where indices_i: vec![0; max_nnz], indices_j: vec![0; max_nnz], values: vec![T::zero(); max_nnz], - one_based, }) } @@ -213,7 +199,6 @@ where /// * `col_indices` -- (len = nnz) Is the array of columns indices /// * `values` -- (len = nnz) Is the array of non-zero values /// * `symmetry` -- Defines the symmetry/storage, if any - /// * `one_based` -- Use one-based indices; e.g., for MUMPS or other FORTRAN routines /// /// # Examples /// @@ -236,7 +221,7 @@ where /// 1.0, /*dup*/ 1.0, 3.0, 3.0, -1.0, 4.0, 4.0, -3.0, 1.0, 2.0, 2.0, 6.0, 1.0, /// ]; /// let symmetry = None; - /// let coo = CooMatrix::from(nrow, ncol, row_indices, col_indices, values, symmetry, false)?; + /// let coo = CooMatrix::from(nrow, ncol, row_indices, col_indices, values, symmetry)?; /// /// // covert to dense /// let a = coo.as_dense(); @@ -258,7 +243,6 @@ where col_indices: Vec, values: Vec, symmetry: Option, - one_based: bool, ) -> Result { if nrow < 1 { return Err("nrow must be ≥ 1"); @@ -276,14 +260,13 @@ where if values.len() != nnz { return Err("values.len() must be = nnz"); } - let d = if one_based { 1 } else { 0 }; let m = to_i32(nrow); let n = to_i32(ncol); for k in 0..nnz { - if row_indices[k] - d < 0 || row_indices[k] - d >= m { + if row_indices[k] < 0 || row_indices[k] >= m { return Err("row index is out-of-range"); } - if col_indices[k] - d < 0 || col_indices[k] - d >= n { + if col_indices[k] < 0 || col_indices[k] >= n { return Err("col index is out-of-range"); } } @@ -296,7 +279,6 @@ where indices_i: row_indices, indices_j: col_indices, values, - one_based, }) } @@ -317,7 +299,7 @@ where /// /// fn main() -> Result<(), StrError> { /// let (nrow, ncol, nnz) = (3, 3, 4); - /// let mut coo = CooMatrix::new(nrow, ncol, nnz, None, false)?; + /// let mut coo = CooMatrix::new(nrow, ncol, nnz, None)?; /// coo.put(0, 0, 1.0)?; /// coo.put(1, 1, 2.0)?; /// coo.put(2, 2, 3.0)?; @@ -358,9 +340,8 @@ where // insert a new entry let i_i32 = to_i32(i); let j_i32 = to_i32(j); - let d = if self.one_based { 1 } else { 0 }; - self.indices_i[self.nnz] = i_i32 + d; - self.indices_j[self.nnz] = j_i32 + d; + self.indices_i[self.nnz] = i_i32; + self.indices_j[self.nnz] = j_i32; self.values[self.nnz] = aij; self.nnz += 1; Ok(()) @@ -378,7 +359,7 @@ where /// /// fn main() -> Result<(), StrError> { /// let (nrow, ncol, max_nnz) = (3, 3, 10); - /// let mut coo = CooMatrix::new(nrow, ncol, max_nnz, None, false)?; + /// let mut coo = CooMatrix::new(nrow, ncol, max_nnz, None)?; /// coo.put(0, 0, 1.0)?; /// coo.put(1, 1, 2.0)?; /// coo.put(2, 2, 3.0)?; @@ -412,7 +393,7 @@ where /// // define (4 x 4) sparse matrix with 6+1 non-zero values /// // (with an extra ij-repeated entry) /// let (nrow, ncol, max_nnz) = (4, 4, 10); - /// let mut coo = CooMatrix::new(nrow, ncol, max_nnz, None, false)?; + /// let mut coo = CooMatrix::new(nrow, ncol, max_nnz, None)?; /// coo.put(0, 0, 0.5)?; // (0, 0, a00/2) << duplicate /// coo.put(0, 0, 0.5)?; // (0, 0, a00/2) << duplicate /// coo.put(0, 1, 2.0)?; @@ -456,7 +437,7 @@ where /// // define (4 x 4) sparse matrix with 6+1 non-zero values /// // (with an extra ij-repeated entry) /// let (nrow, ncol, max_nnz) = (4, 4, 10); - /// let mut coo = CooMatrix::new(nrow, ncol, max_nnz, None, false)?; + /// let mut coo = CooMatrix::new(nrow, ncol, max_nnz, None)?; /// coo.put(0, 0, 0.5)?; // (0, 0, a00/2) << duplicate /// coo.put(0, 0, 0.5)?; // (0, 0, a00/2) << duplicate /// coo.put(0, 1, 2.0)?; @@ -485,10 +466,9 @@ where } let mirror_required = self.symmetry.triangular(); a.fill(T::zero()); - let d = if self.one_based { 1 } else { 0 }; for p in 0..self.nnz { - let i = (self.indices_i[p] - d) as usize; - let j = (self.indices_j[p] - d) as usize; + let i = self.indices_i[p] as usize; + let j = self.indices_j[p] as usize; a.add(i, j, self.values[p]); if mirror_required && i != j { a.add(j, i, self.values[p]); @@ -526,7 +506,7 @@ where /// fn main() -> Result<(), StrError> { /// // set sparse matrix (3 x 3) with 6 non-zeros /// let (nrow, ncol, max_nnz) = (3, 3, 6); - /// let mut coo = CooMatrix::new(nrow, ncol, max_nnz, None, false)?; + /// let mut coo = CooMatrix::new(nrow, ncol, max_nnz, None)?; /// coo.put(0, 0, 1.0)?; /// coo.put(1, 0, 2.0)?; /// coo.put(1, 1, 3.0)?; @@ -567,10 +547,9 @@ where } let mirror_required = self.symmetry.triangular(); v.fill(T::zero()); - let d = if self.one_based { 1 } else { 0 }; for p in 0..self.nnz { - let i = (self.indices_i[p] - d) as usize; - let j = (self.indices_j[p] - d) as usize; + let i = self.indices_i[p] as usize; + let j = self.indices_j[p] as usize; let aij = self.values[p]; v[i] += alpha * aij * u[j]; if mirror_required && i != j { @@ -599,9 +578,6 @@ where if other.symmetry != self.symmetry { return Err("matrices must have the same symmetry"); } - if other.one_based != self.one_based { - return Err("matrices must have the same one_based"); - } self.reset(); for p in 0..other.nnz { let i = other.indices_i[p] as usize; @@ -630,9 +606,6 @@ where if other.symmetry != self.symmetry { return Err("matrices must have the same symmetry"); } - if other.one_based != self.one_based { - return Err("matrices must have the same one_based"); - } for p in 0..other.nnz { let i = other.indices_i[p] as usize; let j = other.indices_j[p] as usize; @@ -652,7 +625,7 @@ where /// use russell_sparse::StrError; /// /// fn main() -> Result<(), StrError> { - /// let coo = CooMatrix::new(1, 2, 3, None, false)?; + /// let coo = CooMatrix::new(1, 2, 3, None)?; /// let (nrow, ncol, nnz, symmetry) = coo.get_info(); /// assert_eq!(nrow, 1); /// assert_eq!(ncol, 2); @@ -725,23 +698,17 @@ mod tests { #[test] fn new_captures_errors() { + assert_eq!(NumCooMatrix::::new(0, 1, 3, None).err(), Some("nrow must be ≥ 1")); + assert_eq!(NumCooMatrix::::new(1, 0, 3, None).err(), Some("ncol must be ≥ 1")); assert_eq!( - NumCooMatrix::::new(0, 1, 3, None, false).err(), - Some("nrow must be ≥ 1") - ); - assert_eq!( - NumCooMatrix::::new(1, 0, 3, None, false).err(), - Some("ncol must be ≥ 1") - ); - assert_eq!( - NumCooMatrix::::new(1, 1, 0, None, false).err(), + NumCooMatrix::::new(1, 1, 0, None).err(), Some("max_nnz must be ≥ 1") ); } #[test] fn new_works() { - let coo = NumCooMatrix::::new(1, 1, 3, None, false).unwrap(); + let coo = NumCooMatrix::::new(1, 1, 3, None).unwrap(); assert_eq!(coo.symmetry, Symmetry::No); assert_eq!(coo.nrow, 1); assert_eq!(coo.ncol, 1); @@ -755,40 +722,36 @@ mod tests { #[test] #[rustfmt::skip] fn from_captures_errors(){ - assert_eq!(NumCooMatrix::::from(0, 1, vec![ 0], vec![ 0], vec![0.0], None, false).err(), Some("nrow must be ≥ 1")); - assert_eq!(NumCooMatrix::::from(1, 0, vec![ 0], vec![ 0], vec![0.0], None, false).err(), Some("ncol must be ≥ 1")); - assert_eq!(NumCooMatrix::::from(1, 1, vec![ ], vec![ 0], vec![0.0], None, false).err(), Some("nnz must be ≥ 1")); - assert_eq!(NumCooMatrix::::from(1, 1, vec![ 0], vec![ ], vec![0.0], None, false).err(), Some("col_indices.len() must be = nnz")); - assert_eq!(NumCooMatrix::::from(1, 1, vec![ 0], vec![ 0], vec![ ], None, false).err(), Some("values.len() must be = nnz")); - assert_eq!(NumCooMatrix::::from(1, 1, vec![-1], vec![ 0], vec![0.0], None, false).err(), Some("row index is out-of-range")); - assert_eq!(NumCooMatrix::::from(1, 1, vec![ 1], vec![ 0], vec![0.0], None, false).err(), Some("row index is out-of-range")); - assert_eq!(NumCooMatrix::::from(1, 1, vec![ 0], vec![-1], vec![0.0], None, false).err(), Some("col index is out-of-range")); - assert_eq!(NumCooMatrix::::from(1, 1, vec![ 0], vec![ 1], vec![0.0], None, false).err(), Some("col index is out-of-range")); - assert_eq!(NumCooMatrix::::from(1, 1, vec![ 0], vec![ 1], vec![0.0], None, true).err(), Some("row index is out-of-range")); - assert_eq!(NumCooMatrix::::from(1, 1, vec![ 2], vec![ 1], vec![0.0], None, true).err(), Some("row index is out-of-range")); - assert_eq!(NumCooMatrix::::from(1, 1, vec![ 1], vec![ 0], vec![0.0], None, true).err(), Some("col index is out-of-range")); - assert_eq!(NumCooMatrix::::from(1, 1, vec![ 1], vec![ 2], vec![0.0], None, true).err(), Some("col index is out-of-range")); + assert_eq!(NumCooMatrix::::from(0, 1, vec![ 0], vec![ 0], vec![0.0], None).err(), Some("nrow must be ≥ 1")); + assert_eq!(NumCooMatrix::::from(1, 0, vec![ 0], vec![ 0], vec![0.0], None).err(), Some("ncol must be ≥ 1")); + assert_eq!(NumCooMatrix::::from(1, 1, vec![ ], vec![ 0], vec![0.0], None).err(), Some("nnz must be ≥ 1")); + assert_eq!(NumCooMatrix::::from(1, 1, vec![ 0], vec![ ], vec![0.0], None).err(), Some("col_indices.len() must be = nnz")); + assert_eq!(NumCooMatrix::::from(1, 1, vec![ 0], vec![ 0], vec![ ], None).err(), Some("values.len() must be = nnz")); + assert_eq!(NumCooMatrix::::from(1, 1, vec![-1], vec![ 0], vec![0.0], None).err(), Some("row index is out-of-range")); + assert_eq!(NumCooMatrix::::from(1, 1, vec![ 1], vec![ 0], vec![0.0], None).err(), Some("row index is out-of-range")); + assert_eq!(NumCooMatrix::::from(1, 1, vec![ 0], vec![-1], vec![0.0], None).err(), Some("col index is out-of-range")); + assert_eq!(NumCooMatrix::::from(1, 1, vec![ 0], vec![ 1], vec![0.0], None).err(), Some("col index is out-of-range")); } #[test] fn from_works() { - let coo = NumCooMatrix::::from(1, 1, vec![1], vec![1], vec![123.0], None, true).unwrap(); + let coo = NumCooMatrix::::from(1, 1, vec![0], vec![0], vec![123.0], None).unwrap(); assert_eq!(coo.symmetry, Symmetry::No); assert_eq!(coo.nrow, 1); assert_eq!(coo.ncol, 1); assert_eq!(coo.nnz, 1); assert_eq!(coo.max_nnz, 1); - assert_eq!(coo.indices_i, &[1]); - assert_eq!(coo.indices_j, &[1]); + assert_eq!(coo.indices_i, &[0]); + assert_eq!(coo.indices_j, &[0]); assert_eq!(coo.values, &[123.0]); let sym = Some(Symmetry::new_general_full()); - let coo = NumCooMatrix::::from(1, 1, vec![1], vec![1], vec![123.0], sym, true).unwrap(); + let coo = NumCooMatrix::::from(1, 1, vec![0], vec![0], vec![123.0], sym).unwrap(); assert_eq!(coo.symmetry, Symmetry::General(Storage::Full)); } #[test] fn get_info_works() { - let coo = NumCooMatrix::::new(1, 2, 10, None, false).unwrap(); + let coo = NumCooMatrix::::new(1, 2, 10, None).unwrap(); let (nrow, ncol, nnz, symmetry) = coo.get_info(); assert_eq!(nrow, 1); assert_eq!(ncol, 2); @@ -798,7 +761,7 @@ mod tests { #[test] fn put_fails_on_wrong_values() { - let mut coo = NumCooMatrix::::new(1, 1, 1, None, false).unwrap(); + let mut coo = NumCooMatrix::::new(1, 1, 1, None).unwrap(); assert_eq!( coo.put(1, 0, 0).err(), Some("COO matrix: index of row is outside range") @@ -813,13 +776,13 @@ mod tests { Some("COO matrix: max number of items has been reached") ); let sym = Some(Symmetry::General(Storage::Lower)); - let mut coo = NumCooMatrix::::new(2, 2, 4, sym, false).unwrap(); + let mut coo = NumCooMatrix::::new(2, 2, 4, sym).unwrap(); assert_eq!( coo.put(0, 1, 0).err(), Some("COO matrix: j > i is incorrect for lower triangular storage") ); let sym = Some(Symmetry::General(Storage::Upper)); - let mut coo = NumCooMatrix::::new(2, 2, 4, sym, false).unwrap(); + let mut coo = NumCooMatrix::::new(2, 2, 4, sym).unwrap(); assert_eq!( coo.put(1, 0, 0).err(), Some("COO matrix: j < i is incorrect for upper triangular storage") @@ -828,7 +791,7 @@ mod tests { #[test] fn put_works() { - let mut coo = NumCooMatrix::::new(3, 3, 5, None, false).unwrap(); + let mut coo = NumCooMatrix::::new(3, 3, 5, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); assert_eq!(coo.nnz, 1); coo.put(0, 1, 2.0).unwrap(); @@ -843,7 +806,7 @@ mod tests { #[test] fn reset_works() { - let mut coo = NumCooMatrix::::new(2, 2, 4, None, false).unwrap(); + let mut coo = NumCooMatrix::::new(2, 2, 4, None).unwrap(); assert_eq!(coo.nnz, 0); coo.put(0, 0, 1.0).unwrap(); coo.put(0, 1, 4.0).unwrap(); @@ -856,7 +819,7 @@ mod tests { #[test] fn to_dense_fails_on_wrong_dims() { - let mut coo = NumCooMatrix::::new(1, 1, 1, None, false).unwrap(); + let mut coo = NumCooMatrix::::new(1, 1, 1, None).unwrap(); coo.put(0, 0, 123.0).unwrap(); let mut a_2x1 = NumMatrix::::new(2, 1); let mut a_1x2 = NumMatrix::::new(1, 2); @@ -866,7 +829,7 @@ mod tests { #[test] fn to_dense_works() { - let mut coo = NumCooMatrix::::new(3, 3, 5, None, false).unwrap(); + let mut coo = NumCooMatrix::::new(3, 3, 5, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); coo.put(0, 1, 2.0).unwrap(); coo.put(1, 0, 3.0).unwrap(); @@ -891,11 +854,11 @@ mod tests { assert_eq!(bb.get(0, 0), 1.0); assert_eq!(bb.get(1, 0), 3.0); // empty matrix - let empty = NumCooMatrix::::new(2, 2, 3, None, false).unwrap(); + let empty = NumCooMatrix::::new(2, 2, 3, None).unwrap(); let mat = empty.as_dense(); assert_eq!(mat.as_data(), &[0.0, 0.0, 0.0, 0.0]); // single component matrix - let mut single = NumCooMatrix::::new(1, 1, 1, None, false).unwrap(); + let mut single = NumCooMatrix::::new(1, 1, 1, None).unwrap(); single.put(0, 0, 123.0).unwrap(); let mat = single.as_dense(); assert_eq!(mat.as_data(), &[123.0]); @@ -905,7 +868,7 @@ mod tests { fn to_dense_with_duplicates_works() { // allocate a square matrix let (nrow, ncol, nnz) = (5, 5, 13); - let mut coo = NumCooMatrix::::new(nrow, ncol, nnz, None, false).unwrap(); + let mut coo = NumCooMatrix::::new(nrow, ncol, nnz, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); // << (0, 0, a00/2) coo.put(0, 0, 1.0).unwrap(); // << (0, 0, a00/2) coo.put(1, 0, 3.0).unwrap(); @@ -936,7 +899,7 @@ mod tests { #[test] fn to_dense_symmetric_lower_works() { let sym = Some(Symmetry::General(Storage::Lower)); - let mut coo = NumCooMatrix::::new(3, 3, 4, sym, false).unwrap(); + let mut coo = NumCooMatrix::::new(3, 3, 4, sym).unwrap(); coo.put(0, 0, 1.0).unwrap(); coo.put(1, 0, 2.0).unwrap(); coo.put(1, 1, 3.0).unwrap(); @@ -952,9 +915,9 @@ mod tests { } #[test] - fn to_dense_symmetric_upper_and_one_based_works() { + fn to_dense_symmetric_upper_works() { let sym = Some(Symmetry::General(Storage::Upper)); - let mut coo = NumCooMatrix::::new(3, 3, 4, sym, true).unwrap(); + let mut coo = NumCooMatrix::::new(3, 3, 4, sym).unwrap(); coo.put(0, 0, 1.0).unwrap(); coo.put(0, 1, 2.0).unwrap(); coo.put(1, 1, 3.0).unwrap(); @@ -971,7 +934,7 @@ mod tests { #[test] fn mat_vec_mul_captures_errors() { - let mut coo = NumCooMatrix::::new(2, 2, 1, None, false).unwrap(); + let mut coo = NumCooMatrix::::new(2, 2, 1, None).unwrap(); coo.put(0, 0, 123).unwrap(); let u = NumVector::::new(3); let mut v = NumVector::::new(coo.nrow); @@ -986,7 +949,7 @@ mod tests { // 1.0 2.0 3.0 // 0.1 0.2 0.3 // 10.0 20.0 30.0 - let mut coo = NumCooMatrix::::new(3, 3, 9, None, false).unwrap(); + let mut coo = NumCooMatrix::::new(3, 3, 9, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); coo.put(0, 1, 2.0).unwrap(); coo.put(0, 2, 3.0).unwrap(); @@ -1006,23 +969,8 @@ mod tests { coo.mat_vec_mul(&mut v, 2.0, &u).unwrap(); vec_approx_eq(v.as_data(), correct_v, 1e-15); - // one-based indexing - let mut coo = NumCooMatrix::::new(3, 3, 9, None, true).unwrap(); - coo.put(0, 0, 1.0).unwrap(); - coo.put(0, 1, 2.0).unwrap(); - coo.put(0, 2, 3.0).unwrap(); - coo.put(1, 0, 0.1).unwrap(); - coo.put(1, 1, 0.2).unwrap(); - coo.put(1, 2, 0.3).unwrap(); - coo.put(2, 0, 10.0).unwrap(); - coo.put(2, 1, 20.0).unwrap(); - coo.put(2, 2, 30.0).unwrap(); - coo.mat_vec_mul(&mut v, 2.0, &u).unwrap(); - let correct_v = &[2.8, 0.28, 28.0]; - vec_approx_eq(v.as_data(), correct_v, 1e-15); - // single component matrix - let mut single = NumCooMatrix::::new(1, 1, 1, None, false).unwrap(); + let mut single = NumCooMatrix::::new(1, 1, 1, None).unwrap(); single.put(0, 0, 123.0).unwrap(); let u = NumVector::from(&[2.0]); let mut v = NumVector::::new(1); @@ -1039,7 +987,7 @@ mod tests { // 2 1 5 1 8 let (nrow, ncol, nnz) = (5, 5, 15); let sym = Some(Symmetry::General(Storage::Lower)); - let mut coo = NumCooMatrix::::new(nrow, ncol, nnz, sym, false).unwrap(); + let mut coo = NumCooMatrix::::new(nrow, ncol, nnz, sym).unwrap(); coo.put(0, 0, 2.0).unwrap(); coo.put(1, 1, 2.0).unwrap(); coo.put(2, 2, 9.0).unwrap(); @@ -1075,7 +1023,7 @@ mod tests { // 2 1 5 1 8 let (nrow, ncol, nnz) = (5, 5, 25); let sym = Some(Symmetry::General(Storage::Full)); - let mut coo = NumCooMatrix::::new(nrow, ncol, nnz, sym, false).unwrap(); + let mut coo = NumCooMatrix::::new(nrow, ncol, nnz, sym).unwrap(); coo.put(0, 0, 2.0).unwrap(); coo.put(1, 1, 2.0).unwrap(); coo.put(2, 2, 9.0).unwrap(); @@ -1119,7 +1067,7 @@ mod tests { // -1 2 -1 2 let (nrow, ncol, nnz) = (3, 3, 5); let sym = Some(Symmetry::PositiveDefinite(Storage::Lower)); - let mut coo = NumCooMatrix::::new(nrow, ncol, nnz, sym, false).unwrap(); + let mut coo = NumCooMatrix::::new(nrow, ncol, nnz, sym).unwrap(); coo.put(0, 0, 2.0).unwrap(); coo.put(1, 1, 2.0).unwrap(); coo.put(2, 2, 2.0).unwrap(); @@ -1159,12 +1107,11 @@ mod tests { let sym = Some(Symmetry::General(Storage::Full)); let nnz_a = 1; let nnz_b = 2; // wrong: must be ≤ nnz_a - let mut a_1x2 = NumCooMatrix::::new(1, 2, nnz_a, None, false).unwrap(); - let b_2x1 = NumCooMatrix::::new(2, 1, nnz_b, None, false).unwrap(); - let b_1x3 = NumCooMatrix::::new(1, 3, nnz_b, None, false).unwrap(); - let b_1x2_sym = NumCooMatrix::::new(1, 2, nnz_b, sym, false).unwrap(); - let b_1x2_one = NumCooMatrix::::new(1, 2, nnz_b, None, true).unwrap(); - let mut b_1x2 = NumCooMatrix::::new(1, 2, nnz_b, None, false).unwrap(); + let mut a_1x2 = NumCooMatrix::::new(1, 2, nnz_a, None).unwrap(); + let b_2x1 = NumCooMatrix::::new(2, 1, nnz_b, None).unwrap(); + let b_1x3 = NumCooMatrix::::new(1, 3, nnz_b, None).unwrap(); + let b_1x2_sym = NumCooMatrix::::new(1, 2, nnz_b, sym).unwrap(); + let mut b_1x2 = NumCooMatrix::::new(1, 2, nnz_b, None).unwrap(); a_1x2.put(0, 0, 123).unwrap(); b_1x2.put(0, 0, 456).unwrap(); b_1x2.put(0, 1, 654).unwrap(); @@ -1174,10 +1121,6 @@ mod tests { a_1x2.assign(2, &b_1x2_sym).err(), Some("matrices must have the same symmetry") ); - assert_eq!( - a_1x2.assign(2, &b_1x2_one).err(), - Some("matrices must have the same one_based") - ); assert_eq!( a_1x2.assign(2, &b_1x2).err(), Some("COO matrix: max number of items has been reached") @@ -1187,8 +1130,8 @@ mod tests { #[test] fn assign_works() { let nnz = 2; - let mut a = NumCooMatrix::::new(3, 2, nnz, None, false).unwrap(); - let mut b = NumCooMatrix::::new(3, 2, nnz, None, false).unwrap(); + let mut a = NumCooMatrix::::new(3, 2, nnz, None).unwrap(); + let mut b = NumCooMatrix::::new(3, 2, nnz, None).unwrap(); a.put(2, 1, 1000.0).unwrap(); b.put(0, 0, 10.0).unwrap(); b.put(2, 1, 20.0).unwrap(); @@ -1216,12 +1159,11 @@ mod tests { let sym = Some(Symmetry::General(Storage::Full)); let nnz_a = 1; let nnz_b = 1; - let mut a_1x2 = NumCooMatrix::::new(1, 2, nnz_a /* + nnz_b */, None, false).unwrap(); - let b_2x1 = NumCooMatrix::::new(2, 1, nnz_b, None, false).unwrap(); - let b_1x3 = NumCooMatrix::::new(1, 3, nnz_b, None, false).unwrap(); - let b_1x2_sym = NumCooMatrix::::new(1, 2, nnz_b, sym, false).unwrap(); - let b_1x2_one = NumCooMatrix::::new(1, 2, nnz_b, None, true).unwrap(); - let mut b_1x2 = NumCooMatrix::::new(1, 2, nnz_b, None, false).unwrap(); + let mut a_1x2 = NumCooMatrix::::new(1, 2, nnz_a /* + nnz_b */, None).unwrap(); + let b_2x1 = NumCooMatrix::::new(2, 1, nnz_b, None).unwrap(); + let b_1x3 = NumCooMatrix::::new(1, 3, nnz_b, None).unwrap(); + let b_1x2_sym = NumCooMatrix::::new(1, 2, nnz_b, sym).unwrap(); + let mut b_1x2 = NumCooMatrix::::new(1, 2, nnz_b, None).unwrap(); a_1x2.put(0, 0, 123).unwrap(); b_1x2.put(0, 0, 456).unwrap(); assert_eq!(a_1x2.augment(2, &b_2x1).err(), Some("matrices must have the same nrow")); @@ -1230,10 +1172,6 @@ mod tests { a_1x2.augment(2, &b_1x2_sym).err(), Some("matrices must have the same symmetry") ); - assert_eq!( - a_1x2.augment(2, &b_1x2_one).err(), - Some("matrices must have the same one_based") - ); assert_eq!( a_1x2.augment(2, &b_1x2).err(), Some("COO matrix: max number of items has been reached") @@ -1244,8 +1182,8 @@ mod tests { fn augment_works() { let nnz_a = 1; let nnz_b = 2; - let mut a = NumCooMatrix::::new(3, 2, nnz_a + nnz_b, None, false).unwrap(); - let mut b = NumCooMatrix::::new(3, 2, nnz_b, None, false).unwrap(); + let mut a = NumCooMatrix::::new(3, 2, nnz_a + nnz_b, None).unwrap(); + let mut b = NumCooMatrix::::new(3, 2, nnz_b, None).unwrap(); a.put(2, 1, 1000.0).unwrap(); b.put(0, 0, 10.0).unwrap(); b.put(2, 1, 20.0).unwrap(); @@ -1270,7 +1208,7 @@ mod tests { #[test] fn getters_are_correct() { - let (coo, _, _, _) = Samples::rectangular_1x2(false, false, false); + let (coo, _, _, _) = Samples::rectangular_1x2(false, false); assert_eq!(coo.get_info(), (1, 2, 2, Symmetry::No)); assert_eq!(coo.get_storage(), Storage::Full); assert_eq!(coo.get_symmetric(), false); @@ -1279,10 +1217,10 @@ mod tests { assert_eq!(coo.get_values(), &[10.0, 20.0]); let sym = Some(Symmetry::new_general_full()); - let coo = NumCooMatrix::::new(2, 2, 2, sym, false).unwrap(); + let coo = NumCooMatrix::::new(2, 2, 2, sym).unwrap(); assert_eq!(coo.get_symmetric(), true); - let mut coo = NumCooMatrix::::new(2, 1, 2, None, false).unwrap(); + let mut coo = NumCooMatrix::::new(2, 1, 2, None).unwrap(); coo.put(0, 0, 123.0).unwrap(); coo.put(1, 0, 456.0).unwrap(); assert_eq!(coo.get_values_mut(), &[123.0, 456.0]); @@ -1293,7 +1231,7 @@ mod tests { #[test] fn derive_methods_work() { - let (coo, _, _, _) = Samples::tiny_1x1(false); + let (coo, _, _, _) = Samples::tiny_1x1(); let mut clone = coo.clone(); clone.values[0] *= 2.0; assert_eq!(coo.values[0], 123.0); @@ -1302,7 +1240,7 @@ mod tests { let json = serde_json::to_string(&coo).unwrap(); assert_eq!( json, - r#"{"symmetry":"No","nrow":1,"ncol":1,"nnz":1,"max_nnz":1,"indices_i":[0],"indices_j":[0],"values":[123.0],"one_based":false}"# + r#"{"symmetry":"No","nrow":1,"ncol":1,"nnz":1,"max_nnz":1,"indices_i":[0],"indices_j":[0],"values":[123.0]}"# ); let from_json: NumCooMatrix = serde_json::from_str(&json).unwrap(); assert_eq!(from_json.symmetry, coo.symmetry); @@ -1313,6 +1251,5 @@ mod tests { assert_eq!(from_json.indices_i, coo.indices_i); assert_eq!(from_json.indices_j, coo.indices_j); assert_eq!(from_json.values, coo.values); - assert_eq!(from_json.one_based, coo.one_based); } } diff --git a/russell_sparse/src/csc_matrix.rs b/russell_sparse/src/csc_matrix.rs index 88d11630..f2b1e849 100644 --- a/russell_sparse/src/csc_matrix.rs +++ b/russell_sparse/src/csc_matrix.rs @@ -275,7 +275,7 @@ where /// // . . 1 . . /// // . 4 2 . 1 /// let (nrow, ncol, nnz) = (5, 5, 13); - /// let mut coo = CooMatrix::new(nrow, ncol, nnz, None, false)?; + /// let mut coo = CooMatrix::new(nrow, ncol, nnz, None)?; /// coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate /// coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate /// coo.put(1, 0, 3.0)?; @@ -374,7 +374,6 @@ where let ncol = coo.ncol; let nnz = coo.nnz; let ndim = usize::max(nrow, ncol); - let d = if coo.one_based { -1 } else { 0 }; // access the triplet data let ai = &coo.indices_i; @@ -407,7 +406,7 @@ where // count the entries in each row (also counting duplicates) // use w as workspace for row counts (including duplicates) for k in 0..nnz { - let i = (ai[k] + d) as usize; + let i = ai[k] as usize; w[i] += 1; } @@ -420,9 +419,9 @@ where // construct the row form (with unsorted values) for k in 0..nnz { - let i = (ai[k] + d) as usize; + let i = ai[k] as usize; let p = w[i] as usize; - rj[p] = aj[k] + d; + rj[p] = aj[k]; rx[p] = ax[k]; w[i] += 1; // w[i] is advanced to the start of row i+1 } @@ -903,7 +902,7 @@ mod tests { #[test] fn new_works() { - let (_, csc_correct, _, _) = Samples::rectangular_1x2(false, false, false); + let (_, csc_correct, _, _) = Samples::rectangular_1x2(false, false); let csc = NumCscMatrix::::new(1, 2, vec![0, 1, 2], vec![0, 0], vec![10.0, 20.0], None).unwrap(); assert_eq!(csc.symmetry, Symmetry::No); assert_eq!(csc.nrow, 1); @@ -915,7 +914,7 @@ mod tests { #[test] fn from_coo_captures_errors() { - let coo = CooMatrix::new(1, 1, 1, None, false).unwrap(); + let coo = CooMatrix::new(1, 1, 1, None).unwrap(); assert_eq!( NumCscMatrix::::from_coo(&coo).err(), Some("COO to CSC requires nnz > 0") @@ -928,84 +927,58 @@ mod tests { // ┌ ┐ // │ 123 │ // └ ┘ - Samples::tiny_1x1(false), - Samples::tiny_1x1(true), + Samples::tiny_1x1(), // 1 . 2 // . 0 3 // 4 5 6 - Samples::unsymmetric_3x3(false, false, false), - Samples::unsymmetric_3x3(false, true, false), - Samples::unsymmetric_3x3(false, false, true), - Samples::unsymmetric_3x3(false, true, true), - Samples::unsymmetric_3x3(true, false, false), - Samples::unsymmetric_3x3(true, true, false), - Samples::unsymmetric_3x3(true, false, true), - Samples::unsymmetric_3x3(true, true, true), + Samples::unsymmetric_3x3(false, false), + Samples::unsymmetric_3x3(false, true), + Samples::unsymmetric_3x3(true, false), + Samples::unsymmetric_3x3(true, true), // 2 3 . . . // 3 . 4 . 6 // . -1 -3 2 . // . . 1 . . // . 4 2 . 1 - Samples::umfpack_unsymmetric_5x5(false), - Samples::umfpack_unsymmetric_5x5(true), + Samples::umfpack_unsymmetric_5x5(), // 1 -1 . -3 . // -2 5 . . . // . . 4 6 4 // -4 . 2 7 . // . 8 . . -5 - Samples::mkl_unsymmetric_5x5(false), - Samples::mkl_unsymmetric_5x5(true), + Samples::mkl_unsymmetric_5x5(), // 1 2 . . . // 3 4 . . . // . . 5 6 . // . . 7 8 . // . . . . 9 - Samples::block_unsymmetric_5x5(false, false, false), - Samples::block_unsymmetric_5x5(false, true, false), - Samples::block_unsymmetric_5x5(false, false, true), - Samples::block_unsymmetric_5x5(false, true, true), - Samples::block_unsymmetric_5x5(true, false, false), - Samples::block_unsymmetric_5x5(true, true, false), - Samples::block_unsymmetric_5x5(true, false, true), - Samples::block_unsymmetric_5x5(true, true, true), + Samples::block_unsymmetric_5x5(false, false), + Samples::block_unsymmetric_5x5(false, true), + Samples::block_unsymmetric_5x5(true, false), + Samples::block_unsymmetric_5x5(true, true), // 9 1.5 6 0.75 3 // 1.5 0.5 . . . // 6 . 12 . . // 0.75 . . 0.625 . // 3 . . . 16 - Samples::mkl_positive_definite_5x5_lower(false), - Samples::mkl_positive_definite_5x5_lower(true), - Samples::mkl_positive_definite_5x5_upper(false), - Samples::mkl_positive_definite_5x5_upper(true), - Samples::mkl_symmetric_5x5_lower(false, false, false), - Samples::mkl_symmetric_5x5_lower(false, true, false), - Samples::mkl_symmetric_5x5_lower(false, false, true), - Samples::mkl_symmetric_5x5_lower(false, true, true), - Samples::mkl_symmetric_5x5_lower(true, false, false), - Samples::mkl_symmetric_5x5_lower(true, true, false), - Samples::mkl_symmetric_5x5_lower(true, false, true), - Samples::mkl_symmetric_5x5_lower(true, true, true), - Samples::mkl_symmetric_5x5_upper(false, false, false), - Samples::mkl_symmetric_5x5_upper(false, true, false), - Samples::mkl_symmetric_5x5_upper(false, false, true), - Samples::mkl_symmetric_5x5_upper(false, true, true), - Samples::mkl_symmetric_5x5_upper(true, false, false), - Samples::mkl_symmetric_5x5_upper(true, true, false), - Samples::mkl_symmetric_5x5_upper(true, false, true), - Samples::mkl_symmetric_5x5_upper(true, true, true), - Samples::mkl_symmetric_5x5_full(false), - Samples::mkl_symmetric_5x5_full(true), + Samples::mkl_positive_definite_5x5_lower(), + Samples::mkl_positive_definite_5x5_upper(), + Samples::mkl_symmetric_5x5_lower(false, false), + Samples::mkl_symmetric_5x5_lower(false, true), + Samples::mkl_symmetric_5x5_lower(true, false), + Samples::mkl_symmetric_5x5_lower(true, true), + Samples::mkl_symmetric_5x5_upper(false, false), + Samples::mkl_symmetric_5x5_upper(false, true), + Samples::mkl_symmetric_5x5_upper(true, false), + Samples::mkl_symmetric_5x5_upper(true, true), + Samples::mkl_symmetric_5x5_full(), // ┌ ┐ // │ 10 20 │ // └ ┘ - Samples::rectangular_1x2(false, false, false), - Samples::rectangular_1x2(false, true, false), - Samples::rectangular_1x2(false, false, true), - Samples::rectangular_1x2(false, true, true), - Samples::rectangular_1x2(true, false, false), - Samples::rectangular_1x2(true, true, false), - Samples::rectangular_1x2(true, false, true), - Samples::rectangular_1x2(true, true, true), + Samples::rectangular_1x2(false, false), + Samples::rectangular_1x2(false, true), + Samples::rectangular_1x2(true, false), + Samples::rectangular_1x2(true, true), // ┌ ┐ // │ 1 . 3 . 5 . 7 │ // └ ┘ @@ -1036,19 +1009,19 @@ mod tests { #[test] #[rustfmt::skip] fn update_from_coo_captures_errors() { - let (coo, _, _, _) = Samples::rectangular_1x2(false, false, false); + let (coo, _, _, _) = Samples::rectangular_1x2(false, false, ); let mut csc = NumCscMatrix::::from_coo(&coo).unwrap(); let yes = Symmetry::General(Storage::Lower); let no = Symmetry::No; - assert_eq!(csc.update_from_coo(&CooMatrix { symmetry: yes, nrow: 1, ncol: 2, nnz: 1, max_nnz: 1, indices_i: vec![0], indices_j: vec![0], values: vec![0.0], one_based: false }).err(), Some("coo.symmetry must be equal to csc.symmetry")); - assert_eq!(csc.update_from_coo(&CooMatrix { symmetry: no, nrow: 2, ncol: 2, nnz: 1, max_nnz: 1, indices_i: vec![0], indices_j: vec![0], values: vec![0.0], one_based: false }).err(), Some("coo.nrow must be equal to csc.nrow")); - assert_eq!(csc.update_from_coo(&CooMatrix { symmetry: no, nrow: 1, ncol: 1, nnz: 1, max_nnz: 1, indices_i: vec![0], indices_j: vec![0], values: vec![0.0], one_based: false }).err(), Some("coo.ncol must be equal to csc.ncol")); - assert_eq!(csc.update_from_coo(&CooMatrix { symmetry: no, nrow: 1, ncol: 2, nnz: 3, max_nnz: 3, indices_i: vec![0,0,0], indices_j: vec![0,0,0], values: vec![0.0,0.0,0.0], one_based: false }).err(), Some("coo.nnz must be equal to nnz(dup) = csc.row_indices.len() = csc.values.len()")); + assert_eq!(csc.update_from_coo(&CooMatrix { symmetry: yes, nrow: 1, ncol: 2, nnz: 1, max_nnz: 1, indices_i: vec![0], indices_j: vec![0], values: vec![0.0] }).err(), Some("coo.symmetry must be equal to csc.symmetry")); + assert_eq!(csc.update_from_coo(&CooMatrix { symmetry: no, nrow: 2, ncol: 2, nnz: 1, max_nnz: 1, indices_i: vec![0], indices_j: vec![0], values: vec![0.0] }).err(), Some("coo.nrow must be equal to csc.nrow")); + assert_eq!(csc.update_from_coo(&CooMatrix { symmetry: no, nrow: 1, ncol: 1, nnz: 1, max_nnz: 1, indices_i: vec![0], indices_j: vec![0], values: vec![0.0] }).err(), Some("coo.ncol must be equal to csc.ncol")); + assert_eq!(csc.update_from_coo(&CooMatrix { symmetry: no, nrow: 1, ncol: 2, nnz: 3, max_nnz: 3, indices_i: vec![0,0,0], indices_j: vec![0,0,0], values: vec![0.0,0.0,0.0] }).err(), Some("coo.nnz must be equal to nnz(dup) = csc.row_indices.len() = csc.values.len()")); } #[test] fn update_from_coo_again_works() { - let (coo, csc_correct, _, _) = Samples::umfpack_unsymmetric_5x5(false); + let (coo, csc_correct, _, _) = Samples::umfpack_unsymmetric_5x5(); let mut csc = NumCscMatrix::::from_coo(&coo).unwrap(); assert_eq!(&csc.col_pointers, &csc_correct.col_pointers); let nnz = csc.col_pointers[csc.ncol] as usize; @@ -1069,42 +1042,42 @@ mod tests { // ┌ ┐ // │ 123 │ // └ ┘ - Samples::tiny_1x1(IGNORED), + Samples::tiny_1x1(), // 1 . 2 // . 0 3 // 4 5 6 - Samples::unsymmetric_3x3(IGNORED, IGNORED, IGNORED), + Samples::unsymmetric_3x3(IGNORED, IGNORED), // 2 3 . . . // 3 . 4 . 6 // . -1 -3 2 . // . . 1 . . // . 4 2 . 1 - Samples::umfpack_unsymmetric_5x5(IGNORED), + Samples::umfpack_unsymmetric_5x5(), // 1 -1 . -3 . // -2 5 . . . // . . 4 6 4 // -4 . 2 7 . // . 8 . . -5 - Samples::mkl_unsymmetric_5x5(IGNORED), + Samples::mkl_unsymmetric_5x5(), // 1 2 . . . // 3 4 . . . // . . 5 6 . // . . 7 8 . // . . . . 9 - Samples::block_unsymmetric_5x5(IGNORED, IGNORED, IGNORED), + Samples::block_unsymmetric_5x5(IGNORED, IGNORED), // 9 1.5 6 0.75 3 // 1.5 0.5 . . . // 6 . 12 . . // 0.75 . . 0.625 . // 3 . . . 16 - Samples::mkl_positive_definite_5x5_lower(IGNORED), - Samples::mkl_symmetric_5x5_lower(IGNORED, IGNORED, IGNORED), - Samples::mkl_symmetric_5x5_upper(IGNORED, IGNORED, IGNORED), - Samples::mkl_symmetric_5x5_full(IGNORED), + Samples::mkl_positive_definite_5x5_lower(), + Samples::mkl_symmetric_5x5_lower(IGNORED, IGNORED), + Samples::mkl_symmetric_5x5_upper(IGNORED, IGNORED), + Samples::mkl_symmetric_5x5_full(), // ┌ ┐ // │ 10 20 │ // └ ┘ - Samples::rectangular_1x2(IGNORED, IGNORED, IGNORED), + Samples::rectangular_1x2(IGNORED, IGNORED), // ┌ ┐ // │ 1 . 3 . 5 . 7 │ // └ ┘ @@ -1133,7 +1106,7 @@ mod tests { #[test] fn to_matrix_fails_on_wrong_dims() { - let (_, csc, _, _) = Samples::rectangular_1x2(false, false, false); + let (_, csc, _, _) = Samples::rectangular_1x2(false, false); let mut a_3x1 = Matrix::new(3, 1); let mut a_1x3 = Matrix::new(1, 3); assert_eq!(csc.to_dense(&mut a_3x1), Err("wrong matrix dimensions")); @@ -1143,7 +1116,7 @@ mod tests { #[test] fn to_matrix_and_as_matrix_work() { // 1 x 2 matrix - let (_, csc, _, _) = Samples::rectangular_1x2(false, false, false); + let (_, csc, _, _) = Samples::rectangular_1x2(false, false); let mut a = Matrix::new(1, 2); csc.to_dense(&mut a).unwrap(); let correct = "┌ ┐\n\ @@ -1152,7 +1125,7 @@ mod tests { assert_eq!(format!("{}", a), correct); // 5 x 5 matrix - let (_, csc, _, _) = Samples::umfpack_unsymmetric_5x5(false); + let (_, csc, _, _) = Samples::umfpack_unsymmetric_5x5(); let mut a = Matrix::new(5, 5); csc.to_dense(&mut a).unwrap(); let correct = "┌ ┐\n\ @@ -1174,7 +1147,7 @@ mod tests { #[test] fn as_matrix_upper_works() { - let (_, csc, _, _) = Samples::mkl_symmetric_5x5_upper(false, false, false); + let (_, csc, _, _) = Samples::mkl_symmetric_5x5_upper(false, false); let a = csc.as_dense(); let correct = "┌ ┐\n\ │ 9 1.5 6 0.75 3 │\n\ @@ -1188,7 +1161,7 @@ mod tests { #[test] fn as_matrix_lower_works() { - let (_, csc, _, _) = Samples::mkl_symmetric_5x5_lower(false, false, false); + let (_, csc, _, _) = Samples::mkl_symmetric_5x5_lower(false, false); let a = csc.as_dense(); let correct = "┌ ┐\n\ │ 9 1.5 6 0.75 3 │\n\ @@ -1229,7 +1202,7 @@ mod tests { #[test] fn mat_vec_mul_symmetric_lower_works() { - let (_, csc, _, _) = Samples::mkl_symmetric_5x5_lower(false, false, false); + let (_, csc, _, _) = Samples::mkl_symmetric_5x5_lower(false, false); let u = Vector::from(&[1.0, 2.0, 3.0, 4.0, 5.0]); let mut v = Vector::new(5); csc.mat_vec_mul(&mut v, 2.0, &u).unwrap(); @@ -1266,13 +1239,13 @@ mod tests { #[test] fn getters_are_correct() { - let (_, csc, _, _) = Samples::rectangular_1x2(false, false, false); + let (_, csc, _, _) = Samples::rectangular_1x2(false, false); assert_eq!(csc.get_info(), (1, 2, 2, Symmetry::No)); assert_eq!(csc.get_col_pointers(), &[0, 1, 2]); assert_eq!(csc.get_row_indices(), &[0, 0]); assert_eq!(csc.get_values(), &[10.0, 20.0]); // with duplicates - let (coo, _, _, _) = Samples::rectangular_1x2(false, false, true); + let (coo, _, _, _) = Samples::rectangular_1x2(false, false); let csc = NumCscMatrix::::from_coo(&coo).unwrap(); assert_eq!(csc.get_info(), (1, 2, 2, Symmetry::No)); assert_eq!(csc.get_col_pointers(), &[0, 1, 2]); @@ -1299,7 +1272,7 @@ mod tests { #[test] fn derive_methods_work() { - let (coo, _, _, _) = Samples::umfpack_unsymmetric_5x5(false); + let (coo, _, _, _) = Samples::umfpack_unsymmetric_5x5(); let csc = NumCscMatrix::::from_coo(&coo).unwrap(); let nrow = coo.nrow; let nnz = coo.nnz; // it must be COO nnz because of (removed) duplicates diff --git a/russell_sparse/src/csr_matrix.rs b/russell_sparse/src/csr_matrix.rs index 460266ee..af0e5f42 100644 --- a/russell_sparse/src/csr_matrix.rs +++ b/russell_sparse/src/csr_matrix.rs @@ -270,7 +270,7 @@ where /// // . . 1 . . /// // . 4 2 . 1 /// let (nrow, ncol, nnz) = (5, 5, 13); - /// let mut coo = CooMatrix::new(nrow, ncol, nnz, None, false)?; + /// let mut coo = CooMatrix::new(nrow, ncol, nnz, None)?; /// coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate /// coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate /// coo.put(1, 0, 3.0)?; @@ -368,7 +368,6 @@ where let ncol = coo.ncol; let nnz = coo.nnz; let ndim = usize::max(nrow, ncol); - let d = if coo.one_based { -1 } else { 0 }; // access the triplet data let ai = &coo.indices_i; @@ -399,7 +398,7 @@ where // count the entries in each row (also counting duplicates) // use w as workspace for row counts (including duplicates) for k in 0..nnz { - let i = (ai[k] + d) as usize; + let i = ai[k] as usize; w[i] += 1; } @@ -412,9 +411,9 @@ where // construct the row form (with unsorted values) for k in 0..nnz { - let i = (ai[k] + d) as usize; + let i = ai[k] as usize; let p = w[i] as usize; - rjx[p].0 = aj[k] + d; + rjx[p].0 = aj[k]; rjx[p].1 = ax[k]; w[i] += 1; // w[i] is advanced to the start of row i+1 } @@ -876,7 +875,7 @@ mod tests { #[test] fn new_works() { - let (_, _, csr_correct, _) = Samples::rectangular_1x2(false, false, false); + let (_, _, csr_correct, _) = Samples::rectangular_1x2(false, false); let csr = NumCsrMatrix::::new(1, 2, vec![0, 2], vec![0, 1], vec![10.0, 20.0], None).unwrap(); assert_eq!(csr.symmetry, Symmetry::No); assert_eq!(csr.nrow, 1); @@ -888,7 +887,7 @@ mod tests { #[test] fn from_coo_captures_errors() { - let coo = CooMatrix::new(1, 1, 1, None, false).unwrap(); + let coo = CooMatrix::new(1, 1, 1, None).unwrap(); assert_eq!( NumCsrMatrix::::from_coo(&coo).err(), Some("COO to CSR requires nnz > 0") @@ -906,84 +905,58 @@ mod tests { // ┌ ┐ // │ 123 │ // └ ┘ - Samples::tiny_1x1(false), - Samples::tiny_1x1(true), + Samples::tiny_1x1(), // 1 . 2 // . 0 3 // 4 5 6 - Samples::unsymmetric_3x3(false, false, false), - Samples::unsymmetric_3x3(false, true, false), - Samples::unsymmetric_3x3(false, false, true), - Samples::unsymmetric_3x3(false, true, true), - Samples::unsymmetric_3x3(true, false, false), - Samples::unsymmetric_3x3(true, true, false), - Samples::unsymmetric_3x3(true, false, true), - Samples::unsymmetric_3x3(true, true, true), + Samples::unsymmetric_3x3(false, false), + Samples::unsymmetric_3x3(false, true), + Samples::unsymmetric_3x3(true, false), + Samples::unsymmetric_3x3(true, true), // 2 3 . . . // 3 . 4 . 6 // . -1 -3 2 . // . . 1 . . // . 4 2 . 1 - Samples::umfpack_unsymmetric_5x5(false), - Samples::umfpack_unsymmetric_5x5(true), + Samples::umfpack_unsymmetric_5x5(), // 1 -1 . -3 . // -2 5 . . . // . . 4 6 4 // -4 . 2 7 . // . 8 . . -5 - Samples::mkl_unsymmetric_5x5(false), - Samples::mkl_unsymmetric_5x5(true), + Samples::mkl_unsymmetric_5x5(), // 1 2 . . . // 3 4 . . . // . . 5 6 . // . . 7 8 . // . . . . 9 - Samples::block_unsymmetric_5x5(false, false, false), - Samples::block_unsymmetric_5x5(false, true, false), - Samples::block_unsymmetric_5x5(false, false, true), - Samples::block_unsymmetric_5x5(false, true, true), - Samples::block_unsymmetric_5x5(true, false, false), - Samples::block_unsymmetric_5x5(true, true, false), - Samples::block_unsymmetric_5x5(true, false, true), - Samples::block_unsymmetric_5x5(true, true, true), + Samples::block_unsymmetric_5x5(false, false), + Samples::block_unsymmetric_5x5(false, true), + Samples::block_unsymmetric_5x5(true, false), + Samples::block_unsymmetric_5x5(true, true), // 9 1.5 6 0.75 3 // 1.5 0.5 . . . // 6 . 12 . . // 0.75 . . 0.625 . // 3 . . . 16 - Samples::mkl_positive_definite_5x5_lower(false), - Samples::mkl_positive_definite_5x5_lower(true), - Samples::mkl_positive_definite_5x5_upper(false), - Samples::mkl_positive_definite_5x5_upper(true), - Samples::mkl_symmetric_5x5_lower(false, false, false), - Samples::mkl_symmetric_5x5_lower(false, true, false), - Samples::mkl_symmetric_5x5_lower(false, false, true), - Samples::mkl_symmetric_5x5_lower(false, true, true), - Samples::mkl_symmetric_5x5_lower(true, false, false), - Samples::mkl_symmetric_5x5_lower(true, true, false), - Samples::mkl_symmetric_5x5_lower(true, false, true), - Samples::mkl_symmetric_5x5_lower(true, true, true), - Samples::mkl_symmetric_5x5_upper(false, false, false), - Samples::mkl_symmetric_5x5_upper(false, true, false), - Samples::mkl_symmetric_5x5_upper(false, false, true), - Samples::mkl_symmetric_5x5_upper(false, true, true), - Samples::mkl_symmetric_5x5_upper(true, false, false), - Samples::mkl_symmetric_5x5_upper(true, true, false), - Samples::mkl_symmetric_5x5_upper(true, false, true), - Samples::mkl_symmetric_5x5_upper(true, true, true), - Samples::mkl_symmetric_5x5_full(false), - Samples::mkl_symmetric_5x5_full(true), + Samples::mkl_positive_definite_5x5_lower(), + Samples::mkl_positive_definite_5x5_upper(), + Samples::mkl_symmetric_5x5_lower(false, false), + Samples::mkl_symmetric_5x5_lower(false, true), + Samples::mkl_symmetric_5x5_lower(true, false), + Samples::mkl_symmetric_5x5_lower(true, true), + Samples::mkl_symmetric_5x5_upper(false, false), + Samples::mkl_symmetric_5x5_upper(false, true), + Samples::mkl_symmetric_5x5_upper(true, false), + Samples::mkl_symmetric_5x5_upper(true, true), + Samples::mkl_symmetric_5x5_full(), // ┌ ┐ // │ 10 20 │ // └ ┘ - Samples::rectangular_1x2(false, false, false), - Samples::rectangular_1x2(false, true, false), - Samples::rectangular_1x2(false, false, true), - Samples::rectangular_1x2(false, true, true), - Samples::rectangular_1x2(true, false, false), - Samples::rectangular_1x2(true, true, false), - Samples::rectangular_1x2(true, false, true), - Samples::rectangular_1x2(true, true, true), + Samples::rectangular_1x2(false, false), + Samples::rectangular_1x2(false, true), + Samples::rectangular_1x2(true, false), + Samples::rectangular_1x2(true, true), // ┌ ┐ // │ 1 . 3 . 5 . 7 │ // └ ┘ @@ -1013,7 +986,7 @@ mod tests { #[test] fn debug_conversion() { - let (coo, _, csr_correct, _) = Samples::umfpack_unsymmetric_5x5(false); + let (coo, _, csr_correct, _) = Samples::umfpack_unsymmetric_5x5(); let csr = NumCsrMatrix::::from_coo(&coo).unwrap(); assert_eq!(&csr.row_pointers, &csr_correct.row_pointers); let nnz = csr.row_pointers[csr.nrow] as usize; @@ -1024,19 +997,19 @@ mod tests { #[test] #[rustfmt::skip] fn update_from_coo_captures_errors() { - let (coo, _, _, _) = Samples::rectangular_1x2(false, false, false); + let (coo, _, _, _) = Samples::rectangular_1x2(false, false); let mut csr = NumCsrMatrix::::from_coo(&coo).unwrap(); let yes = Symmetry::General(Storage::Lower); let no = Symmetry::No; - assert_eq!(csr.update_from_coo(&CooMatrix { symmetry: yes, nrow: 1, ncol: 2, nnz: 1, max_nnz: 1, indices_i: vec![0], indices_j: vec![0], values: vec![0.0], one_based: false }).err(), Some("coo.symmetry must be equal to csr.symmetry")); - assert_eq!(csr.update_from_coo(&CooMatrix { symmetry: no, nrow: 2, ncol: 2, nnz: 1, max_nnz: 1, indices_i: vec![0], indices_j: vec![0], values: vec![0.0], one_based: false }).err(), Some("coo.nrow must be equal to csr.nrow")); - assert_eq!(csr.update_from_coo(&CooMatrix { symmetry: no, nrow: 1, ncol: 1, nnz: 1, max_nnz: 1, indices_i: vec![0], indices_j: vec![0], values: vec![0.0], one_based: false }).err(), Some("coo.ncol must be equal to csr.ncol")); - assert_eq!(csr.update_from_coo(&CooMatrix { symmetry: no, nrow: 1, ncol: 2, nnz: 3, max_nnz: 3, indices_i: vec![0,0,0], indices_j: vec![0,0,0], values: vec![0.0,0.0,0.0], one_based: false }).err(), Some("coo.nnz must be equal to nnz(dup) = self.col_indices.len() = csr.values.len()")); + assert_eq!(csr.update_from_coo(&CooMatrix { symmetry: yes, nrow: 1, ncol: 2, nnz: 1, max_nnz: 1, indices_i: vec![0], indices_j: vec![0], values: vec![0.0] }).err(), Some("coo.symmetry must be equal to csr.symmetry")); + assert_eq!(csr.update_from_coo(&CooMatrix { symmetry: no, nrow: 2, ncol: 2, nnz: 1, max_nnz: 1, indices_i: vec![0], indices_j: vec![0], values: vec![0.0] }).err(), Some("coo.nrow must be equal to csr.nrow")); + assert_eq!(csr.update_from_coo(&CooMatrix { symmetry: no, nrow: 1, ncol: 1, nnz: 1, max_nnz: 1, indices_i: vec![0], indices_j: vec![0], values: vec![0.0] }).err(), Some("coo.ncol must be equal to csr.ncol")); + assert_eq!(csr.update_from_coo(&CooMatrix { symmetry: no, nrow: 1, ncol: 2, nnz: 3, max_nnz: 3, indices_i: vec![0,0,0], indices_j: vec![0,0,0], values: vec![0.0,0.0,0.0] }).err(), Some("coo.nnz must be equal to nnz(dup) = self.col_indices.len() = csr.values.len()")); } #[test] fn update_from_coo_again_works() { - let (coo, _, csr_correct, _) = Samples::umfpack_unsymmetric_5x5(false); + let (coo, _, csr_correct, _) = Samples::umfpack_unsymmetric_5x5(); let mut csr = NumCsrMatrix::::from_coo(&coo).unwrap(); assert_eq!(&csr.row_pointers, &csr_correct.row_pointers); let nnz = csr.row_pointers[csr.nrow] as usize; @@ -1057,42 +1030,42 @@ mod tests { // ┌ ┐ // │ 123 │ // └ ┘ - Samples::tiny_1x1(IGNORED), + Samples::tiny_1x1(), // 1 . 2 // . 0 3 // 4 5 6 - Samples::unsymmetric_3x3(IGNORED, IGNORED, IGNORED), + Samples::unsymmetric_3x3(IGNORED, IGNORED), // 2 3 . . . // 3 . 4 . 6 // . -1 -3 2 . // . . 1 . . // . 4 2 . 1 - Samples::umfpack_unsymmetric_5x5(IGNORED), + Samples::umfpack_unsymmetric_5x5(), // 1 -1 . -3 . // -2 5 . . . // . . 4 6 4 // -4 . 2 7 . // . 8 . . -5 - Samples::mkl_unsymmetric_5x5(IGNORED), + Samples::mkl_unsymmetric_5x5(), // 1 2 . . . // 3 4 . . . // . . 5 6 . // . . 7 8 . // . . . . 9 - Samples::block_unsymmetric_5x5(IGNORED, IGNORED, IGNORED), + Samples::block_unsymmetric_5x5(IGNORED, IGNORED), // 9 1.5 6 0.75 3 // 1.5 0.5 . . . // 6 . 12 . . // 0.75 . . 0.625 . // 3 . . . 16 - Samples::mkl_positive_definite_5x5_lower(IGNORED), - Samples::mkl_symmetric_5x5_lower(IGNORED, IGNORED, IGNORED), - Samples::mkl_symmetric_5x5_upper(IGNORED, IGNORED, IGNORED), - Samples::mkl_symmetric_5x5_full(IGNORED), + Samples::mkl_positive_definite_5x5_lower(), + Samples::mkl_symmetric_5x5_lower(IGNORED, IGNORED), + Samples::mkl_symmetric_5x5_upper(IGNORED, IGNORED), + Samples::mkl_symmetric_5x5_full(), // ┌ ┐ // │ 10 20 │ // └ ┘ - Samples::rectangular_1x2(IGNORED, IGNORED, IGNORED), + Samples::rectangular_1x2(IGNORED, IGNORED), // ┌ ┐ // │ 1 . 3 . 5 . 7 │ // └ ┘ @@ -1121,7 +1094,7 @@ mod tests { #[test] fn to_matrix_fails_on_wrong_dims() { - let (_, _, csr, _) = Samples::rectangular_1x2(false, false, false); + let (_, _, csr, _) = Samples::rectangular_1x2(false, false); let mut a_3x1 = Matrix::new(3, 1); let mut a_1x3 = Matrix::new(1, 3); assert_eq!(csr.to_dense(&mut a_3x1), Err("wrong matrix dimensions")); @@ -1131,7 +1104,7 @@ mod tests { #[test] fn to_matrix_and_as_matrix_work() { // 1 x 2 matrix - let (_, _, csr, _) = Samples::rectangular_1x2(false, false, false); + let (_, _, csr, _) = Samples::rectangular_1x2(false, false); let mut a = Matrix::new(1, 2); csr.to_dense(&mut a).unwrap(); let correct = "┌ ┐\n\ @@ -1140,7 +1113,7 @@ mod tests { assert_eq!(format!("{}", a), correct); // 5 x 5 matrix - let (_, _, csr, _) = Samples::umfpack_unsymmetric_5x5(false); + let (_, _, csr, _) = Samples::umfpack_unsymmetric_5x5(); let mut a = Matrix::new(5, 5); csr.to_dense(&mut a).unwrap(); let correct = "┌ ┐\n\ @@ -1162,7 +1135,7 @@ mod tests { #[test] fn as_matrix_upper_works() { - let (_, _, csr, _) = Samples::mkl_symmetric_5x5_upper(false, false, false); + let (_, _, csr, _) = Samples::mkl_symmetric_5x5_upper(false, false); let a = csr.as_dense(); let correct = "┌ ┐\n\ │ 9 1.5 6 0.75 3 │\n\ @@ -1176,7 +1149,7 @@ mod tests { #[test] fn as_matrix_lower_works() { - let (_, _, csr, _) = Samples::mkl_symmetric_5x5_lower(false, false, false); + let (_, _, csr, _) = Samples::mkl_symmetric_5x5_lower(false, false); let a = csr.as_dense(); let correct = "┌ ┐\n\ │ 9 1.5 6 0.75 3 │\n\ @@ -1217,7 +1190,7 @@ mod tests { #[test] fn mat_vec_mul_symmetric_lower_works() { - let (_, _, csr, _) = Samples::mkl_symmetric_5x5_lower(false, false, false); + let (_, _, csr, _) = Samples::mkl_symmetric_5x5_lower(false, false); let u = Vector::from(&[1.0, 2.0, 3.0, 4.0, 5.0]); let mut v = Vector::new(5); csr.mat_vec_mul(&mut v, 2.0, &u).unwrap(); @@ -1254,13 +1227,13 @@ mod tests { #[test] fn getters_are_correct() { - let (_, _, csr, _) = Samples::rectangular_1x2(false, false, false); + let (_, _, csr, _) = Samples::rectangular_1x2(false, false); assert_eq!(csr.get_info(), (1, 2, 2, Symmetry::No)); assert_eq!(csr.get_row_pointers(), &[0, 2]); assert_eq!(csr.get_col_indices(), &[0, 1]); assert_eq!(csr.get_values(), &[10.0, 20.0]); // with duplicates - let (coo, _, _, _) = Samples::rectangular_1x2(false, false, true); + let (coo, _, _, _) = Samples::rectangular_1x2(false, false); let csr = NumCsrMatrix::::from_coo(&coo).unwrap(); assert_eq!(csr.get_info(), (1, 2, 2, Symmetry::No)); assert_eq!(csr.get_row_pointers(), &[0, 2]); @@ -1286,7 +1259,7 @@ mod tests { #[test] fn derive_methods_work() { - let (coo, _, _, _) = Samples::umfpack_unsymmetric_5x5(false); + let (coo, _, _, _) = Samples::umfpack_unsymmetric_5x5(); let csr = NumCsrMatrix::::from_coo(&coo).unwrap(); let nrow = coo.nrow; let nnz = coo.nnz; // it must be COO nnz because of (removed) duplicates diff --git a/russell_sparse/src/enums.rs b/russell_sparse/src/enums.rs index 3f9b4cc8..4eafff13 100644 --- a/russell_sparse/src/enums.rs +++ b/russell_sparse/src/enums.rs @@ -201,15 +201,6 @@ impl Genie { Symmetry::No } } - - /// Returns whether the sparse matrix indices must be one-based or not - pub fn one_based(&self) -> bool { - match self { - Genie::Mumps => true, - Genie::Umfpack => false, - Genie::IntelDss => false, - } - } } impl Symmetry { @@ -532,7 +523,6 @@ mod tests { assert_eq!(genie.symmetry(true, false), gl); assert_eq!(genie.symmetry(false, true), pl); assert_eq!(genie.symmetry(true, true), pl); - assert_eq!(genie.one_based(), true); let genie = Genie::Umfpack; assert_eq!(genie.to_string(), "umfpack"); @@ -541,7 +531,6 @@ mod tests { assert_eq!(genie.symmetry(true, false), gf); assert_eq!(genie.symmetry(false, true), pf); assert_eq!(genie.symmetry(true, true), pf); - assert_eq!(genie.one_based(), false); let genie = Genie::IntelDss; assert_eq!(genie.to_string(), "inteldss"); @@ -550,7 +539,6 @@ mod tests { assert_eq!(genie.symmetry(true, false), gu); assert_eq!(genie.symmetry(false, true), pu); assert_eq!(genie.symmetry(true, true), pu); - assert_eq!(genie.one_based(), false); } #[test] diff --git a/russell_sparse/src/lib.rs b/russell_sparse/src/lib.rs index cc6fcb25..ba282ab8 100644 --- a/russell_sparse/src/lib.rs +++ b/russell_sparse/src/lib.rs @@ -82,7 +82,7 @@ //! // │ 4 5 6 │ but should be saved for Intel DSS //! // └ ┘ //! let (nrow, ncol, nnz) = (3, 3, 6); -//! let mut coo = CooMatrix::new(nrow, ncol, nnz, None, false)?; +//! let mut coo = CooMatrix::new(nrow, ncol, nnz, None)?; //! coo.put(0, 0, 1.0)?; //! coo.put(0, 2, 2.0)?; //! coo.put(1, 2, 3.0)?; @@ -132,7 +132,7 @@ //! let mut solver = LinSolver::new(Genie::Umfpack)?; //! //! // allocate the coefficient matrix -//! let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None, false)?; +//! let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None)?; //! coo.put(0, 0, 0.2)?; //! coo.put(0, 1, 0.2)?; //! coo.put(1, 0, 0.5)?; @@ -191,7 +191,7 @@ //! // . -1 -3 2 . //! // . . 1 . . //! // . 4 2 . 1 -//! let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None, false)?; +//! let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None)?; //! coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate //! coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate //! coo.put(1, 0, 3.0)?; diff --git a/russell_sparse/src/lin_solver.rs b/russell_sparse/src/lin_solver.rs index ce9084e2..f0d6a8db 100644 --- a/russell_sparse/src/lin_solver.rs +++ b/russell_sparse/src/lin_solver.rs @@ -111,7 +111,7 @@ impl<'a> LinSolver<'a> { /// let nnz = 5; // number of non-zero values /// /// // allocate the coefficient matrix - /// let mut mat = SparseMatrix::new_coo(ndim, ndim, nnz, None, false)?; + /// let mut mat = SparseMatrix::new_coo(ndim, ndim, nnz, None)?; /// mat.put(0, 0, 0.2)?; /// mat.put(0, 1, 0.2)?; /// mat.put(1, 0, 0.5)?; @@ -174,7 +174,7 @@ mod tests { #[test] #[serial] fn lin_solver_compute_works_mumps() { - let (coo, _, _, _) = Samples::mkl_symmetric_5x5_lower(true, false, false); + let (coo, _, _, _) = Samples::mkl_symmetric_5x5_lower(true, false); let mut mat = SparseMatrix::from_coo(coo); let mut x = Vector::new(5); let rhs = Vector::from(&[1.0, 2.0, 3.0, 4.0, 5.0]); @@ -185,7 +185,7 @@ mod tests { #[test] fn lin_solver_compute_works_umfpack() { - let (coo, _, _, _) = Samples::mkl_symmetric_5x5_full(false); + let (coo, _, _, _) = Samples::mkl_symmetric_5x5_full(); let mut mat = SparseMatrix::from_coo(coo); let mut x = Vector::new(5); let rhs = Vector::from(&[1.0, 2.0, 3.0, 4.0, 5.0]); diff --git a/russell_sparse/src/read_matrix_market.rs b/russell_sparse/src/read_matrix_market.rs index df66e427..f277433c 100644 --- a/russell_sparse/src/read_matrix_market.rs +++ b/russell_sparse/src/read_matrix_market.rs @@ -167,7 +167,6 @@ impl MatrixMarketData { /// /// * `full_path` -- may be a String, &str, or Path /// * `symmetric_handling` -- Options to handle symmetric matrices -/// * `one_based` -- Use one-based indices; e.g., for MUMPS or other FORTRAN routines /// /// # Output /// @@ -265,7 +264,7 @@ impl MatrixMarketData { /// /// fn main() -> Result<(), StrError> { /// let name = "./data/matrix_market/ok_simple_general.mtx"; -/// let coo = read_matrix_market(name, MMsymOption::LeaveAsLower, false)?; +/// let coo = read_matrix_market(name, MMsymOption::LeaveAsLower)?; /// let (nrow, ncol, nnz, symmetry) = coo.get_info(); /// assert_eq!(nrow, 3); /// assert_eq!(ncol, 3); @@ -304,7 +303,7 @@ impl MatrixMarketData { /// /// fn main() -> Result<(), StrError> { /// let name = "./data/matrix_market/ok_simple_symmetric.mtx"; -/// let coo = read_matrix_market(name, MMsymOption::LeaveAsLower, false)?; +/// let coo = read_matrix_market(name, MMsymOption::LeaveAsLower)?; /// let (nrow, ncol, nnz, symmetry) = coo.get_info(); /// assert_eq!(nrow, 3); /// assert_eq!(ncol, 3); @@ -320,11 +319,7 @@ impl MatrixMarketData { /// Ok(()) /// } /// ``` -pub fn read_matrix_market

( - full_path: &P, - symmetric_handling: MMsymOption, - one_based: bool, -) -> Result +pub fn read_matrix_market

(full_path: &P, symmetric_handling: MMsymOption) -> Result where P: AsRef + ?Sized, { @@ -374,7 +369,7 @@ where } // allocate triplet - let mut coo = CooMatrix::new(data.m as usize, data.n as usize, max as usize, symmetry, one_based).unwrap(); + let mut coo = CooMatrix::new(data.m as usize, data.n as usize, max as usize, symmetry).unwrap(); // read and parse triples loop { @@ -537,30 +532,29 @@ mod tests { #[test] fn read_matrix_market_handle_wrong_files() { let h = MMsymOption::LeaveAsLower; - let o = false; - assert_eq!(read_matrix_market("__wrong__", h, o).err(), Some("cannot open file")); + assert_eq!(read_matrix_market("__wrong__", h).err(), Some("cannot open file")); assert_eq!( - read_matrix_market("./data/matrix_market/bad_empty_file.mtx", h, o).err(), + read_matrix_market("./data/matrix_market/bad_empty_file.mtx", h).err(), Some("file is empty") ); assert_eq!( - read_matrix_market("./data/matrix_market/bad_wrong_header.mtx", h, o).err(), + read_matrix_market("./data/matrix_market/bad_wrong_header.mtx", h).err(), Some("after %%MatrixMarket, the first option must be \"matrix\"") ); assert_eq!( - read_matrix_market("./data/matrix_market/bad_wrong_dims.mtx", h, o).err(), + read_matrix_market("./data/matrix_market/bad_wrong_dims.mtx", h).err(), Some("found invalid (zero or negative) dimensions") ); assert_eq!( - read_matrix_market("./data/matrix_market/bad_missing_data.mtx", h, o).err(), + read_matrix_market("./data/matrix_market/bad_missing_data.mtx", h).err(), Some("not all triples (i, j, aij) have been found") ); assert_eq!( - read_matrix_market("./data/matrix_market/bad_many_lines.mtx", h, o).err(), + read_matrix_market("./data/matrix_market/bad_many_lines.mtx", h).err(), Some("there are more (i, j, aij) triples than specified") ); assert_eq!( - read_matrix_market("./data/matrix_market/bad_symmetric_rectangular.mtx", h,o).err(), + read_matrix_market("./data/matrix_market/bad_symmetric_rectangular.mtx", h).err(), Some("MatrixMarket data is invalid: the number of rows must be equal the number of columns for symmetric matrices") ); } @@ -568,9 +562,8 @@ mod tests { #[test] fn read_matrix_market_works() { let h = MMsymOption::LeaveAsLower; - let o = false; let filepath = "./data/matrix_market/ok_general.mtx".to_string(); - let coo = read_matrix_market(&filepath, h, o).unwrap(); + let coo = read_matrix_market(&filepath, h).unwrap(); assert_eq!(coo.symmetry, Symmetry::No); assert_eq!((coo.nrow, coo.ncol, coo.nnz, coo.max_nnz), (5, 5, 12, 12)); assert_eq!(coo.indices_i, &[0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4]); @@ -584,9 +577,8 @@ mod tests { #[test] fn read_matrix_market_symmetric_lower_works() { let h = MMsymOption::LeaveAsLower; - let o = false; let filepath = "./data/matrix_market/ok_symmetric.mtx".to_string(); - let coo = read_matrix_market(&filepath, h, o).unwrap(); + let coo = read_matrix_market(&filepath, h).unwrap(); assert_eq!(coo.symmetry, Symmetry::General(Storage::Lower)); assert_eq!((coo.nrow, coo.ncol, coo.nnz, coo.max_nnz), (5, 5, 15, 15)); assert_eq!(coo.indices_i, &[0, 1, 2, 3, 4, 1, 2, 3, 4, 2, 3, 4, 3, 4, 4]); @@ -600,9 +592,8 @@ mod tests { #[test] fn read_matrix_market_symmetric_upper_works() { let h = MMsymOption::SwapToUpper; - let o = false; let filepath = "./data/matrix_market/ok_symmetric.mtx".to_string(); - let coo = read_matrix_market(&filepath, h, o).unwrap(); + let coo = read_matrix_market(&filepath, h).unwrap(); assert_eq!(coo.symmetry, Symmetry::General(Storage::Upper)); assert_eq!((coo.nrow, coo.ncol, coo.nnz, coo.max_nnz), (5, 5, 15, 15)); assert_eq!(coo.indices_i, &[0, 1, 2, 3, 4, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3]); @@ -616,9 +607,8 @@ mod tests { #[test] fn read_matrix_market_symmetric_to_full_works() { let h = MMsymOption::MakeItFull; - let o = false; let filepath = "./data/matrix_market/ok_symmetric_small.mtx".to_string(); - let coo = read_matrix_market(&filepath, h, o).unwrap(); + let coo = read_matrix_market(&filepath, h).unwrap(); assert_eq!(coo.symmetry, Symmetry::General(Storage::Full)); assert_eq!((coo.nrow, coo.ncol, coo.nnz, coo.max_nnz), (5, 5, 11, 14)); assert_eq!(coo.indices_i, &[0, 1, 0, 2, 1, 3, 2, 3, 4, 1, 4, 0, 0, 0]); diff --git a/russell_sparse/src/samples.rs b/russell_sparse/src/samples.rs index 99d85594..146c8eca 100644 --- a/russell_sparse/src/samples.rs +++ b/russell_sparse/src/samples.rs @@ -16,12 +16,12 @@ impl Samples { /// │ 123 │ /// └ ┘ /// ``` - pub fn tiny_1x1(one_based: bool) -> (CooMatrix, CscMatrix, CsrMatrix, f64) { + pub fn tiny_1x1() -> (CooMatrix, CscMatrix, CsrMatrix, f64) { let sym = None; let nrow = 1; let ncol = 1; let max_nnz = 1; - let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym, one_based).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym).unwrap(); coo.put(0, 0, 123.0).unwrap(); // CSC matrix let col_pointers = vec![0, 1]; @@ -43,12 +43,12 @@ impl Samples { /// │ 12+3i │ /// └ ┘ /// ``` - pub fn complex_tiny_1x1(one_based: bool) -> (ComplexCooMatrix, ComplexCscMatrix, ComplexCsrMatrix, Complex64) { + pub fn complex_tiny_1x1() -> (ComplexCooMatrix, ComplexCscMatrix, ComplexCsrMatrix, Complex64) { let sym = None; let nrow = 1; let ncol = 1; let max_nnz = 1; - let mut coo = ComplexCooMatrix::new(nrow, ncol, max_nnz, sym, one_based).unwrap(); + let mut coo = ComplexCooMatrix::new(nrow, ncol, max_nnz, sym).unwrap(); coo.put(0, 0, cpx!(12.0, 3.0)).unwrap(); // CSC matrix let col_pointers = vec![0, 1]; @@ -70,10 +70,10 @@ impl Samples { /// -1 2 -1 => -1 2 /// -1 2 -1 2 /// ``` - pub fn positive_definite_3x3(one_based: bool) -> (CooMatrix, CscMatrix, CsrMatrix, f64) { + pub fn positive_definite_3x3() -> (CooMatrix, CscMatrix, CsrMatrix, f64) { let (nrow, ncol, nnz) = (3, 3, 6); let sym = Some(Symmetry::PositiveDefinite(Storage::Lower)); - let mut coo = CooMatrix::new(nrow, ncol, nnz, sym, one_based).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, nnz, sym).unwrap(); coo.put(1, 0, -0.5).unwrap(); // duplicate coo.put(0, 0, 2.0).unwrap(); coo.put(2, 2, 2.0).unwrap(); @@ -116,12 +116,10 @@ impl Samples { /// -1-1i 2+2i -1+1i => -1-1i 2+2i /// -1+1i 2-1i -1+1i 2-1i /// ``` - pub fn complex_symmetric_3x3_lower( - one_based: bool, - ) -> (ComplexCooMatrix, ComplexCscMatrix, ComplexCsrMatrix, Complex64) { + pub fn complex_symmetric_3x3_lower() -> (ComplexCooMatrix, ComplexCscMatrix, ComplexCsrMatrix, Complex64) { let (nrow, ncol, nnz) = (3, 3, 6); let sym = Some(Symmetry::General(Storage::Lower)); - let mut coo = ComplexCooMatrix::new(nrow, ncol, nnz, sym, one_based).unwrap(); + let mut coo = ComplexCooMatrix::new(nrow, ncol, nnz, sym).unwrap(); coo.put(1, 0, cpx!(-0.5, -0.5)).unwrap(); // duplicate coo.put(0, 0, cpx!(2.0, 1.0)).unwrap(); coo.put(2, 2, cpx!(2.0, -1.0)).unwrap(); @@ -169,7 +167,7 @@ impl Samples { pub fn complex_symmetric_3x3_full() -> (ComplexCooMatrix, ComplexCscMatrix, ComplexCsrMatrix, Complex64) { let (nrow, ncol, nnz) = (3, 3, 8); let sym = Some(Symmetry::General(Storage::Full)); - let mut coo = ComplexCooMatrix::new(nrow, ncol, nnz, sym, false).unwrap(); + let mut coo = ComplexCooMatrix::new(nrow, ncol, nnz, sym).unwrap(); coo.put(1, 0, cpx!(-0.5, -0.5)).unwrap(); // duplicate coo.put(0, 0, cpx!(2.0, 1.0)).unwrap(); coo.put(2, 2, cpx!(2.0, -1.0)).unwrap(); @@ -221,7 +219,7 @@ impl Samples { pub fn lower_symmetric_5x5() -> (CooMatrix, CscMatrix, CsrMatrix, f64) { let (nrow, ncol, nnz) = (5, 5, 18); let sym = Some(Symmetry::PositiveDefinite(Storage::Lower)); - let mut coo = CooMatrix::new(nrow, ncol, nnz, sym, false).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, nnz, sym).unwrap(); coo.put(1, 1, 2.0).unwrap(); coo.put(4, 2, 2.5).unwrap(); // duplicate coo.put(2, 2, 9.0).unwrap(); @@ -301,7 +299,6 @@ impl Samples { /// let x_correct = &[3.0, 3.0, 15]; /// ``` pub fn unsymmetric_3x3( - one_based: bool, shuffle_coo_entries: bool, duplicate_coo_entries: bool, ) -> (CooMatrix, CscMatrix, CsrMatrix, f64) { @@ -309,7 +306,7 @@ impl Samples { let nrow = 3; let ncol = 3; let max_nnz = 10; // more nnz than needed => OK - let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym, one_based).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym).unwrap(); if shuffle_coo_entries { if duplicate_coo_entries { coo.put(0, 2, 2.0).unwrap(); @@ -403,12 +400,12 @@ impl Samples { /// ```text /// let x_correct = &[1.0, 2.0, 3.0, 4.0, 5.0]; /// ``` - pub fn umfpack_unsymmetric_5x5(one_based: bool) -> (CooMatrix, CscMatrix, CsrMatrix, f64) { + pub fn umfpack_unsymmetric_5x5() -> (CooMatrix, CscMatrix, CsrMatrix, f64) { let sym = None; let nrow = 5; let ncol = 5; let max_nnz = 13; - let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym, one_based).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym).unwrap(); coo.put(0, 0, 1.0).unwrap(); // << (0, 0, a00/2) duplicate coo.put(2, 1, -1.0).unwrap(); coo.put(1, 0, 3.0).unwrap(); @@ -473,11 +470,11 @@ impl Samples { /// /// Reference: /// - pub fn mkl_unsymmetric_5x5(one_based: bool) -> (CooMatrix, CscMatrix, CsrMatrix, f64) { + pub fn mkl_unsymmetric_5x5() -> (CooMatrix, CscMatrix, CsrMatrix, f64) { let sym = None; let nrow = 5; let ncol = 5; - let mut coo = CooMatrix::new(nrow, ncol, 13, sym, one_based).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, 13, sym).unwrap(); coo.put(2, 4, 4.0).unwrap(); coo.put(4, 1, 8.0).unwrap(); coo.put(0, 1, -1.0).unwrap(); @@ -540,7 +537,6 @@ impl Samples { /// . . . . 9 /// ``` pub fn block_unsymmetric_5x5( - one_based: bool, shuffle_coo_entries: bool, duplicate_coo_entries: bool, ) -> (CooMatrix, CscMatrix, CsrMatrix, f64) { @@ -548,7 +544,7 @@ impl Samples { let nrow = 5; let ncol = 5; let max_nnz = 11; // more nnz than needed => OK - let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym, one_based).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym).unwrap(); if shuffle_coo_entries { if duplicate_coo_entries { coo.put(4, 4, 9.0).unwrap(); @@ -658,11 +654,11 @@ impl Samples { /// ```text /// x_correct = vec![-979.0 / 3.0, 983.0, 1961.0 / 12.0, 398.0, 123.0 / 2.0]; /// ``` - pub fn mkl_positive_definite_5x5_lower(one_based: bool) -> (CooMatrix, CscMatrix, CsrMatrix, f64) { + pub fn mkl_positive_definite_5x5_lower() -> (CooMatrix, CscMatrix, CsrMatrix, f64) { let sym = Some(Symmetry::PositiveDefinite(Storage::Lower)); let nrow = 5; let ncol = 5; - let mut coo = CooMatrix::new(nrow, ncol, 9, sym, one_based).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, 9, sym).unwrap(); coo.put(0, 0, 9.0).unwrap(); coo.put(1, 1, 0.5).unwrap(); coo.put(2, 2, 12.0).unwrap(); @@ -732,11 +728,11 @@ impl Samples { /// ```text /// x_correct = vec![-979.0 / 3.0, 983.0, 1961.0 / 12.0, 398.0, 123.0 / 2.0]; /// ``` - pub fn mkl_positive_definite_5x5_upper(one_based: bool) -> (CooMatrix, CscMatrix, CsrMatrix, f64) { + pub fn mkl_positive_definite_5x5_upper() -> (CooMatrix, CscMatrix, CsrMatrix, f64) { let sym = Some(Symmetry::PositiveDefinite(Storage::Upper)); let nrow = 5; let ncol = 5; - let mut coo = CooMatrix::new(nrow, ncol, 9, sym, one_based).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, 9, sym).unwrap(); coo.put(0, 0, 9.0).unwrap(); coo.put(0, 1, 1.5).unwrap(); coo.put(1, 1, 0.5).unwrap(); @@ -807,7 +803,6 @@ impl Samples { /// x_correct = vec![-979.0 / 3.0, 983.0, 1961.0 / 12.0, 398.0, 123.0 / 2.0]; /// ``` pub fn mkl_symmetric_5x5_lower( - one_based: bool, shuffle_coo_entries: bool, duplicate_coo_entries: bool, ) -> (CooMatrix, CscMatrix, CsrMatrix, f64) { @@ -815,7 +810,7 @@ impl Samples { let nrow = 5; let ncol = 5; let max_nnz = 13; - let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym, one_based).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym).unwrap(); if shuffle_coo_entries { if duplicate_coo_entries { // diagonal @@ -930,7 +925,6 @@ impl Samples { /// x_correct = vec![-979.0 / 3.0, 983.0, 1961.0 / 12.0, 398.0, 123.0 / 2.0]; /// ``` pub fn mkl_symmetric_5x5_upper( - one_based: bool, shuffle_coo_entries: bool, duplicate_coo_entries: bool, ) -> (CooMatrix, CscMatrix, CsrMatrix, f64) { @@ -938,7 +932,7 @@ impl Samples { let nrow = 5; let ncol = 5; let max_nnz = 15; - let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym, one_based).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym).unwrap(); if shuffle_coo_entries { if duplicate_coo_entries { coo.put(0, 0, 6.0).unwrap(); // << duplicate @@ -1051,12 +1045,12 @@ impl Samples { /// ```text /// x_correct = vec![-979.0 / 3.0, 983.0, 1961.0 / 12.0, 398.0, 123.0 / 2.0]; /// ``` - pub fn mkl_symmetric_5x5_full(one_based: bool) -> (CooMatrix, CscMatrix, CsrMatrix, f64) { + pub fn mkl_symmetric_5x5_full() -> (CooMatrix, CscMatrix, CsrMatrix, f64) { let sym = Some(Symmetry::General(Storage::Full)); let nrow = 5; let ncol = 5; let max_nnz = 13; - let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym, one_based).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym).unwrap(); coo.put(0, 0, 9.0).unwrap(); coo.put(0, 1, 1.5).unwrap(); coo.put(0, 2, 6.0).unwrap(); @@ -1117,7 +1111,6 @@ impl Samples { /// └ ┘ /// ``` pub fn rectangular_1x2( - one_based: bool, shuffle_coo_entries: bool, duplicate_coo_entries: bool, ) -> (CooMatrix, CscMatrix, CsrMatrix, f64) { @@ -1125,7 +1118,7 @@ impl Samples { let nrow = 1; let ncol = 2; let max_nnz = 10; - let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym, one_based).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, max_nnz, sym).unwrap(); if shuffle_coo_entries { if duplicate_coo_entries { coo.put(0, 1, 2.0).unwrap(); @@ -1184,7 +1177,7 @@ impl Samples { let sym = None; let nrow = 1; let ncol = 7; - let mut coo = CooMatrix::new(nrow, ncol, 4, sym, false).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, 4, sym).unwrap(); coo.put(0, 0, 1.0).unwrap(); coo.put(0, 2, 3.0).unwrap(); coo.put(0, 4, 5.0).unwrap(); @@ -1231,7 +1224,7 @@ impl Samples { let sym = None; let nrow = 7; let ncol = 1; - let mut coo = CooMatrix::new(nrow, ncol, 3, sym, false).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, 3, sym).unwrap(); coo.put(1, 0, 2.0).unwrap(); coo.put(3, 0, 4.0).unwrap(); coo.put(5, 0, 6.0).unwrap(); @@ -1271,7 +1264,7 @@ impl Samples { let sym = None; let nrow = 3; let ncol = 4; - let mut coo = CooMatrix::new(nrow, ncol, 9, sym, false).unwrap(); + let mut coo = CooMatrix::new(nrow, ncol, 9, sym).unwrap(); coo.put(0, 0, 5.0).unwrap(); coo.put(1, 0, 10.0).unwrap(); coo.put(2, 0, 15.0).unwrap(); @@ -1326,7 +1319,7 @@ impl Samples { let sym = None; let nrow = 4; let ncol = 3; - let mut coo = ComplexCooMatrix::new(nrow, ncol, 7, sym, false).unwrap(); + let mut coo = ComplexCooMatrix::new(nrow, ncol, 7, sym).unwrap(); coo.put(0, 0, cpx!(4.0, 4.0)).unwrap(); coo.put(0, 2, cpx!(2.0, 2.0)).unwrap(); coo.put(1, 1, cpx!(1.0, 0.0)).unwrap(); @@ -1450,16 +1443,12 @@ mod tests { let a = Matrix::from(correct); let mut ai = Matrix::new(1, 1); let correct_det = mat_inverse(&mut ai, &a).unwrap(); - for (coo, csc, csr, det) in [ - Samples::tiny_1x1(false), // - Samples::tiny_1x1(true), // - ] { - approx_eq(det, correct_det, 1e-15); - mat_approx_eq(&coo.as_dense(), correct, 1e-15); - mat_approx_eq(&csc.as_dense(), correct, 1e-15); - mat_approx_eq(&csr.as_dense(), correct, 1e-15); - check(&coo, &csc, &csr); - } + let (coo, csc, csr, det) = Samples::tiny_1x1(); + approx_eq(det, correct_det, 1e-15); + mat_approx_eq(&coo.as_dense(), correct, 1e-15); + mat_approx_eq(&csc.as_dense(), correct, 1e-15); + mat_approx_eq(&csr.as_dense(), correct, 1e-15); + check(&coo, &csc, &csr); // ---------------------------------------------------------------------------- @@ -1469,16 +1458,12 @@ mod tests { let a = ComplexMatrix::from(correct); let mut ai = ComplexMatrix::new(1, 1); let correct_det = complex_mat_inverse(&mut ai, &a).unwrap(); - for (coo, csc, csr, det) in [ - Samples::complex_tiny_1x1(false), // - Samples::complex_tiny_1x1(true), // - ] { - complex_approx_eq(det, correct_det, 1e-15); - complex_mat_approx_eq(&coo.as_dense(), correct, 1e-15); - complex_mat_approx_eq(&csc.as_dense(), correct, 1e-15); - complex_mat_approx_eq(&csr.as_dense(), correct, 1e-15); - check(&coo, &csc, &csr); - } + let (coo, csc, csr, det) = Samples::complex_tiny_1x1(); + complex_approx_eq(det, correct_det, 1e-15); + complex_mat_approx_eq(&coo.as_dense(), correct, 1e-15); + complex_mat_approx_eq(&csc.as_dense(), correct, 1e-15); + complex_mat_approx_eq(&csr.as_dense(), correct, 1e-15); + check(&coo, &csc, &csr); // ---------------------------------------------------------------------------- @@ -1490,7 +1475,7 @@ mod tests { let a = Matrix::from(correct); let mut ai = Matrix::new(3, 3); let correct_det = mat_inverse(&mut ai, &a).unwrap(); - let (coo, csc, csr, det) = Samples::positive_definite_3x3(false); + let (coo, csc, csr, det) = Samples::positive_definite_3x3(); approx_eq(det, correct_det, 1e-15); mat_approx_eq(&coo.as_dense(), correct, 1e-15); mat_approx_eq(&csc.as_dense(), correct, 1e-15); @@ -1509,7 +1494,7 @@ mod tests { let mut ai = ComplexMatrix::new(3, 3); let correct_det = complex_mat_inverse(&mut ai, &a).unwrap(); // lower - let (coo, csc, csr, det) = Samples::complex_symmetric_3x3_lower(false); + let (coo, csc, csr, det) = Samples::complex_symmetric_3x3_lower(); complex_approx_eq(det, correct_det, 1e-15); complex_mat_approx_eq(&coo.as_dense(), correct, 1e-15); complex_mat_approx_eq(&csc.as_dense(), correct, 1e-15); @@ -1553,14 +1538,10 @@ mod tests { let mut ai = Matrix::new(3, 3); let correct_det = mat_inverse(&mut ai, &a).unwrap(); for (coo, csc, csr, det) in [ - Samples::unsymmetric_3x3(false, false, false), - Samples::unsymmetric_3x3(false, true, false), - Samples::unsymmetric_3x3(false, true, false), - Samples::unsymmetric_3x3(false, true, true), - Samples::unsymmetric_3x3(true, false, false), - Samples::unsymmetric_3x3(true, true, false), - Samples::unsymmetric_3x3(true, true, false), - Samples::unsymmetric_3x3(true, true, true), + Samples::unsymmetric_3x3(false, false), + Samples::unsymmetric_3x3(false, true), + Samples::unsymmetric_3x3(true, false), + Samples::unsymmetric_3x3(true, true), ] { approx_eq(det, correct_det, 1e-13); mat_approx_eq(&coo.as_dense(), correct, 1e-15); @@ -1581,16 +1562,12 @@ mod tests { let a = Matrix::from(correct); let mut ai = Matrix::new(5, 5); let correct_det = mat_inverse(&mut ai, &a).unwrap(); - for (coo, csc, csr, det) in [ - Samples::umfpack_unsymmetric_5x5(false), - Samples::umfpack_unsymmetric_5x5(true), - ] { - approx_eq(det, correct_det, 1e-13); - mat_approx_eq(&coo.as_dense(), correct, 1e-15); - mat_approx_eq(&csc.as_dense(), correct, 1e-15); - mat_approx_eq(&csr.as_dense(), correct, 1e-15); - check(&coo, &csc, &csr); - } + let (coo, csc, csr, det) = Samples::umfpack_unsymmetric_5x5(); + approx_eq(det, correct_det, 1e-13); + mat_approx_eq(&coo.as_dense(), correct, 1e-15); + mat_approx_eq(&csc.as_dense(), correct, 1e-15); + mat_approx_eq(&csr.as_dense(), correct, 1e-15); + check(&coo, &csc, &csr); // ---------------------------------------------------------------------------- @@ -1604,15 +1581,12 @@ mod tests { let a = Matrix::from(correct); let mut ai = Matrix::new(5, 5); let correct_det = mat_inverse(&mut ai, &a).unwrap(); - for (coo, csc, csr, det) in [ - Samples::mkl_unsymmetric_5x5(false), // - ] { - approx_eq(det, correct_det, 1e-13); - mat_approx_eq(&coo.as_dense(), correct, 1e-15); - mat_approx_eq(&csc.as_dense(), correct, 1e-15); - mat_approx_eq(&csr.as_dense(), correct, 1e-15); - check(&coo, &csc, &csr); - } + let (coo, csc, csr, det) = Samples::mkl_unsymmetric_5x5(); + approx_eq(det, correct_det, 1e-13); + mat_approx_eq(&coo.as_dense(), correct, 1e-15); + mat_approx_eq(&csc.as_dense(), correct, 1e-15); + mat_approx_eq(&csr.as_dense(), correct, 1e-15); + check(&coo, &csc, &csr); // ---------------------------------------------------------------------------- @@ -1627,14 +1601,10 @@ mod tests { let mut ai = Matrix::new(5, 5); let correct_det = mat_inverse(&mut ai, &a).unwrap(); for (coo, csc, csr, det) in [ - Samples::block_unsymmetric_5x5(false, false, false), - Samples::block_unsymmetric_5x5(false, true, false), - Samples::block_unsymmetric_5x5(false, false, true), - Samples::block_unsymmetric_5x5(false, true, true), - Samples::block_unsymmetric_5x5(true, false, false), - Samples::block_unsymmetric_5x5(true, true, false), - Samples::block_unsymmetric_5x5(true, false, true), - Samples::block_unsymmetric_5x5(true, true, true), + Samples::block_unsymmetric_5x5(false, false), + Samples::block_unsymmetric_5x5(false, true), + Samples::block_unsymmetric_5x5(true, false), + Samples::block_unsymmetric_5x5(true, true), ] { approx_eq(det, correct_det, 1e-13); mat_approx_eq(&coo.as_dense(), correct, 1e-15); @@ -1656,28 +1626,17 @@ mod tests { let mut ai = Matrix::new(5, 5); let correct_det = mat_inverse(&mut ai, &a).unwrap(); for (coo, csc, csr, det) in [ - Samples::mkl_positive_definite_5x5_lower(false), - Samples::mkl_positive_definite_5x5_lower(true), - Samples::mkl_positive_definite_5x5_upper(false), - Samples::mkl_positive_definite_5x5_upper(true), - Samples::mkl_symmetric_5x5_lower(false, false, false), - Samples::mkl_symmetric_5x5_lower(false, true, false), - Samples::mkl_symmetric_5x5_lower(false, false, true), - Samples::mkl_symmetric_5x5_lower(false, true, true), - Samples::mkl_symmetric_5x5_lower(true, false, false), - Samples::mkl_symmetric_5x5_lower(true, true, false), - Samples::mkl_symmetric_5x5_lower(true, false, true), - Samples::mkl_symmetric_5x5_lower(true, true, true), - Samples::mkl_symmetric_5x5_upper(false, false, false), - Samples::mkl_symmetric_5x5_upper(false, true, false), - Samples::mkl_symmetric_5x5_upper(false, false, true), - Samples::mkl_symmetric_5x5_upper(false, true, true), - Samples::mkl_symmetric_5x5_upper(true, false, false), - Samples::mkl_symmetric_5x5_upper(true, true, false), - Samples::mkl_symmetric_5x5_upper(true, false, true), - Samples::mkl_symmetric_5x5_upper(true, true, true), - Samples::mkl_symmetric_5x5_full(false), - Samples::mkl_symmetric_5x5_full(true), + Samples::mkl_positive_definite_5x5_lower(), + Samples::mkl_positive_definite_5x5_upper(), + Samples::mkl_symmetric_5x5_lower(false, false), + Samples::mkl_symmetric_5x5_lower(false, true), + Samples::mkl_symmetric_5x5_lower(true, false), + Samples::mkl_symmetric_5x5_lower(true, true), + Samples::mkl_symmetric_5x5_upper(false, false), + Samples::mkl_symmetric_5x5_upper(false, true), + Samples::mkl_symmetric_5x5_upper(true, false), + Samples::mkl_symmetric_5x5_upper(true, true), + Samples::mkl_symmetric_5x5_full(), ] { approx_eq(det, correct_det, 1e-13); mat_approx_eq(&coo.as_dense(), correct, 1e-15); @@ -1690,14 +1649,10 @@ mod tests { let correct = &[[10.0, 20.0]]; for (coo, csc, csr, _) in [ - Samples::rectangular_1x2(false, false, false), - Samples::rectangular_1x2(false, true, false), - Samples::rectangular_1x2(false, false, true), - Samples::rectangular_1x2(false, true, true), - Samples::rectangular_1x2(true, false, false), - Samples::rectangular_1x2(true, true, false), - Samples::rectangular_1x2(true, false, true), - Samples::rectangular_1x2(true, true, true), + Samples::rectangular_1x2(false, false), + Samples::rectangular_1x2(false, true), + Samples::rectangular_1x2(true, false), + Samples::rectangular_1x2(true, true), ] { mat_approx_eq(&coo.as_dense(), correct, 1e-15); mat_approx_eq(&csc.as_dense(), correct, 1e-15); diff --git a/russell_sparse/src/solver_mumps.rs b/russell_sparse/src/solver_mumps.rs index 62fb3f90..b0fcdca0 100644 --- a/russell_sparse/src/solver_mumps.rs +++ b/russell_sparse/src/solver_mumps.rs @@ -170,6 +170,12 @@ pub struct SolverMUMPS { /// Time spent on solve in nanoseconds time_solve_ns: u128, + + /// Holds the (one-based/Fortran) row indices i + fortran_indices_i: Vec, + + /// Holds the (one-based/Fortran) column indices j + fortran_indices_j: Vec, } impl Drop for SolverMUMPS { @@ -207,6 +213,8 @@ impl SolverMUMPS { time_initialize_ns: 0, time_factorize_ns: 0, time_solve_ns: 0, + fortran_indices_i: Vec::new(), + fortran_indices_j: Vec::new(), }) } } @@ -238,9 +246,6 @@ impl LinSolTrait for SolverMUMPS { let coo = mat.get_coo()?; // check the COO matrix - if !coo.one_based { - return Err("the COO matrix must have one-based (FORTRAN) indices as required by MUMPS"); - } if coo.nrow != coo.ncol { return Err("the COO matrix must be square"); } @@ -263,6 +268,12 @@ impl LinSolTrait for SolverMUMPS { self.initialized_symmetry = coo.symmetry; self.initialized_ndim = coo.nrow; self.initialized_nnz = coo.nnz; + self.fortran_indices_i = vec![0; coo.nnz]; + self.fortran_indices_j = vec![0; coo.nnz]; + for k in 0..coo.nnz { + self.fortran_indices_i[k] = coo.indices_i[k] + 1; + self.fortran_indices_j[k] = coo.indices_j[k] + 1; + } } // configuration parameters @@ -316,8 +327,8 @@ impl LinSolTrait for SolverMUMPS { positive_definite, ndim, nnz, - coo.indices_i.as_ptr(), - coo.indices_j.as_ptr(), + self.fortran_indices_i.as_ptr(), + self.fortran_indices_j.as_ptr(), coo.values.as_ptr(), ); if status != SUCCESSFUL_EXIT { @@ -620,7 +631,7 @@ mod tests { assert!(!solver.factorized); // get COO matrix errors - let (_, csc, _, _) = Samples::tiny_1x1(true); + let (_, csc, _, _) = Samples::tiny_1x1(); let mut mat = SparseMatrix::from_csc(csc); assert_eq!( solver.factorize(&mut mat, None).err(), @@ -628,25 +639,19 @@ mod tests { ); // check COO matrix - let coo = CooMatrix::new(1, 1, 1, None, false).unwrap(); - let mut mat = SparseMatrix::from_coo(coo); - assert_eq!( - solver.factorize(&mut mat, None).err(), - Some("the COO matrix must have one-based (FORTRAN) indices as required by MUMPS") - ); - let (coo, _, _, _) = Samples::rectangular_1x2(true, false, false); + let (coo, _, _, _) = Samples::rectangular_1x2(true, false); let mut mat = SparseMatrix::from_coo(coo); assert_eq!( solver.factorize(&mut mat, None).err(), Some("the COO matrix must be square") ); - let coo = CooMatrix::new(1, 1, 1, None, true).unwrap(); + let coo = CooMatrix::new(1, 1, 1, None).unwrap(); let mut mat = SparseMatrix::from_coo(coo); assert_eq!( solver.factorize(&mut mat, None).err(), Some("the COO matrix must have at least one non-zero value") ); - let (coo, _, _, _) = Samples::mkl_symmetric_5x5_upper(true, false, false); + let (coo, _, _, _) = Samples::mkl_symmetric_5x5_upper(true, false); let mut mat = SparseMatrix::from_coo(coo); assert_eq!( solver.factorize(&mut mat, None).err(), @@ -654,14 +659,14 @@ mod tests { ); // check already factorized data - let mut coo = CooMatrix::new(2, 2, 2, None, true).unwrap(); + let mut coo = CooMatrix::new(2, 2, 2, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); coo.put(1, 1, 2.0).unwrap(); let mut mat = SparseMatrix::from_coo(coo); // ... factorize once => OK solver.factorize(&mut mat, None).unwrap(); // ... change matrix (symmetry) - let mut coo = CooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full)), true).unwrap(); + let mut coo = CooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full))).unwrap(); coo.put(0, 0, 1.0).unwrap(); coo.put(1, 1, 2.0).unwrap(); let mut mat = SparseMatrix::from_coo(coo); @@ -670,7 +675,7 @@ mod tests { Some("subsequent factorizations must use the same matrix (symmetry differs)") ); // ... change matrix (ndim) - let mut coo = CooMatrix::new(1, 1, 1, None, true).unwrap(); + let mut coo = CooMatrix::new(1, 1, 1, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); let mut mat = SparseMatrix::from_coo(coo); assert_eq!( @@ -678,7 +683,7 @@ mod tests { Some("subsequent factorizations must use the same matrix (ndim differs)") ); // ... change matrix (nnz) - let mut coo = CooMatrix::new(2, 2, 1, None, true).unwrap(); + let mut coo = CooMatrix::new(2, 2, 1, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); let mut mat = SparseMatrix::from_coo(coo); assert_eq!( @@ -690,7 +695,7 @@ mod tests { #[test] #[serial] fn factorize_fails_on_singular_matrix() { - let mut mat_singular = SparseMatrix::new_coo(5, 5, 2, None, true).unwrap(); + let mut mat_singular = SparseMatrix::new_coo(5, 5, 2, None).unwrap(); mat_singular.put(0, 0, 1.0).unwrap(); mat_singular.put(4, 4, 1.0).unwrap(); let mut solver = SolverMUMPS::new().unwrap(); @@ -703,7 +708,7 @@ mod tests { #[test] #[serial] fn solve_handles_errors() { - let mut coo = CooMatrix::new(2, 2, 2, None, true).unwrap(); + let mut coo = CooMatrix::new(2, 2, 2, None).unwrap(); coo.put(0, 0, 123.0).unwrap(); coo.put(1, 1, 456.0).unwrap(); let mut mat = SparseMatrix::from_coo(coo); @@ -729,7 +734,7 @@ mod tests { ); // wrong symmetry let rhs = Vector::new(2); - let mut coo_wrong = CooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full)), true).unwrap(); + let mut coo_wrong = CooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full))).unwrap(); coo_wrong.put(0, 0, 123.0).unwrap(); coo_wrong.put(1, 1, 456.0).unwrap(); let mut mat_wrong = SparseMatrix::from_coo(coo_wrong); @@ -739,7 +744,7 @@ mod tests { Err("solve must use the same matrix (symmetry differs)") ); // wrong ndim - let mut coo_wrong = CooMatrix::new(1, 1, 1, None, true).unwrap(); + let mut coo_wrong = CooMatrix::new(1, 1, 1, None).unwrap(); coo_wrong.put(0, 0, 123.0).unwrap(); let mut mat_wrong = SparseMatrix::from_coo(coo_wrong); mat_wrong.get_csc_or_from_coo().unwrap(); // make sure to convert to CSC (because we're not calling factorize on this wrong matrix) @@ -748,7 +753,7 @@ mod tests { Err("solve must use the same matrix (ndim differs)") ); // wrong nnz - let mut coo_wrong = CooMatrix::new(2, 2, 3, None, true).unwrap(); + let mut coo_wrong = CooMatrix::new(2, 2, 3, None).unwrap(); coo_wrong.put(0, 0, 123.0).unwrap(); coo_wrong.put(1, 1, 123.0).unwrap(); coo_wrong.put(0, 1, 100.0).unwrap(); @@ -773,7 +778,7 @@ mod tests { assert!(!solver.factorized); // sample matrix - let (coo, _, _, _) = Samples::umfpack_unsymmetric_5x5(true); + let (coo, _, _, _) = Samples::umfpack_unsymmetric_5x5(); let mut mat = SparseMatrix::from_coo(coo); // set params @@ -810,7 +815,7 @@ mod tests { vec_approx_eq(x_again.as_data(), x_correct, 1e-14); // solve with positive-definite matrix works - let (coo_pd_lower, _, _, _) = Samples::mkl_positive_definite_5x5_lower(true); + let (coo_pd_lower, _, _, _) = Samples::mkl_positive_definite_5x5_lower(); let mut mat_pd_lower = SparseMatrix::from_coo(coo_pd_lower); params.ordering = Ordering::Auto; params.scaling = Scaling::Auto; diff --git a/russell_sparse/src/solver_umfpack.rs b/russell_sparse/src/solver_umfpack.rs index 38ecc06d..eab1dd46 100644 --- a/russell_sparse/src/solver_umfpack.rs +++ b/russell_sparse/src/solver_umfpack.rs @@ -481,7 +481,7 @@ mod tests { assert!(!solver.factorized); // COO to CSC errors - let coo = CooMatrix::new(1, 1, 1, None, false).unwrap(); + let coo = CooMatrix::new(1, 1, 1, None).unwrap(); let mut mat = SparseMatrix::from_coo(coo); assert_eq!( solver.factorize(&mut mat, None).err(), @@ -495,7 +495,7 @@ mod tests { solver.factorize(&mut mat, None).err(), Some("the matrix must be square") ); - let (coo, _, _, _) = Samples::mkl_symmetric_5x5_lower(false, false, false); + let (coo, _, _, _) = Samples::mkl_symmetric_5x5_lower(false, false); let mut mat = SparseMatrix::from_coo(coo); assert_eq!( solver.factorize(&mut mat, None).err(), @@ -503,14 +503,14 @@ mod tests { ); // check already factorized data - let mut coo = CooMatrix::new(2, 2, 2, None, false).unwrap(); + let mut coo = CooMatrix::new(2, 2, 2, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); coo.put(1, 1, 2.0).unwrap(); let mut mat = SparseMatrix::from_coo(coo); // ... factorize once => OK solver.factorize(&mut mat, None).unwrap(); // ... change matrix (symmetry) - let mut coo = CooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full)), false).unwrap(); + let mut coo = CooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full))).unwrap(); coo.put(0, 0, 1.0).unwrap(); coo.put(1, 1, 2.0).unwrap(); let mut mat = SparseMatrix::from_coo(coo); @@ -519,7 +519,7 @@ mod tests { Some("subsequent factorizations must use the same matrix (symmetry differs)") ); // ... change matrix (ndim) - let mut coo = CooMatrix::new(1, 1, 1, None, false).unwrap(); + let mut coo = CooMatrix::new(1, 1, 1, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); let mut mat = SparseMatrix::from_coo(coo); assert_eq!( @@ -527,7 +527,7 @@ mod tests { Some("subsequent factorizations must use the same matrix (ndim differs)") ); // ... change matrix (nnz) - let mut coo = CooMatrix::new(2, 2, 1, None, false).unwrap(); + let mut coo = CooMatrix::new(2, 2, 1, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); let mut mat = SparseMatrix::from_coo(coo); assert_eq!( @@ -540,7 +540,7 @@ mod tests { fn factorize_works() { let mut solver = SolverUMFPACK::new().unwrap(); assert!(!solver.factorized); - let (coo, _, _, _) = Samples::umfpack_unsymmetric_5x5(false); + let (coo, _, _, _) = Samples::umfpack_unsymmetric_5x5(); let mut mat = SparseMatrix::from_coo(coo); let mut params = LinSolParams::new(); @@ -566,7 +566,7 @@ mod tests { #[test] fn factorize_fails_on_singular_matrix() { let mut solver = SolverUMFPACK::new().unwrap(); - let mut coo = CooMatrix::new(2, 2, 2, None, false).unwrap(); + let mut coo = CooMatrix::new(2, 2, 2, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); coo.put(1, 1, 0.0).unwrap(); let mut mat = SparseMatrix::from_coo(coo); @@ -575,7 +575,7 @@ mod tests { #[test] fn solve_handles_errors() { - let mut coo = CooMatrix::new(2, 2, 2, None, false).unwrap(); + let mut coo = CooMatrix::new(2, 2, 2, None).unwrap(); coo.put(0, 0, 123.0).unwrap(); coo.put(1, 1, 456.0).unwrap(); let mut mat = SparseMatrix::from_coo(coo); @@ -601,7 +601,7 @@ mod tests { ); // wrong symmetry let rhs = Vector::new(2); - let mut coo_wrong = CooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full)), false).unwrap(); + let mut coo_wrong = CooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full))).unwrap(); coo_wrong.put(0, 0, 123.0).unwrap(); coo_wrong.put(1, 1, 456.0).unwrap(); let mut mat_wrong = SparseMatrix::from_coo(coo_wrong); @@ -611,7 +611,7 @@ mod tests { Err("solve must use the same matrix (symmetry differs)") ); // wrong ndim - let mut coo_wrong = CooMatrix::new(1, 1, 1, None, false).unwrap(); + let mut coo_wrong = CooMatrix::new(1, 1, 1, None).unwrap(); coo_wrong.put(0, 0, 123.0).unwrap(); let mut mat_wrong = SparseMatrix::from_coo(coo_wrong); mat_wrong.get_csc_or_from_coo().unwrap(); // make sure to convert to CSC (because we're not calling factorize on this wrong matrix) @@ -620,7 +620,7 @@ mod tests { Err("solve must use the same matrix (ndim differs)") ); // wrong nnz - let mut coo_wrong = CooMatrix::new(2, 2, 3, None, false).unwrap(); + let mut coo_wrong = CooMatrix::new(2, 2, 3, None).unwrap(); coo_wrong.put(0, 0, 123.0).unwrap(); coo_wrong.put(1, 1, 123.0).unwrap(); coo_wrong.put(0, 1, 100.0).unwrap(); @@ -635,7 +635,7 @@ mod tests { #[test] fn solve_works() { let mut solver = SolverUMFPACK::new().unwrap(); - let (coo, _, _, _) = Samples::umfpack_unsymmetric_5x5(false); + let (coo, _, _, _) = Samples::umfpack_unsymmetric_5x5(); let mut mat = SparseMatrix::from_coo(coo); let mut x = Vector::new(5); let rhs = Vector::from(&[8.0, 45.0, -3.0, 3.0, 19.0]); diff --git a/russell_sparse/src/sparse_matrix.rs b/russell_sparse/src/sparse_matrix.rs index 2500ba59..c84ff200 100644 --- a/russell_sparse/src/sparse_matrix.rs +++ b/russell_sparse/src/sparse_matrix.rs @@ -59,16 +59,9 @@ where /// * `max_nnz` -- (≥ 1) Maximum number of entries ≥ nnz (number of non-zeros), /// including entries with repeated indices. (must be fit i32) /// * `symmetry` -- Defines the symmetry/storage, if any - /// * `one_based` -- Use one-based indices; e.g., for MUMPS or other FORTRAN routines - pub fn new_coo( - nrow: usize, - ncol: usize, - max_nnz: usize, - symmetry: Option, - one_based: bool, - ) -> Result { + pub fn new_coo(nrow: usize, ncol: usize, max_nnz: usize, symmetry: Option) -> Result { Ok(NumSparseMatrix { - coo: Some(NumCooMatrix::new(nrow, ncol, max_nnz, symmetry, one_based)?), + coo: Some(NumCooMatrix::new(nrow, ncol, max_nnz, symmetry)?), csc: None, csr: None, }) @@ -450,9 +443,9 @@ mod tests { #[test] fn new_functions_work() { // COO - NumSparseMatrix::::new_coo(1, 1, 1, None, false).unwrap(); + NumSparseMatrix::::new_coo(1, 1, 1, None).unwrap(); assert_eq!( - NumSparseMatrix::::new_coo(0, 1, 1, None, false).err(), + NumSparseMatrix::::new_coo(0, 1, 1, None).err(), Some("nrow must be ≥ 1") ); // CSC @@ -472,7 +465,7 @@ mod tests { #[test] fn getters_work() { // test matrices - let (coo, csc, csr, _) = Samples::rectangular_1x2(false, false, false); + let (coo, csc, csr, _) = Samples::rectangular_1x2(false, false); let mut a = Matrix::new(1, 2); let x = Vector::from(&[2.0, 1.0]); let mut wrong = Vector::new(2); @@ -520,9 +513,9 @@ mod tests { #[test] fn setters_work() { // test matrices - let (coo, csc, csr, _) = Samples::rectangular_1x2(false, false, false); - let mut other = NumSparseMatrix::::new_coo(1, 1, 1, None, false).unwrap(); - let mut wrong = NumSparseMatrix::::new_coo(1, 1, 3, None, false).unwrap(); + let (coo, csc, csr, _) = Samples::rectangular_1x2(false, false); + let mut other = NumSparseMatrix::::new_coo(1, 1, 1, None).unwrap(); + let mut wrong = NumSparseMatrix::::new_coo(1, 1, 3, None).unwrap(); other.put(0, 0, 2.0).unwrap(); wrong.put(0, 0, 1.0).unwrap(); wrong.put(0, 0, 2.0).unwrap(); @@ -532,7 +525,7 @@ mod tests { assert_eq!(coo_mat.get_coo_mut().unwrap().get_info(), (1, 2, 2, Symmetry::No)); assert_eq!(coo_mat.get_csc_mut().err(), Some("CSC matrix is not available")); assert_eq!(coo_mat.get_csr_mut().err(), Some("CSR matrix is not available")); - let mut empty = NumSparseMatrix::::new_coo(1, 1, 1, None, false).unwrap(); + let mut empty = NumSparseMatrix::::new_coo(1, 1, 1, None).unwrap(); assert_eq!(empty.get_csc_or_from_coo().err(), Some("COO to CSC requires nnz > 0")); assert_eq!(empty.get_csr_or_from_coo().err(), Some("COO to CSR requires nnz > 0")); // CSC @@ -594,7 +587,7 @@ mod tests { Some("COO matrix is not available to augment") ); // COO - let mut coo = NumSparseMatrix::::new_coo(2, 2, 1, None, false).unwrap(); + let mut coo = NumSparseMatrix::::new_coo(2, 2, 1, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); assert_eq!( coo.put(1, 1, 2.0).err(), @@ -603,7 +596,7 @@ mod tests { coo.reset().unwrap(); coo.put(1, 1, 2.0).unwrap(); // COO (assign) - let mut this = NumSparseMatrix::::new_coo(1, 1, 1, None, false).unwrap(); + let mut this = NumSparseMatrix::::new_coo(1, 1, 1, None).unwrap(); this.put(0, 0, 8000.0).unwrap(); this.assign(4.0, &other).unwrap(); assert_eq!( @@ -618,7 +611,7 @@ mod tests { ); assert_eq!(this.assign(2.0, &csc_mat).err(), Some("COO matrix is not available")); // COO (augment) - let mut this = NumSparseMatrix::::new_coo(1, 1, 1 + 1, None, false).unwrap(); + let mut this = NumSparseMatrix::::new_coo(1, 1, 1 + 1, None).unwrap(); this.put(0, 0, 100.0).unwrap(); this.augment(4.0, &other).unwrap(); assert_eq!( @@ -635,7 +628,7 @@ mod tests { // ┌ ┐ // │ 10 20 │ // └ ┘ - let (coo, _, _, _) = Samples::rectangular_1x2(false, false, false); + let (coo, _, _, _) = Samples::rectangular_1x2(false, false); let mut mat = NumSparseMatrix::::from_coo(coo); let csc = mat.get_csc_or_from_coo().unwrap(); // will create a new csc assert_eq!(csc.get_values(), &[10.0, 20.0]); @@ -651,7 +644,7 @@ mod tests { // ┌ ┐ // │ 10 20 │ // └ ┘ - let (coo, _, _, _) = Samples::rectangular_1x2(false, false, false); + let (coo, _, _, _) = Samples::rectangular_1x2(false, false); let mut mat = NumSparseMatrix::::from_coo(coo); let csr = mat.get_csr_or_from_coo().unwrap(); // will create a new csr assert_eq!(csr.get_values(), &[10.0, 20.0]); @@ -664,7 +657,7 @@ mod tests { #[test] fn derive_methods_work() { - let (coo, _, _, _) = Samples::tiny_1x1(false); + let (coo, _, _, _) = Samples::tiny_1x1(); let (nrow, ncol, nnz, symmetry) = coo.get_info(); let mat = NumSparseMatrix::::from_coo(coo); let mut clone = mat.clone(); @@ -675,7 +668,7 @@ mod tests { let json = serde_json::to_string(&mat).unwrap(); assert_eq!( json, - r#"{"coo":{"symmetry":"No","nrow":1,"ncol":1,"nnz":1,"max_nnz":1,"indices_i":[0],"indices_j":[0],"values":[123.0],"one_based":false},"csc":null,"csr":null}"# + r#"{"coo":{"symmetry":"No","nrow":1,"ncol":1,"nnz":1,"max_nnz":1,"indices_i":[0],"indices_j":[0],"values":[123.0]},"csc":null,"csr":null}"# ); let from_json: NumSparseMatrix = serde_json::from_str(&json).unwrap(); let (json_nrow, json_ncol, json_nnz, json_symmetry) = from_json.get_coo().unwrap().get_info(); diff --git a/russell_sparse/src/verify_lin_sys.rs b/russell_sparse/src/verify_lin_sys.rs index cee89b54..dca60b51 100644 --- a/russell_sparse/src/verify_lin_sys.rs +++ b/russell_sparse/src/verify_lin_sys.rs @@ -32,7 +32,7 @@ impl VerifyLinSys { /// fn main() -> Result<(), StrError> { /// // set sparse matrix (3 x 3) with 4 non-zeros /// let (nrow, ncol, nnz) = (3, 3, 4); - /// let mut coo = SparseMatrix::new_coo(nrow, ncol, nnz, None, false)?; + /// let mut coo = SparseMatrix::new_coo(nrow, ncol, nnz, None)?; /// coo.put(0, 0, 1.0)?; /// coo.put(0, 2, 4.0)?; /// coo.put(1, 1, 2.0)?; @@ -159,7 +159,7 @@ mod tests { #[test] fn from_captures_errors() { // real - let coo = SparseMatrix::new_coo(2, 1, 1, None, false).unwrap(); + let coo = SparseMatrix::new_coo(2, 1, 1, None).unwrap(); let x = Vector::new(1); let rhs = Vector::new(2); assert_eq!(VerifyLinSys::from(&coo, &x, &rhs).err(), Some("matrix is empty")); @@ -174,7 +174,7 @@ mod tests { Some("rhs.dim() must be equal to nrow") ); // complex - let coo = ComplexSparseMatrix::new_coo(2, 1, 1, None, false).unwrap(); + let coo = ComplexSparseMatrix::new_coo(2, 1, 1, None).unwrap(); let x = ComplexVector::new(1); let rhs = ComplexVector::new(2); assert_eq!( @@ -198,7 +198,7 @@ mod tests { // 1 3 -2 // 3 5 6 // 2 4 3 - let mut coo = SparseMatrix::new_coo(3, 3, 9, None, false).unwrap(); + let mut coo = SparseMatrix::new_coo(3, 3, 9, None).unwrap(); coo.put(0, 0, 1.0).unwrap(); coo.put(0, 1, 3.0).unwrap(); coo.put(0, 2, -2.0).unwrap(); diff --git a/russell_sparse/src/write_matrix_market.rs b/russell_sparse/src/write_matrix_market.rs index d8028296..cacd2580 100644 --- a/russell_sparse/src/write_matrix_market.rs +++ b/russell_sparse/src/write_matrix_market.rs @@ -158,7 +158,7 @@ mod tests { // . -1 -3 2 . // . . 1 . . // . 4 2 . 1 - let (_, csc, _, _) = Samples::umfpack_unsymmetric_5x5(false); + let (_, csc, _, _) = Samples::umfpack_unsymmetric_5x5(); let full_path = "/tmp/russell_sparse/test_write_matrix_market_csc.mtx"; csc_write_matrix_market(&csc, full_path, false).unwrap(); let contents = fs::read_to_string(full_path).map_err(|_| "cannot open file").unwrap(); @@ -182,7 +182,7 @@ mod tests { // 2 -1 2 sym // -1 2 -1 => -1 2 // -1 2 -1 2 - let (_, csc, _, _) = Samples::positive_definite_3x3(false); + let (_, csc, _, _) = Samples::positive_definite_3x3(); let full_path = "/tmp/russell_sparse/test_write_matrix_market_csc.mtx"; csc_write_matrix_market(&csc, full_path, false).unwrap(); let contents = fs::read_to_string(full_path).map_err(|_| "cannot open file").unwrap(); @@ -205,7 +205,7 @@ mod tests { // . -1 -3 2 . // . . 1 . . // . 4 2 . 1 - let (_, _, csr, _) = Samples::umfpack_unsymmetric_5x5(false); + let (_, _, csr, _) = Samples::umfpack_unsymmetric_5x5(); let full_path = "/tmp/russell_sparse/test_write_matrix_market_csr.mtx"; csr_write_matrix_market(&csr, full_path, false).unwrap(); let contents = fs::read_to_string(full_path).map_err(|_| "cannot open file").unwrap(); @@ -229,7 +229,7 @@ mod tests { // 2 -1 2 sym // -1 2 -1 => -1 2 // -1 2 -1 2 - let (_, _, csr, _) = Samples::positive_definite_3x3(false); + let (_, _, csr, _) = Samples::positive_definite_3x3(); let full_path = "/tmp/russell_sparse/test_write_matrix_market_csr.mtx"; csr_write_matrix_market(&csr, full_path, false).unwrap(); let contents = fs::read_to_string(full_path).map_err(|_| "cannot open file").unwrap(); diff --git a/russell_sparse/tests/test_complex_coo_matrix.rs b/russell_sparse/tests/test_complex_coo_matrix.rs index 5fd24373..b10abf12 100644 --- a/russell_sparse/tests/test_complex_coo_matrix.rs +++ b/russell_sparse/tests/test_complex_coo_matrix.rs @@ -6,7 +6,7 @@ use russell_sparse::StrError; #[test] fn test_complex_coo_matrix() -> Result<(), StrError> { let sym = Some(Symmetry::new_general_lower()); - let mut coo = ComplexCooMatrix::new(3, 3, 4, sym, false)?; + let mut coo = ComplexCooMatrix::new(3, 3, 4, sym)?; coo.put(0, 0, cpx!(1.0, 0.1))?; coo.put(1, 0, cpx!(2.0, 0.2))?; coo.put(1, 1, cpx!(3.0, 0.3))?; diff --git a/russell_sparse/tests/test_complex_mumps.rs b/russell_sparse/tests/test_complex_mumps.rs index 05f7d9ed..0f881481 100644 --- a/russell_sparse/tests/test_complex_mumps.rs +++ b/russell_sparse/tests/test_complex_mumps.rs @@ -9,7 +9,7 @@ use serial_test::serial; fn test_complex_mumps() -> Result<(), StrError> { let n = 10; let d = (n as f64) / 10.0; - let mut coo = ComplexCooMatrix::new(n, n, n, None, true)?; + let mut coo = ComplexCooMatrix::new(n, n, n, None)?; let mut x_correct = ComplexVector::new(n); let mut rhs = ComplexVector::new(n); for k in 0..n { diff --git a/russell_sparse/tests/test_complex_umfpack.rs b/russell_sparse/tests/test_complex_umfpack.rs index e1747dce..07dc2063 100644 --- a/russell_sparse/tests/test_complex_umfpack.rs +++ b/russell_sparse/tests/test_complex_umfpack.rs @@ -7,7 +7,7 @@ use russell_sparse::StrError; fn test_complex_umfpack() -> Result<(), StrError> { let n = 10; let d = (n as f64) / 10.0; - let mut coo = ComplexCooMatrix::new(n, n, n, None, false)?; + let mut coo = ComplexCooMatrix::new(n, n, n, None)?; let mut x_correct = ComplexVector::new(n); let mut rhs = ComplexVector::new(n); for k in 0..n { diff --git a/russell_sparse/tests/test_mumps.rs b/russell_sparse/tests/test_mumps.rs index b85bc5b9..58d770d1 100644 --- a/russell_sparse/tests/test_mumps.rs +++ b/russell_sparse/tests/test_mumps.rs @@ -8,7 +8,7 @@ use serial_test::serial; fn test_complex_umfpack() -> Result<(), StrError> { let n = 10; let d = (n as f64) / 10.0; - let mut coo = CooMatrix::new(n, n, n, None, true)?; + let mut coo = CooMatrix::new(n, n, n, None)?; let mut x_correct = Vector::new(n); let mut rhs = Vector::new(n); for k in 0..n { diff --git a/russell_sparse/tests/test_nonlinear_system.rs b/russell_sparse/tests/test_nonlinear_system.rs index 845ec9f4..7312072d 100644 --- a/russell_sparse/tests/test_nonlinear_system.rs +++ b/russell_sparse/tests/test_nonlinear_system.rs @@ -67,7 +67,7 @@ fn check_jacobian() { } } let nnz = neq * neq; - let mut jj_tri = CooMatrix::new(neq, neq, nnz, None, false).unwrap(); + let mut jj_tri = CooMatrix::new(neq, neq, nnz, None).unwrap(); calc_jacobian(&mut jj_tri, &uu).unwrap(); let mut jj_ana = Matrix::new(neq, neq); jj_tri.to_dense(&mut jj_ana).unwrap(); @@ -75,10 +75,9 @@ fn check_jacobian() { } fn solve_nonlinear_system(genie: Genie) -> Result<(), StrError> { - let one_based = if genie == Genie::Mumps { true } else { false }; let (neq, nnz) = (4, 16); let mut solver = LinSolver::new(genie)?; - let mut jj = SparseMatrix::new_coo(neq, neq, nnz, None, one_based).unwrap(); + let mut jj = SparseMatrix::new_coo(neq, neq, nnz, None).unwrap(); let mut rr = Vector::new(neq); let mut uu = Vector::from(&[0.0, 0.0, 0.0, 0.0]); let mut mdu = Vector::new(neq); diff --git a/russell_sparse/tests/test_umfpack.rs b/russell_sparse/tests/test_umfpack.rs index ee31e1f8..76761946 100644 --- a/russell_sparse/tests/test_umfpack.rs +++ b/russell_sparse/tests/test_umfpack.rs @@ -6,7 +6,7 @@ use russell_sparse::StrError; fn test_complex_umfpack() -> Result<(), StrError> { let n = 10; let d = (n as f64) / 10.0; - let mut coo = CooMatrix::new(n, n, n, None, false)?; + let mut coo = CooMatrix::new(n, n, n, None)?; let mut x_correct = Vector::new(n); let mut rhs = Vector::new(n); for k in 0..n {