Skip to content

Commit

Permalink
[sparse] Rename sym flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cpmech committed Mar 9, 2024
1 parent b9a8254 commit 36b3ce1
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 55 deletions.
4 changes: 2 additions & 2 deletions russell_sparse/examples/doc_coo_from_arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ fn main() -> Result<(), StrError> {
let values = vec![
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)?;
let sym = None;
let coo = CooMatrix::from(nrow, ncol, row_indices, col_indices, values, sym)?;

// covert to dense
let a = coo.as_dense();
Expand Down
4 changes: 2 additions & 2 deletions russell_sparse/examples/doc_csc_from_arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fn main() -> Result<(), StrError> {
6.0, 1.0, // j = 4, count = 10, 11,
// 12
];
let symmetry = None;
let csc = CscMatrix::new(nrow, ncol, col_pointers, row_indices, values, symmetry)?;
let sym = None;
let csc = CscMatrix::new(nrow, ncol, col_pointers, row_indices, values, sym)?;

// covert to dense
let a = csc.as_dense();
Expand Down
4 changes: 2 additions & 2 deletions russell_sparse/examples/doc_csr_from_arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fn main() -> Result<(), StrError> {
4.0, 2.0, 1.0, // i = 4, count = 9, 10, 11
// count = 12
];
let symmetry = None;
let csr = CsrMatrix::new(nrow, ncol, row_pointers, col_indices, values, symmetry)?;
let sym = None;
let csr = CsrMatrix::new(nrow, ncol, row_pointers, col_indices, values, sym)?;

// covert to dense
let a = csr.as_dense();
Expand Down
4 changes: 2 additions & 2 deletions russell_sparse/src/bin/solve_matrix_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ fn main() -> Result<(), StrError> {
let mut mat = SparseMatrix::from_coo(coo);

// save information about the matrix
let (nrow, ncol, nnz, symmetry) = mat.get_info();
let (nrow, ncol, nnz, sym) = mat.get_info();
stats.set_matrix_name_from_path(&opt.matrix_market_file);
stats.matrix.nrow = nrow;
stats.matrix.ncol = ncol;
stats.matrix.nnz = nnz;
stats.matrix.symmetry = format!("{:?}", symmetry);
stats.matrix.symmetry = format!("{:?}", sym);

// allocate and configure the solver
let mut solver = LinSolver::new(genie)?;
Expand Down
2 changes: 1 addition & 1 deletion russell_sparse/src/complex_lin_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait ComplexLinSolTrait {
///
/// # Notes
///
/// 1. The structure of the matrix (nrow, ncol, nnz, symmetry) must be
/// 1. The structure of the matrix (nrow, ncol, nnz, sym) must be
/// exactly the same among multiple calls to `factorize`. The values may differ
/// from call to call, nonetheless.
/// 2. The first call to `factorize` will define the structure which must be
Expand Down
6 changes: 3 additions & 3 deletions russell_sparse/src/complex_solver_mumps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl ComplexLinSolTrait for ComplexSolverMUMPS {
///
/// # Notes
///
/// 1. The structure of the matrix (nrow, ncol, nnz, symmetry) must be
/// 1. The structure of the matrix (nrow, ncol, nnz, sym) must be
/// exactly the same among multiple calls to `factorize`. The values may differ
/// from call to call, nonetheless.
/// 2. The first call to `factorize` will define the structure which must be
Expand Down Expand Up @@ -362,8 +362,8 @@ impl ComplexLinSolTrait for ComplexSolverMUMPS {
let coo = mat.get_coo()?;

// check already factorized data
let (nrow, ncol, nnz, symmetry) = coo.get_info();
if symmetry != self.initialized_symmetry {
let (nrow, ncol, nnz, sym) = coo.get_info();
if sym != self.initialized_symmetry {
return Err("solve must use the same matrix (symmetry differs)");
}
if nrow != self.initialized_ndim || ncol != self.initialized_ndim {
Expand Down
6 changes: 3 additions & 3 deletions russell_sparse/src/complex_solver_umfpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl ComplexLinSolTrait for ComplexSolverUMFPACK {
///
/// # Notes
///
/// 1. The structure of the matrix (nrow, ncol, nnz, symmetry) must be
/// 1. The structure of the matrix (nrow, ncol, nnz, sym) must be
/// exactly the same among multiple calls to `factorize`. The values may differ
/// from call to call, nonetheless.
/// 2. The first call to `factorize` will define the structure which must be
Expand Down Expand Up @@ -325,8 +325,8 @@ impl ComplexLinSolTrait for ComplexSolverUMFPACK {
let csc = mat.get_csc()?;

// check already factorized data
let (nrow, ncol, nnz, symmetry) = csc.get_info();
if symmetry != self.initialized_symmetry {
let (nrow, ncol, nnz, sym) = csc.get_info();
if sym != self.initialized_symmetry {
return Err("solve must use the same matrix (symmetry differs)");
}
if nrow != self.initialized_ndim || ncol != self.initialized_ndim {
Expand Down
18 changes: 9 additions & 9 deletions russell_sparse/src/coo_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ where
/// let values = vec![
/// 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)?;
/// let sym = None;
/// let coo = CooMatrix::from(nrow, ncol, row_indices, col_indices, values, sym)?;
///
/// // covert to dense
/// let a = coo.as_dense();
Expand Down Expand Up @@ -371,11 +371,11 @@ where
/// │ 0 0 3 │\n\
/// └ ┘";
/// coo.reset();
/// let (nrow, ncol, nnz, symmetry) = coo.get_info();
/// let (nrow, ncol, nnz, sym) = coo.get_info();
/// assert_eq!(nrow, 3);
/// assert_eq!(ncol, 3);
/// assert_eq!(nnz, 0);
/// assert_eq!(symmetry, Symmetry::No);
/// assert_eq!(sym, Sym::No);
/// Ok(())
/// }
/// ```
Expand Down Expand Up @@ -616,7 +616,7 @@ where

/// Returns information about the dimensions and symmetry type
///
/// Returns `(nrow, ncol, nnz, symmetry)`
/// Returns `(nrow, ncol, nnz, sym)`
///
/// # Example
///
Expand All @@ -626,11 +626,11 @@ where
///
/// fn main() -> Result<(), StrError> {
/// let coo = CooMatrix::new(1, 2, 3, None)?;
/// let (nrow, ncol, nnz, symmetry) = coo.get_info();
/// let (nrow, ncol, nnz, sym) = coo.get_info();
/// assert_eq!(nrow, 1);
/// assert_eq!(ncol, 2);
/// assert_eq!(nnz, 0);
/// assert_eq!(symmetry, Symmetry::No);
/// assert_eq!(sym, Sym::No);
/// Ok(())
/// }
/// ```
Expand Down Expand Up @@ -752,11 +752,11 @@ mod tests {
#[test]
fn get_info_works() {
let coo = NumCooMatrix::<f32>::new(1, 2, 10, None).unwrap();
let (nrow, ncol, nnz, symmetry) = coo.get_info();
let (nrow, ncol, nnz, sym) = coo.get_info();
assert_eq!(nrow, 1);
assert_eq!(ncol, 2);
assert_eq!(nnz, 0);
assert_eq!(symmetry, Sym::No);
assert_eq!(sym, Sym::No);
}

#[test]
Expand Down
13 changes: 6 additions & 7 deletions russell_sparse/src/csc_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ where
/// 6.0, 1.0, // j = 4, count = 10, 11,
/// // 12
/// ];
/// let symmetry = None;
/// let csc = CscMatrix::new(nrow, ncol, col_pointers, row_indices, values, symmetry)?;
/// let sym = None;
/// let csc = CscMatrix::new(nrow, ncol, col_pointers, row_indices, values, sym)?;
///
/// // covert to dense
/// let a = csc.as_dense();
Expand Down Expand Up @@ -611,9 +611,8 @@ where
/// 6.0, 1.0, // j = 4, count = 10, 11,
/// // 12
/// ];
/// let symmetry = None;
/// let csc = CscMatrix::new(nrow, ncol,
/// col_pointers, row_indices, values, symmetry)?;
/// let sym = None;
/// let csc = CscMatrix::new(nrow, ncol, col_pointers, row_indices, values, sym)?;
///
/// // covert to dense
/// let a = csc.as_dense();
Expand Down Expand Up @@ -767,11 +766,11 @@ where
/// let values = vec![10.0, 20.0];
/// let csc = CscMatrix::new(1, 2,
/// col_pointers, row_indices, values, None)?;
/// let (nrow, ncol, nnz, symmetry) = csc.get_info();
/// let (nrow, ncol, nnz, sym) = csc.get_info();
/// assert_eq!(nrow, 1);
/// assert_eq!(ncol, 2);
/// assert_eq!(nnz, 2);
/// assert_eq!(symmetry, Symmetry::No);
/// assert_eq!(sym, Sym::No);
/// let a = csc.as_dense();
/// let correct = "┌ ┐\n\
/// │ 10 20 │\n\
Expand Down
4 changes: 2 additions & 2 deletions russell_sparse/src/csr_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,11 @@ where
/// let values = vec![10.0, 20.0];
/// let csr = CsrMatrix::new(1, 2,
/// row_pointers, col_indices, values, None)?;
/// let (nrow, ncol, nnz, symmetry) = csr.get_info();
/// let (nrow, ncol, nnz, sym) = csr.get_info();
/// assert_eq!(nrow, 1);
/// assert_eq!(ncol, 2);
/// assert_eq!(nnz, 2);
/// assert_eq!(symmetry, Symmetry::No);
/// assert_eq!(sym, Sym::No);
/// let a = csr.as_dense();
/// let correct = "┌ ┐\n\
/// │ 10 20 │\n\
Expand Down
2 changes: 1 addition & 1 deletion russell_sparse/src/lin_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait LinSolTrait {
///
/// # Notes
///
/// 1. The structure of the matrix (nrow, ncol, nnz, symmetry) must be
/// 1. The structure of the matrix (nrow, ncol, nnz, sym) must be
/// exactly the same among multiple calls to `factorize`. The values may differ
/// from call to call, nonetheless.
/// 2. The first call to `factorize` will define the structure which must be
Expand Down
8 changes: 4 additions & 4 deletions russell_sparse/src/read_matrix_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ impl MatrixMarketData {
/// fn main() -> Result<(), StrError> {
/// let name = "./data/matrix_market/ok_simple_general.mtx";
/// let coo = read_matrix_market(name, MMsymOption::LeaveAsLower)?;
/// let (nrow, ncol, nnz, symmetry) = coo.get_info();
/// let (nrow, ncol, nnz, sym) = coo.get_info();
/// assert_eq!(nrow, 3);
/// assert_eq!(ncol, 3);
/// assert_eq!(nnz, 5);
/// assert_eq!(symmetry, Symmetry::No);
/// assert_eq!(sym, Sym::No);
/// let a = coo.as_dense();
/// let correct = "┌ ┐\n\
/// │ 1 2 0 │\n\
Expand Down Expand Up @@ -304,11 +304,11 @@ impl MatrixMarketData {
/// fn main() -> Result<(), StrError> {
/// let name = "./data/matrix_market/ok_simple_symmetric.mtx";
/// let coo = read_matrix_market(name, MMsymOption::LeaveAsLower)?;
/// let (nrow, ncol, nnz, symmetry) = coo.get_info();
/// let (nrow, ncol, nnz, sym) = coo.get_info();
/// assert_eq!(nrow, 3);
/// assert_eq!(ncol, 3);
/// assert_eq!(nnz, 4);
/// assert_eq!(symmetry, Symmetry::General(Storage::Lower));
/// assert_eq!(sym, Sym::General(Storage::Lower));
/// let a = coo.as_dense();
/// let correct = "┌ ┐\n\
/// │ 1 2 0 │\n\
Expand Down
6 changes: 3 additions & 3 deletions russell_sparse/src/solver_mumps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl LinSolTrait for SolverMUMPS {
///
/// # Notes
///
/// 1. The structure of the matrix (nrow, ncol, nnz, symmetry) must be
/// 1. The structure of the matrix (nrow, ncol, nnz, sym) must be
/// exactly the same among multiple calls to `factorize`. The values may differ
/// from call to call, nonetheless.
/// 2. The first call to `factorize` will define the structure which must be
Expand Down Expand Up @@ -392,8 +392,8 @@ impl LinSolTrait for SolverMUMPS {
let coo = mat.get_coo()?;

// check already factorized data
let (nrow, ncol, nnz, symmetry) = coo.get_info();
if symmetry != self.initialized_symmetry {
let (nrow, ncol, nnz, sym) = coo.get_info();
if sym != self.initialized_symmetry {
return Err("solve must use the same matrix (symmetry differs)");
}
if nrow != self.initialized_ndim || ncol != self.initialized_ndim {
Expand Down
6 changes: 3 additions & 3 deletions russell_sparse/src/solver_umfpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl LinSolTrait for SolverUMFPACK {
///
/// # Notes
///
/// 1. The structure of the matrix (nrow, ncol, nnz, symmetry) must be
/// 1. The structure of the matrix (nrow, ncol, nnz, sym) must be
/// exactly the same among multiple calls to `factorize`. The values may differ
/// from call to call, nonetheless.
/// 2. The first call to `factorize` will define the structure which must be
Expand Down Expand Up @@ -304,8 +304,8 @@ impl LinSolTrait for SolverUMFPACK {
let csc = mat.get_csc()?;

// check already factorized data
let (nrow, ncol, nnz, symmetry) = csc.get_info();
if symmetry != self.initialized_symmetry {
let (nrow, ncol, nnz, sym) = csc.get_info();
if sym != self.initialized_symmetry {
return Err("solve must use the same matrix (symmetry differs)");
}
if nrow != self.initialized_ndim || ncol != self.initialized_ndim {
Expand Down
14 changes: 7 additions & 7 deletions russell_sparse/src/sparse_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ where
/// * `ncol` -- (≥ 1) Is the number of columns of the sparse matrix (must be fit i32)
/// * `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
pub fn new_coo(nrow: usize, ncol: usize, max_nnz: usize, symmetry: Option<Sym>) -> Result<Self, StrError> {
/// * `sym` -- Defines the symmetry/storage, if any
pub fn new_coo(nrow: usize, ncol: usize, max_nnz: usize, sym: Option<Sym>) -> Result<Self, StrError> {
Ok(NumSparseMatrix {
coo: Some(NumCooMatrix::new(nrow, ncol, max_nnz, symmetry)?),
coo: Some(NumCooMatrix::new(nrow, ncol, max_nnz, sym)?),
csc: None,
csr: None,
})
Expand Down Expand Up @@ -190,7 +190,7 @@ where

/// Returns information about the dimensions and symmetry type
///
/// Returns `(nrow, ncol, nnz, symmetry)`
/// Returns `(nrow, ncol, nnz, sym)`
///
/// **Priority**: CSC -> CSR -> COO
pub fn get_info(&self) -> (usize, usize, usize, Sym) {
Expand Down Expand Up @@ -652,7 +652,7 @@ mod tests {
#[test]
fn derive_methods_work() {
let (coo, _, _, _) = Samples::tiny_1x1();
let (nrow, ncol, nnz, symmetry) = coo.get_info();
let (nrow, ncol, nnz, sym) = coo.get_info();
let mat = NumSparseMatrix::<f64>::from_coo(coo);
let mut clone = mat.clone();
clone.get_coo_mut().unwrap().values[0] *= 2.0;
Expand All @@ -665,8 +665,8 @@ mod tests {
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<f64> = serde_json::from_str(&json).unwrap();
let (json_nrow, json_ncol, json_nnz, json_symmetry) = from_json.get_coo().unwrap().get_info();
assert_eq!(json_symmetry, symmetry);
let (json_nrow, json_ncol, json_nnz, json_sym) = from_json.get_coo().unwrap().get_info();
assert_eq!(json_sym, sym);
assert_eq!(json_nrow, nrow);
assert_eq!(json_ncol, ncol);
assert_eq!(json_nnz, nnz);
Expand Down
8 changes: 4 additions & 4 deletions russell_sparse/src/write_matrix_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ where
let d = if vismatrix { 0 } else { 1 };

// info
let (nrow, ncol, nnz, symmetry) = mat.get_info();
let (nrow, ncol, nnz, sym) = mat.get_info();

// write header
if !vismatrix {
if symmetry == Sym::No {
if sym == Sym::No {
write!(&mut buffer, "%%MatrixMarket matrix coordinate real general\n").unwrap();
} else {
write!(&mut buffer, "%%MatrixMarket matrix coordinate real symmetric\n").unwrap();
Expand Down Expand Up @@ -99,11 +99,11 @@ where
let d = if vismatrix { 0 } else { 1 };

// info
let (nrow, ncol, nnz, symmetry) = mat.get_info();
let (nrow, ncol, nnz, sym) = mat.get_info();

// write header
if !vismatrix {
if symmetry == Sym::No {
if sym == Sym::No {
write!(&mut buffer, "%%MatrixMarket matrix coordinate real general\n").unwrap();
} else {
write!(&mut buffer, "%%MatrixMarket matrix coordinate real symmetric\n").unwrap();
Expand Down

0 comments on commit 36b3ce1

Please sign in to comment.