diff --git a/README.md b/README.md
index 5c80b892..6eca0b0e 100644
--- a/README.md
+++ b/README.md
@@ -122,14 +122,14 @@ fn main() -> Result<(), StrError> {
```rust
use russell_lab::{Matrix, Vector, StrError};
-use russell_sparse::{ConfigSolver, Solver, SparseTriplet};
+use russell_sparse::{ConfigSolver, Solver, CooMatrix};
fn main() -> Result<(), StrError> {
// allocate a square matrix
let neq = 5; // number of equations
let nnz = 13; // number of non-zeros
- let mut trip = SparseTriplet::new(neq, nnz)?;
+ let mut trip = CooMatrix::new(neq, nnz)?;
trip.put(0, 0, 1.0)?; // << (0, 0, a00/2)
trip.put(0, 0, 1.0)?; // << (0, 0, a00/2)
trip.put(1, 0, 3.0)?;
diff --git a/russell_sparse/README.md b/russell_sparse/README.md
index 1ad11e8d..56a0d800 100644
--- a/russell_sparse/README.md
+++ b/russell_sparse/README.md
@@ -65,13 +65,13 @@ export OPENBLAS_NUM_THREADS=1
```rust
use russell_lab::{Matrix, Vector};
-use russell_sparse::{ConfigSolver, Solver, SparseTriplet, StrError};
+use russell_sparse::{ConfigSolver, Solver, CooMatrix, StrError};
fn main() -> Result<(), StrError> {
// allocate a square matrix
let neq = 3; // number of equations
let nnz = 5; // number of non-zeros
- let mut trip = SparseTriplet::new(neq, nnz)?;
+ let mut trip = CooMatrix::new(neq, nnz)?;
trip.put(0, 0, 0.2)?;
trip.put(0, 1, 0.2)?;
trip.put(1, 0, 0.5)?;
diff --git a/russell_sparse/src/bin/mem_check_build.rs b/russell_sparse/src/bin/mem_check_build.rs
index 918725f0..c1090d94 100644
--- a/russell_sparse/src/bin/mem_check_build.rs
+++ b/russell_sparse/src/bin/mem_check_build.rs
@@ -1,5 +1,5 @@
use russell_lab::Vector;
-use russell_sparse::{ConfigSolver, LinSolKind, Solver, SparseTriplet};
+use russell_sparse::{ConfigSolver, CooMatrix, LinSolKind, Solver};
fn test_solver(name: LinSolKind) {
match name {
@@ -9,7 +9,7 @@ fn test_solver(name: LinSolKind) {
let (neq, nnz) = (5, 13);
- let mut trip = match SparseTriplet::new(neq, nnz) {
+ let mut trip = match CooMatrix::new(neq, nnz) {
Ok(v) => v,
Err(e) => {
println!("FAIL(new triplet): {}", e);
@@ -81,7 +81,7 @@ fn test_solver_singular(name: LinSolKind) {
let (neq, nnz) = (2, 2);
- let trip_singular = match SparseTriplet::new(neq, nnz) {
+ let trip_singular = match CooMatrix::new(neq, nnz) {
Ok(v) => v,
Err(e) => {
println!("FAIL(new triplet): {}", e);
diff --git a/russell_sparse/src/lib.rs b/russell_sparse/src/lib.rs
index 44b64f29..4e768695 100644
--- a/russell_sparse/src/lib.rs
+++ b/russell_sparse/src/lib.rs
@@ -6,13 +6,13 @@
//!
//! ```
//! use russell_lab::{Matrix, Vector};
-//! use russell_sparse::{ConfigSolver, Solver, SparseTriplet, StrError};
+//! use russell_sparse::{ConfigSolver, Solver, CooMatrix, StrError};
//!
//! fn main() -> Result<(), StrError> {
//!
//! // allocate a square matrix
//! let (neq, nnz) = (5, 13);
-//! let mut trip = SparseTriplet::new(neq, nnz)?;
+//! let mut trip = CooMatrix::new(neq, nnz)?;
//! trip.put(0, 0, 1.0)?; // << (0, 0, a00/2)
//! trip.put(0, 0, 1.0)?; // << (0, 0, a00/2)
//! trip.put(1, 0, 3.0)?;
diff --git a/russell_sparse/src/prelude.rs b/russell_sparse/src/prelude.rs
index 4bbe7a76..34415858 100644
--- a/russell_sparse/src/prelude.rs
+++ b/russell_sparse/src/prelude.rs
@@ -5,4 +5,4 @@
pub use crate::config_solver::ConfigSolver;
pub use crate::solver::Solver;
-pub use crate::sparse_triplet::SparseTriplet;
+pub use crate::sparse_triplet::CooMatrix;
diff --git a/russell_sparse/src/read_matrix_market.rs b/russell_sparse/src/read_matrix_market.rs
index 8d5578ba..15eb4716 100644
--- a/russell_sparse/src/read_matrix_market.rs
+++ b/russell_sparse/src/read_matrix_market.rs
@@ -1,4 +1,4 @@
-use super::SparseTriplet;
+use super::CooMatrix;
use crate::StrError;
use std::ffi::OsStr;
use std::fs::File;
@@ -161,7 +161,7 @@ impl MatrixMarketData {
}
}
-/// Reads a MatrixMarket file into a SparseTriplet
+/// Reads a MatrixMarket file into a CooMatrix
///
/// **Note:** This function works only with square matrices.
///
@@ -186,12 +186,12 @@ impl MatrixMarketData {
///
/// If `sym_mirror` is true, the reader will set `nnz` (number of non-zero values)
/// with twice the specified `nnz` value because we cannot know how many entries
-/// are on the diagonal until the whole file is read. Nonetheless, the `SparseTriplet`
-/// can be used normally by the user, since this information is internal to `SparseTriplet`.
+/// are on the diagonal until the whole file is read. Nonetheless, the `CooMatrix`
+/// can be used normally by the user, since this information is internal to `CooMatrix`.
///
/// # Output
///
-/// * A SparseTriplet or an error message
+/// * A CooMatrix or an error message
/// * Returns true if the `symmetric` keyword is present in the header
///
/// # Panics
@@ -325,7 +325,7 @@ impl MatrixMarketData {
/// Ok(())
/// }
/// ```
-pub fn read_matrix_market
(full_path: &P, sym_mirror: bool) -> Result<(SparseTriplet, bool), StrError>
+pub fn read_matrix_market
(full_path: &P, sym_mirror: bool) -> Result<(CooMatrix, bool), StrError>
where
P: AsRef + ?Sized,
{
@@ -366,7 +366,7 @@ where
}
// allocate triplet
- let mut trip = SparseTriplet::new(data.m as usize, max as usize)?;
+ let mut trip = CooMatrix::new(data.m as usize, max as usize)?;
// read and parse triples
loop {
diff --git a/russell_sparse/src/solver.rs b/russell_sparse/src/solver.rs
index 8cf9b37d..c148571c 100644
--- a/russell_sparse/src/solver.rs
+++ b/russell_sparse/src/solver.rs
@@ -1,6 +1,6 @@
use super::{
code_symmetry_mmp, code_symmetry_umf, str_enum_ordering, str_enum_scaling, str_mmp_ordering, str_mmp_scaling,
- str_umf_ordering, str_umf_scaling, ConfigSolver, LinSolKind, SparseTriplet,
+ str_umf_ordering, str_umf_scaling, ConfigSolver, CooMatrix, LinSolKind,
};
use crate::{StrError, Symmetry};
use russell_lab::{format_nanoseconds, vec_copy, Stopwatch, Vector};
@@ -148,7 +148,7 @@ impl Solver {
}
/// Performs the factorization
- pub fn factorize(&mut self, trip: &SparseTriplet) -> Result<(), StrError> {
+ pub fn factorize(&mut self, trip: &CooMatrix) -> Result<(), StrError> {
if trip.neq != self.neq {
return Err("cannot factorize because the triplet has incompatible number of equations");
}
@@ -200,12 +200,12 @@ impl Solver {
///
/// ```
/// use russell_lab::{Matrix, Vector};
- /// use russell_sparse::{ConfigSolver, SparseTriplet, Solver, StrError};
+ /// use russell_sparse::{ConfigSolver, CooMatrix, Solver, StrError};
///
/// fn main() -> Result<(), StrError> {
/// // allocate a square matrix
/// let (neq, nnz) = (5, 13);
- /// let mut trip = SparseTriplet::new(neq, nnz)?;
+ /// let mut trip = CooMatrix::new(neq, nnz)?;
/// trip.put(0, 0, 1.0)?; // << (0, 0, a00/2)
/// trip.put(0, 0, 1.0)?; // << (0, 0, a00/2)
/// trip.put(1, 0, 3.0)?;
@@ -309,12 +309,12 @@ impl Solver {
///
/// ```
/// use russell_lab::{Matrix, Vector};
- /// use russell_sparse::{ConfigSolver, Solver, SparseTriplet, StrError};
+ /// use russell_sparse::{ConfigSolver, Solver, CooMatrix, StrError};
///
/// fn main() -> Result<(), StrError> {
/// // allocate a square matrix
/// let (neq, nnz) = (3, 5);
- /// let mut trip = SparseTriplet::new(neq, nnz)?;
+ /// let mut trip = CooMatrix::new(neq, nnz)?;
/// trip.put(0, 0, 0.2)?;
/// trip.put(0, 1, 0.2)?;
/// trip.put(1, 0, 0.5)?;
@@ -357,7 +357,7 @@ impl Solver {
/// Ok(())
/// }
/// ```
- pub fn compute(config: ConfigSolver, trip: &SparseTriplet, rhs: &Vector) -> Result<(Self, Vector), StrError> {
+ pub fn compute(config: ConfigSolver, trip: &CooMatrix, rhs: &Vector) -> Result<(Self, Vector), StrError> {
let mut solver = Solver::new(config, trip.neq, trip.pos, None)?;
let mut x = Vector::new(trip.neq());
solver.factorize(&trip)?;
@@ -526,7 +526,7 @@ impl fmt::Display for Solver {
#[cfg(test)]
mod tests {
- use super::{ConfigSolver, LinSolKind, Solver, SparseTriplet};
+ use super::{ConfigSolver, CooMatrix, LinSolKind, Solver};
use russell_chk::vec_approx_eq;
use russell_lab::Vector;
@@ -543,7 +543,7 @@ mod tests {
fn factorize_fails_on_incompatible_triplet() {
let config = ConfigSolver::new();
let mut solver = Solver::new(config, 1, 1, None).unwrap();
- let trip = SparseTriplet::new(2, 2).unwrap();
+ let trip = CooMatrix::new(2, 2).unwrap();
assert_eq!(
solver.factorize(&trip).err(),
Some("cannot factorize because the triplet has incompatible number of equations")
@@ -555,7 +555,7 @@ mod tests {
let config = ConfigSolver::new();
let (neq, nnz) = (2, 2);
let mut solver = Solver::new(config, neq, nnz, None).unwrap();
- let mut trip = SparseTriplet::new(neq, nnz).unwrap();
+ let mut trip = CooMatrix::new(neq, nnz).unwrap();
trip.put(0, 0, 1.0).unwrap();
trip.put(1, 1, 0.0).unwrap();
assert_eq!(solver.factorize(&trip), Err("Error(1): Matrix is singular"));
@@ -566,7 +566,7 @@ mod tests {
let config = ConfigSolver::new();
let (neq, nnz) = (2, 2);
let mut solver = Solver::new(config, neq, nnz, None).unwrap();
- let mut trip = SparseTriplet::new(neq, nnz).unwrap();
+ let mut trip = CooMatrix::new(neq, nnz).unwrap();
trip.put(0, 0, 1.0).unwrap();
trip.put(1, 1, 1.0).unwrap();
solver.factorize(&trip).unwrap();
@@ -578,7 +578,7 @@ mod tests {
let config = ConfigSolver::new();
let (neq, nnz) = (2, 2);
let mut solver = Solver::new(config, neq, nnz, None).unwrap();
- let mut trip = SparseTriplet::new(neq, nnz).unwrap();
+ let mut trip = CooMatrix::new(neq, nnz).unwrap();
trip.put(0, 0, 1.0).unwrap();
trip.put(1, 1, 1.0).unwrap();
let mut x = Vector::new(neq);
@@ -594,7 +594,7 @@ mod tests {
let config = ConfigSolver::new();
let (neq, nnz) = (2, 2);
let mut solver = Solver::new(config, neq, nnz, None).unwrap();
- let mut trip = SparseTriplet::new(neq, nnz).unwrap();
+ let mut trip = CooMatrix::new(neq, nnz).unwrap();
trip.put(0, 0, 1.0).unwrap();
trip.put(1, 1, 1.0).unwrap();
solver.factorize(&trip).unwrap();
@@ -619,7 +619,7 @@ mod tests {
let mut solver = Solver::new(config, neq, nnz, None).unwrap();
// allocate a square matrix
- let mut trip = SparseTriplet::new(neq, nnz).unwrap();
+ let mut trip = CooMatrix::new(neq, nnz).unwrap();
trip.put(0, 0, 1.0).unwrap(); // << (0, 0, a00/2)
trip.put(0, 0, 1.0).unwrap(); // << (0, 0, a00/2)
trip.put(1, 0, 3.0).unwrap();
@@ -659,7 +659,7 @@ mod tests {
let mut solver = Solver::new(config, neq, nnz, None).unwrap();
// factorize fails on incompatible triplet
- let mut trip_wrong = SparseTriplet::new(1, 1).unwrap();
+ let mut trip_wrong = CooMatrix::new(1, 1).unwrap();
trip_wrong.put(0, 0, 1.0).unwrap();
assert_eq!(
solver.factorize(&trip_wrong).err(),
@@ -667,7 +667,7 @@ mod tests {
);
// allocate a square matrix
- let mut trip = SparseTriplet::new(neq, nnz).unwrap();
+ let mut trip = CooMatrix::new(neq, nnz).unwrap();
trip.put(0, 0, 1.0).unwrap(); // << (0, 0, a00/2)
trip.put(0, 0, 1.0).unwrap(); // << (0, 0, a00/2)
trip.put(1, 0, 3.0).unwrap();
@@ -721,7 +721,7 @@ mod tests {
vec_approx_eq(x_again.as_data(), x_correct, 1e-14);
// factorize fails on singular matrix
- let mut trip_singular = SparseTriplet::new(5, 2).unwrap();
+ let mut trip_singular = CooMatrix::new(5, 2).unwrap();
trip_singular.put(0, 0, 1.0).unwrap();
trip_singular.put(4, 4, 1.0).unwrap();
let mut solver = Solver::new(config, 5, 2, None).unwrap();
@@ -734,7 +734,7 @@ mod tests {
#[test]
fn compute_works() {
let (neq, nnz) = (3, 6);
- let mut trip = SparseTriplet::new(neq, nnz).unwrap();
+ let mut trip = CooMatrix::new(neq, nnz).unwrap();
trip.put(0, 0, 1.0).unwrap();
trip.put(0, 1, 1.0).unwrap();
trip.put(1, 0, 2.0).unwrap();
diff --git a/russell_sparse/src/sparse_triplet.rs b/russell_sparse/src/sparse_triplet.rs
index 73ba81c3..0298fbbc 100644
--- a/russell_sparse/src/sparse_triplet.rs
+++ b/russell_sparse/src/sparse_triplet.rs
@@ -3,7 +3,7 @@ use russell_lab::{Matrix, Vector};
use russell_openblas::to_i32;
use std::fmt;
-/// Holds triples (i,j,aij) representing a sparse matrix
+/// Holds the row index, col index, and values of a matrix (also known as Triplet)
///
/// # Remarks
///
@@ -14,7 +14,7 @@ use std::fmt;
/// - A maximum number of entries must be decided prior to allocating a new Triplet
/// - The maximum number of entries includes possible entries with repeated indices
/// - See the `to_matrix` method for an example
-pub struct SparseTriplet {
+pub struct CooMatrix {
pub(crate) neq: usize, // [i32] number of rows = number of columns = n_equation
pub(crate) pos: usize, // [i32] current index => nnz in the end
pub(crate) max: usize, // [i32] max allowed number of entries (may be > nnz)
@@ -23,8 +23,8 @@ pub struct SparseTriplet {
pub(crate) values_aij: Vec, // [nnz] values aij
}
-impl SparseTriplet {
- /// Creates a new SparseTriplet representing a sparse matrix
+impl CooMatrix {
+ /// Creates a new CooMatrix representing a sparse matrix
///
/// ```text
/// trip := sparse(a)
@@ -41,11 +41,11 @@ impl SparseTriplet {
/// # Example
///
/// ```
- /// use russell_sparse::{SparseTriplet, StrError};
+ /// use russell_sparse::{CooMatrix, StrError};
///
/// fn main() -> Result<(), StrError> {
/// let (neq, nnz) = (3, 4);
- /// let trip = SparseTriplet::new(neq, nnz)?;
+ /// let trip = CooMatrix::new(neq, nnz)?;
/// Ok(())
/// }
/// ```
@@ -53,7 +53,7 @@ impl SparseTriplet {
if neq == 0 || max == 0 {
return Err("neq and max must be greater than zero");
}
- Ok(SparseTriplet {
+ Ok(CooMatrix {
neq,
pos: 0,
max,
@@ -68,11 +68,11 @@ impl SparseTriplet {
/// # Example
///
/// ```
- /// use russell_sparse::{SparseTriplet, StrError};
+ /// use russell_sparse::{CooMatrix, StrError};
///
/// fn main() -> Result<(), StrError> {
/// let (neq, nnz) = (3, 4);
- /// let mut trip = SparseTriplet::new(neq, nnz)?;
+ /// let mut trip = CooMatrix::new(neq, nnz)?;
/// trip.put(0, 0, 1.0)?;
/// trip.put(1, 1, 2.0)?;
/// trip.put(2, 2, 3.0)?;
@@ -104,11 +104,11 @@ impl SparseTriplet {
/// # Example
///
/// ```
- /// use russell_sparse::{SparseTriplet, StrError};
+ /// use russell_sparse::{CooMatrix, StrError};
///
/// fn main() -> Result<(), StrError> {
/// let (neq, nnz) = (2, 1);
- /// let trip = SparseTriplet::new(neq, nnz)?;
+ /// let trip = CooMatrix::new(neq, nnz)?;
/// assert_eq!(trip.neq(), 2);
/// Ok(())
/// }
@@ -122,11 +122,11 @@ impl SparseTriplet {
/// # Example
///
/// ```
- /// use russell_sparse::{SparseTriplet, StrError};
+ /// use russell_sparse::{CooMatrix, StrError};
///
/// fn main() -> Result<(), StrError> {
/// let (neq, nnz) = (2, 1);
- /// let mut trip = SparseTriplet::new(neq, neq)?;
+ /// let mut trip = CooMatrix::new(neq, neq)?;
/// assert_eq!(trip.nnz_current(), 0);
/// trip.put(0, 0, 1.0);
/// assert_eq!(trip.nnz_current(), 1);
@@ -142,11 +142,11 @@ impl SparseTriplet {
/// # Example
///
/// ```
- /// use russell_sparse::{SparseTriplet, StrError};
+ /// use russell_sparse::{CooMatrix, StrError};
///
/// fn main() -> Result<(), StrError> {
/// let (neq, nnz) = (2, 1);
- /// let trip = SparseTriplet::new(neq, nnz)?;
+ /// let trip = CooMatrix::new(neq, nnz)?;
/// assert_eq!(trip.nnz_maximum(), 1);
/// Ok(())
/// }
@@ -160,11 +160,11 @@ impl SparseTriplet {
/// # Example
///
/// ```
- /// use russell_sparse::{SparseTriplet, StrError};
+ /// use russell_sparse::{CooMatrix, StrError};
///
/// fn main() -> Result<(), StrError> {
/// let (neq, nnz) = (3, 4);
- /// let mut trip = SparseTriplet::new(neq, nnz)?;
+ /// let mut trip = CooMatrix::new(neq, nnz)?;
/// trip.put(0, 0, 1.0)?;
/// trip.put(1, 1, 2.0)?;
/// trip.put(2, 2, 3.0)?;
@@ -181,16 +181,16 @@ impl SparseTriplet {
/// Returns the Matrix corresponding to this Triplet
///
- /// Note: this function calls [SparseTriplet::to_matrix].
+ /// Note: this function calls [CooMatrix::to_matrix].
///
/// ```
- /// use russell_sparse::{SparseTriplet, StrError};
+ /// use russell_sparse::{CooMatrix, StrError};
///
/// fn main() -> Result<(), StrError> {
/// // define (4 x 4) sparse matrix with 6+1 non-zero values
/// // (with an extra ij-repeated entry)
/// let (neq, nnz) = (4, 7);
- /// let mut trip = SparseTriplet::new(neq, nnz)?;
+ /// let mut trip = CooMatrix::new(neq, nnz)?;
/// trip.put(0, 0, 0.5)?; // (0, 0, a00/2)
/// trip.put(0, 0, 0.5)?; // (0, 0, a00/2)
/// trip.put(0, 1, 2.0)?;
@@ -219,7 +219,7 @@ impl SparseTriplet {
/// Converts the triplet data to a matrix, up to a limit
///
- /// Note: see the function [SparseTriplet::as_matrix] that returns the Matrix already.
+ /// Note: see the function [CooMatrix::as_matrix] that returns the Matrix already.
///
/// # Input
///
@@ -230,13 +230,13 @@ impl SparseTriplet {
///
/// ```
/// use russell_lab::{Matrix};
- /// use russell_sparse::{SparseTriplet, StrError};
+ /// use russell_sparse::{CooMatrix, StrError};
///
/// fn main() -> Result<(), StrError> {
/// // define (4 x 4) sparse matrix with 6+1 non-zero values
/// // (with an extra ij-repeated entry)
/// let (neq, nnz) = (4, 7);
- /// let mut trip = SparseTriplet::new(neq, nnz)?;
+ /// let mut trip = CooMatrix::new(neq, nnz)?;
/// trip.put(0, 0, 0.5)?; // (0, 0, a00/2)
/// trip.put(0, 0, 0.5)?; // (0, 0, a00/2)
/// trip.put(0, 1, 2.0)?;
@@ -306,12 +306,12 @@ impl SparseTriplet {
///
/// ```
/// use russell_lab::{Matrix, Vector};
- /// use russell_sparse::{SparseTriplet, StrError};
+ /// use russell_sparse::{CooMatrix, StrError};
///
/// fn main() -> Result<(), StrError> {
/// // set sparse matrix (3 x 3) with 6 non-zeros
/// let (neq, nnz) = (3, 6);
- /// let mut trip = SparseTriplet::new(neq, nnz)?;
+ /// let mut trip = CooMatrix::new(neq, nnz)?;
/// trip.put(0, 0, 1.0)?;
/// trip.put(1, 0, 2.0)?;
/// trip.put(1, 1, 3.0)?;
@@ -361,7 +361,7 @@ impl SparseTriplet {
}
}
-impl fmt::Display for SparseTriplet {
+impl fmt::Display for CooMatrix {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
@@ -379,25 +379,25 @@ impl fmt::Display for SparseTriplet {
#[cfg(test)]
mod tests {
- use super::SparseTriplet;
+ use super::CooMatrix;
use russell_chk::vec_approx_eq;
use russell_lab::{Matrix, Vector};
#[test]
fn new_fails_on_wrong_input() {
assert_eq!(
- SparseTriplet::new(0, 3).err(),
+ CooMatrix::new(0, 3).err(),
Some("neq and max must be greater than zero")
);
assert_eq!(
- SparseTriplet::new(3, 0).err(),
+ CooMatrix::new(3, 0).err(),
Some("neq and max must be greater than zero")
);
}
#[test]
fn new_works() {
- let trip = SparseTriplet::new(3, 5).unwrap();
+ let trip = CooMatrix::new(3, 5).unwrap();
assert_eq!(trip.neq, 3);
assert_eq!(trip.pos, 0);
assert_eq!(trip.max, 5);
@@ -405,7 +405,7 @@ mod tests {
#[test]
fn put_fails_on_wrong_values() {
- let mut trip = SparseTriplet::new(1, 1).unwrap();
+ let mut trip = CooMatrix::new(1, 1).unwrap();
assert_eq!(
trip.put(1, 0, 0.0).err(),
Some("sparse matrix row index is out of bounds")
@@ -423,7 +423,7 @@ mod tests {
#[test]
fn put_works() {
- let mut trip = SparseTriplet::new(3, 5).unwrap();
+ let mut trip = CooMatrix::new(3, 5).unwrap();
trip.put(0, 0, 1.0).unwrap();
assert_eq!(trip.pos, 1);
trip.put(0, 1, 2.0).unwrap();
@@ -438,7 +438,7 @@ mod tests {
#[test]
fn getters_and_reset_work() {
- let mut trip = SparseTriplet::new(2, 4).unwrap();
+ let mut trip = CooMatrix::new(2, 4).unwrap();
assert_eq!(trip.nnz_current(), 0);
trip.put(0, 0, 1.0).unwrap();
trip.put(0, 1, 4.0).unwrap();
@@ -453,7 +453,7 @@ mod tests {
#[test]
fn to_matrix_fails_on_wrong_dims() {
- let trip = SparseTriplet::new(1, 1).unwrap();
+ let trip = CooMatrix::new(1, 1).unwrap();
let mut a_2x1 = Matrix::new(2, 1);
let mut a_1x2 = Matrix::new(1, 2);
assert_eq!(trip.to_matrix(&mut a_2x1), Err("wrong matrix dimensions"));
@@ -462,7 +462,7 @@ mod tests {
#[test]
fn to_matrix_works() {
- let mut trip = SparseTriplet::new(3, 5).unwrap();
+ let mut trip = CooMatrix::new(3, 5).unwrap();
trip.put(0, 0, 1.0).unwrap();
trip.put(0, 1, 2.0).unwrap();
trip.put(1, 0, 3.0).unwrap();
@@ -489,7 +489,7 @@ mod tests {
fn to_matrix_with_duplicates_works() {
// allocate a square matrix
let (neq, nnz) = (5, 13);
- let mut trip = SparseTriplet::new(neq, nnz).unwrap();
+ let mut trip = CooMatrix::new(neq, nnz).unwrap();
trip.put(0, 0, 1.0).unwrap(); // << (0, 0, a00/2)
trip.put(0, 0, 1.0).unwrap(); // << (0, 0, a00/2)
trip.put(1, 0, 3.0).unwrap();
@@ -519,7 +519,7 @@ mod tests {
#[test]
fn mat_vec_mul_fails_on_wrong_input() {
- let trip = SparseTriplet::new(2, 1).unwrap();
+ let trip = CooMatrix::new(2, 1).unwrap();
let u = Vector::new(3);
assert_eq!(trip.mat_vec_mul(&u, false).err(), Some("u.ndim must equal neq"));
}
@@ -529,7 +529,7 @@ mod tests {
// 1.0 2.0 3.0
// 0.1 0.2 0.3
// 10.0 20.0 30.0
- let mut trip = SparseTriplet::new(3, 9).unwrap();
+ let mut trip = CooMatrix::new(3, 9).unwrap();
trip.put(0, 0, 1.0).unwrap();
trip.put(0, 1, 2.0).unwrap();
trip.put(0, 2, 3.0).unwrap();
@@ -553,7 +553,7 @@ mod tests {
// 3 1 1 7
// 2 1 5 1 8
let (neq, nnz) = (5, 15);
- let mut trip = SparseTriplet::new(neq, nnz).unwrap();
+ let mut trip = CooMatrix::new(neq, nnz).unwrap();
trip.put(0, 0, 2.0).unwrap();
trip.put(1, 1, 2.0).unwrap();
trip.put(2, 2, 9.0).unwrap();
@@ -587,7 +587,7 @@ mod tests {
// 3 1 1 7 1
// 2 1 5 1 8
let (neq, nnz) = (5, 25);
- let mut trip = SparseTriplet::new(neq, nnz).unwrap();
+ let mut trip = CooMatrix::new(neq, nnz).unwrap();
trip.put(0, 0, 2.0).unwrap();
trip.put(1, 1, 2.0).unwrap();
trip.put(2, 2, 9.0).unwrap();
@@ -629,7 +629,7 @@ mod tests {
// -1 2 -1 => -1 2
// -1 2 -1 2
let (neq, nnz) = (3, 5);
- let mut trip = SparseTriplet::new(neq, nnz).unwrap();
+ let mut trip = CooMatrix::new(neq, nnz).unwrap();
trip.put(0, 0, 2.0).unwrap();
trip.put(1, 1, 2.0).unwrap();
trip.put(2, 2, 2.0).unwrap();
@@ -643,7 +643,7 @@ mod tests {
#[test]
fn display_trait_works() {
- let trip = SparseTriplet::new(3, 1).unwrap();
+ let trip = CooMatrix::new(3, 1).unwrap();
let correct: &str = "\x20\x20\x20\x20\"neq\": 3,\n\
\x20\x20\x20\x20\"nnz_current\": 0,\n\
\x20\x20\x20\x20\"nnz_maximum\": 1,\n";
diff --git a/russell_sparse/src/verify_lin_sys.rs b/russell_sparse/src/verify_lin_sys.rs
index 1f892d7a..f8d70ed6 100644
--- a/russell_sparse/src/verify_lin_sys.rs
+++ b/russell_sparse/src/verify_lin_sys.rs
@@ -1,4 +1,4 @@
-use super::SparseTriplet;
+use super::CooMatrix;
use crate::StrError;
use russell_lab::{format_nanoseconds, vec_norm, vec_update, Norm, Stopwatch, Vector};
use russell_openblas::{idamax, to_i32};
@@ -24,12 +24,12 @@ impl VerifyLinSys {
///
/// ```
/// use russell_lab::{Matrix, Vector};
- /// use russell_sparse::{SparseTriplet, VerifyLinSys, StrError};
+ /// use russell_sparse::{CooMatrix, VerifyLinSys, StrError};
///
/// fn main() -> Result<(), StrError> {
/// // set sparse matrix (3 x 3) with 4 non-zeros
/// let (neq, nnz) = (3, 4);
- /// let mut trip = SparseTriplet::new(neq, nnz)?;
+ /// let mut trip = CooMatrix::new(neq, nnz)?;
/// trip.put(0, 0, 1.0)?;
/// trip.put(0, 2, 4.0)?;
/// trip.put(1, 1, 2.0)?;
@@ -57,7 +57,7 @@ impl VerifyLinSys {
/// Ok(())
/// }
/// ```
- pub fn new(trip: &SparseTriplet, x: &Vector, rhs: &Vector, triangular: bool) -> Result {
+ pub fn new(trip: &CooMatrix, x: &Vector, rhs: &Vector, triangular: bool) -> Result {
if x.dim() != trip.neq || rhs.dim() != trip.neq {
return Err("vector dimensions are incompatible");
}
@@ -120,12 +120,12 @@ impl fmt::Display for VerifyLinSys {
#[cfg(test)]
mod tests {
- use super::{SparseTriplet, VerifyLinSys};
+ use super::{CooMatrix, VerifyLinSys};
use russell_lab::Vector;
#[test]
fn new_fails_on_wrong_vectors() {
- let trip = SparseTriplet::new(1, 1).unwrap();
+ let trip = CooMatrix::new(1, 1).unwrap();
let x = Vector::new(2);
let rhs = Vector::new(3);
let x_wrong = Vector::new(3);
@@ -145,7 +145,7 @@ mod tests {
// | 1 3 -2 |
// | 3 5 6 |
// | 2 4 3 |
- let mut trip = SparseTriplet::new(3, 9).unwrap();
+ let mut trip = CooMatrix::new(3, 9).unwrap();
trip.put(0, 0, 1.0).unwrap();
trip.put(0, 1, 3.0).unwrap();
trip.put(0, 2, -2.0).unwrap();
@@ -167,7 +167,7 @@ mod tests {
#[test]
fn display_trait_works() {
- let mut trip = SparseTriplet::new(2, 2).unwrap();
+ let mut trip = CooMatrix::new(2, 2).unwrap();
trip.put(0, 0, 1.0).unwrap();
trip.put(1, 1, 1.0).unwrap();
let x = Vector::from(&[1.0, 1.0]);
diff --git a/russell_sparse/src/write_matrix_market.rs b/russell_sparse/src/write_matrix_market.rs
index 3d3959ad..14fbb829 100644
--- a/russell_sparse/src/write_matrix_market.rs
+++ b/russell_sparse/src/write_matrix_market.rs
@@ -1,4 +1,4 @@
-use super::SparseTriplet;
+use super::CooMatrix;
use crate::StrError;
use std::ffi::OsStr;
use std::fmt::Write;
@@ -6,8 +6,8 @@ use std::fs::{self, File};
use std::io::Write as IoWrite;
use std::path::Path;
-impl SparseTriplet {
- /// Writes a MatrixMarket file from a SparseTriplet
+impl CooMatrix {
+ /// Writes a MatrixMarket file from a CooMatrix
///
/// # Input
///
diff --git a/russell_sparse/tests/test_nonlinear_system.rs b/russell_sparse/tests/test_nonlinear_system.rs
index 466c5f3a..83d76d8a 100644
--- a/russell_sparse/tests/test_nonlinear_system.rs
+++ b/russell_sparse/tests/test_nonlinear_system.rs
@@ -1,6 +1,6 @@
use russell_chk::{deriv_central5, vec_approx_eq};
use russell_lab::{mat_approx_eq, vec_norm, vec_update, Matrix, Norm, Vector};
-use russell_sparse::{ConfigSolver, LinSolKind, Solver, SparseTriplet, StrError};
+use russell_sparse::{ConfigSolver, CooMatrix, LinSolKind, Solver, StrError};
fn calc_residual(rr: &mut Vector, uu: &Vector) {
let (d1, d2, d3, d4) = (uu[0], uu[1], uu[2], uu[3]);
@@ -10,7 +10,7 @@ fn calc_residual(rr: &mut Vector, uu: &Vector) {
rr[3] = -9.0 * d1 + 4.0 * d1 * d4 * d4 * d4 + 7.0 * d2 + 2.0 * d3 + 5.0 * d4 - 0.5;
}
-fn calc_jacobian(jj: &mut SparseTriplet, uu: &Vector) -> Result<(), StrError> {
+fn calc_jacobian(jj: &mut CooMatrix, uu: &Vector) -> Result<(), StrError> {
let (d1, d2, d3, d4) = (uu[0], uu[1], uu[2], uu[3]);
jj.reset();
@@ -67,7 +67,7 @@ fn check_jacobian() {
}
}
let nnz = neq * neq;
- let mut jj_tri = SparseTriplet::new(neq, nnz).unwrap();
+ let mut jj_tri = CooMatrix::new(neq, nnz).unwrap();
calc_jacobian(&mut jj_tri, &uu).unwrap();
let mut jj_ana = Matrix::new(neq, neq);
jj_tri.to_matrix(&mut jj_ana).unwrap();
@@ -80,7 +80,7 @@ fn solve_nonlinear_system(kind: LinSolKind) -> Result<(), StrError> {
// config.verbose();
let (neq, nnz) = (4, 16);
let mut solver = Solver::new(config, neq, nnz, None)?;
- let mut jj = SparseTriplet::new(neq, nnz).unwrap();
+ let mut jj = CooMatrix::new(neq, nnz).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);