Put COO, CSR, SparsityPattern and related types in their own modules
This mimics how std does it, e.g. std::vec::Vec. This avoids potential problems down the road, where adding more types might clutter the API interface and generated documentation.
This commit is contained in:
parent
7a5f8ef1ea
commit
a15e78a6b7
|
@ -1,3 +1,5 @@
|
||||||
|
//! An implementation of the COO sparse matrix format.
|
||||||
|
|
||||||
use crate::SparseFormatError;
|
use crate::SparseFormatError;
|
||||||
use nalgebra::{ClosedAdd, DMatrix, Scalar};
|
use nalgebra::{ClosedAdd, DMatrix, Scalar};
|
||||||
use num_traits::Zero;
|
use num_traits::Zero;
|
||||||
|
@ -24,7 +26,7 @@ use num_traits::Zero;
|
||||||
/// -------
|
/// -------
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use nalgebra_sparse::CooMatrix;
|
/// # use nalgebra_sparse::coo::CooMatrix;
|
||||||
/// // Create a zero matrix
|
/// // Create a zero matrix
|
||||||
/// let mut coo = CooMatrix::new(4, 4);
|
/// let mut coo = CooMatrix::new(4, 4);
|
||||||
/// // Or initialize it with a set of triplets
|
/// // Or initialize it with a set of triplets
|
||||||
|
@ -165,7 +167,7 @@ where
|
||||||
/// --------
|
/// --------
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use nalgebra_sparse::CooMatrix;
|
/// # use nalgebra_sparse::coo::CooMatrix;
|
||||||
/// let row_indices = vec![0, 1];
|
/// let row_indices = vec![0, 1];
|
||||||
/// let col_indices = vec![1, 2];
|
/// let col_indices = vec![1, 2];
|
||||||
/// let values = vec![1.0, 2.0];
|
/// let values = vec![1.0, 2.0];
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use crate::{SparsityPattern, SparseFormatError, SparsityPatternFormatError, SparseFormatErrorKind};
|
//! An implementation of the CSR sparse matrix format.
|
||||||
use crate::iter::SparsityPatternIter;
|
|
||||||
|
use crate::{SparseFormatError, SparseFormatErrorKind};
|
||||||
|
use crate::pattern::{SparsityPattern, SparsityPatternFormatError, SparsityPatternIter};
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::slice::{IterMut, Iter};
|
use std::slice::{IterMut, Iter};
|
||||||
|
@ -124,7 +126,7 @@ impl<T> CsrMatrix<T> {
|
||||||
/// Examples
|
/// Examples
|
||||||
/// --------
|
/// --------
|
||||||
/// ```
|
/// ```
|
||||||
/// # use nalgebra_sparse::CsrMatrix;
|
/// # use nalgebra_sparse::csr::CsrMatrix;
|
||||||
/// let row_offsets = vec![0, 2, 3, 4];
|
/// let row_offsets = vec![0, 2, 3, 4];
|
||||||
/// let col_indices = vec![0, 2, 1, 0];
|
/// let col_indices = vec![0, 2, 1, 0];
|
||||||
/// let values = vec![1, 2, 3, 4];
|
/// let values = vec![1, 2, 3, 4];
|
||||||
|
@ -148,7 +150,7 @@ impl<T> CsrMatrix<T> {
|
||||||
/// Examples
|
/// Examples
|
||||||
/// --------
|
/// --------
|
||||||
/// ```
|
/// ```
|
||||||
/// # use nalgebra_sparse::CsrMatrix;
|
/// # use nalgebra_sparse::csr::CsrMatrix;
|
||||||
/// # let row_offsets = vec![0, 2, 3, 4];
|
/// # let row_offsets = vec![0, 2, 3, 4];
|
||||||
/// # let col_indices = vec![0, 2, 1, 0];
|
/// # let col_indices = vec![0, 2, 1, 0];
|
||||||
/// # let values = vec![1, 2, 3, 4];
|
/// # let values = vec![1, 2, 3, 4];
|
||||||
|
@ -432,6 +434,7 @@ impl<'a, T> CsrRowMut<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Row iterator for [CsrMatrix](struct.CsrMatrix.html).
|
||||||
pub struct CsrRowIter<'a, T> {
|
pub struct CsrRowIter<'a, T> {
|
||||||
// The index of the row that will be returned on the next
|
// The index of the row that will be returned on the next
|
||||||
current_row_idx: usize,
|
current_row_idx: usize,
|
||||||
|
@ -448,6 +451,7 @@ impl<'a, T> Iterator for CsrRowIter<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Mutable row iterator for [CsrMatrix](struct.CsrMatrix.html).
|
||||||
pub struct CsrRowIterMut<'a, T> {
|
pub struct CsrRowIterMut<'a, T> {
|
||||||
current_row_idx: usize,
|
current_row_idx: usize,
|
||||||
pattern: &'a SparsityPattern,
|
pattern: &'a SparsityPattern,
|
||||||
|
|
|
@ -65,30 +65,11 @@
|
||||||
#![deny(unused_results)]
|
#![deny(unused_results)]
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
mod coo;
|
pub mod coo;
|
||||||
mod csr;
|
pub mod csr;
|
||||||
mod pattern;
|
pub mod pattern;
|
||||||
|
|
||||||
pub mod ops;
|
pub mod ops;
|
||||||
|
|
||||||
pub use coo::CooMatrix;
|
|
||||||
pub use csr::{CsrMatrix, CsrRow, CsrRowMut};
|
|
||||||
pub use pattern::{SparsityPattern, SparsityPatternFormatError};
|
|
||||||
|
|
||||||
/// Iterator types for matrices.
|
|
||||||
///
|
|
||||||
/// Most users will not need to interface with these types directly. Instead, refer to the
|
|
||||||
/// iterator methods for the respective matrix formats.
|
|
||||||
pub mod iter {
|
|
||||||
// Iterators are best implemented in the same modules as the matrices they iterate over,
|
|
||||||
// since they are so closely tied to their respective implementations. However,
|
|
||||||
// in the crate's public API we move them into a separate `iter` module in order to avoid
|
|
||||||
// cluttering the docs with iterator types that most users will never need to explicitly
|
|
||||||
// know about.
|
|
||||||
pub use crate::pattern::SparsityPatternIter;
|
|
||||||
pub use crate::csr::{CsrTripletIter, CsrTripletIterMut};
|
|
||||||
}
|
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Matrix operations involving sparse matrices.
|
//! Matrix operations involving sparse matrices.
|
||||||
|
|
||||||
use crate::CooMatrix;
|
use crate::coo::CooMatrix;
|
||||||
use nalgebra::base::storage::{Storage, StorageMut};
|
use nalgebra::base::storage::{Storage, StorageMut};
|
||||||
use nalgebra::{ClosedAdd, ClosedMul, Dim, Scalar, Vector};
|
use nalgebra::{ClosedAdd, ClosedMul, Dim, Scalar, Vector};
|
||||||
use num_traits::{One, Zero};
|
use num_traits::{One, Zero};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Sparsity patterns for CSR and CSC matrices.
|
||||||
use crate::SparseFormatError;
|
use crate::SparseFormatError;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
@ -156,7 +157,7 @@ impl SparsityPattern {
|
||||||
/// --------
|
/// --------
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use nalgebra_sparse::{SparsityPattern};
|
/// # use nalgebra_sparse::pattern::SparsityPattern;
|
||||||
/// let offsets = vec![0, 2, 3, 4];
|
/// let offsets = vec![0, 2, 3, 4];
|
||||||
/// let minor_indices = vec![0, 2, 1, 0];
|
/// let minor_indices = vec![0, 2, 1, 0];
|
||||||
/// let pattern = SparsityPattern::try_from_offsets_and_indices(3, 4, offsets, minor_indices)
|
/// let pattern = SparsityPattern::try_from_offsets_and_indices(3, 4, offsets, minor_indices)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use nalgebra_sparse::{CooMatrix, SparseFormatErrorKind};
|
use nalgebra_sparse::{SparseFormatErrorKind};
|
||||||
|
use nalgebra_sparse::coo::CooMatrix;
|
||||||
use nalgebra::DMatrix;
|
use nalgebra::DMatrix;
|
||||||
use crate::assert_panics;
|
use crate::assert_panics;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use nalgebra_sparse::CooMatrix;
|
use nalgebra_sparse::coo::CooMatrix;
|
||||||
use nalgebra_sparse::ops::spmv_coo;
|
use nalgebra_sparse::ops::spmv_coo;
|
||||||
use nalgebra::DVector;
|
use nalgebra::DVector;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue