Finish initial must_use annotations

This commit is contained in:
Malte Tammena 2021-06-06 15:28:37 +02:00
parent 39aa52d019
commit 42a2c74571
17 changed files with 97 additions and 0 deletions

View File

@ -80,6 +80,7 @@ where
} }
/// Retrieves the lower-triangular factor of the cholesky decomposition. /// Retrieves the lower-triangular factor of the cholesky decomposition.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn l(&self) -> OMatrix<T, D, D> { pub fn l(&self) -> OMatrix<T, D, D> {
let mut res = self.l.clone(); let mut res = self.l.clone();
res.fill_upper_triangle(Zero::zero(), 1); res.fill_upper_triangle(Zero::zero(), 1);
@ -91,6 +92,7 @@ where
/// ///
/// This is an allocation-less version of `self.l()`. The values of the strict upper-triangular /// This is an allocation-less version of `self.l()`. The values of the strict upper-triangular
/// part are garbage and should be ignored by further computations. /// part are garbage and should be ignored by further computations.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn l_dirty(&self) -> &OMatrix<T, D, D> { pub fn l_dirty(&self) -> &OMatrix<T, D, D> {
&self.l &self.l
} }

View File

@ -302,6 +302,7 @@ where
/// The determinant of the decomposed matrix. /// The determinant of the decomposed matrix.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn determinant(&self) -> T { pub fn determinant(&self) -> T {
let mut det = T::one(); let mut det = T::one();
for e in self.eigenvalues.iter() { for e in self.eigenvalues.iter() {

View File

@ -89,6 +89,7 @@ where
/// Computes the hessenberg matrix of this decomposition. /// Computes the hessenberg matrix of this decomposition.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn h(&self) -> OMatrix<T, D, D> { pub fn h(&self) -> OMatrix<T, D, D> {
let mut h = self.h.clone_owned(); let mut h = self.h.clone_owned();
h.fill_lower_triangle(T::zero(), 2); h.fill_lower_triangle(T::zero(), 2);
@ -109,6 +110,7 @@ where
/// Computes the unitary matrix `Q` of this decomposition. /// Computes the unitary matrix `Q` of this decomposition.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn q(&self) -> OMatrix<T, D, D> { pub fn q(&self) -> OMatrix<T, D, D> {
let n = self.h.nrows() as i32; let n = self.h.nrows() as i32;
let mut q = self.h.clone_owned(); let mut q = self.h.clone_owned();

View File

@ -85,6 +85,7 @@ where
/// Gets the lower-triangular matrix part of the decomposition. /// Gets the lower-triangular matrix part of the decomposition.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn l(&self) -> OMatrix<T, R, DimMinimum<R, C>> { pub fn l(&self) -> OMatrix<T, R, DimMinimum<R, C>> {
let (nrows, ncols) = self.lu.data.shape(); let (nrows, ncols) = self.lu.data.shape();
let mut res = self.lu.columns_generic(0, nrows.min(ncols)).into_owned(); let mut res = self.lu.columns_generic(0, nrows.min(ncols)).into_owned();
@ -97,6 +98,7 @@ where
/// Gets the upper-triangular matrix part of the decomposition. /// Gets the upper-triangular matrix part of the decomposition.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn u(&self) -> OMatrix<T, DimMinimum<R, C>, C> { pub fn u(&self) -> OMatrix<T, DimMinimum<R, C>, C> {
let (nrows, ncols) = self.lu.data.shape(); let (nrows, ncols) = self.lu.data.shape();
let mut res = self.lu.rows_generic(0, nrows.min(ncols)).into_owned(); let mut res = self.lu.rows_generic(0, nrows.min(ncols)).into_owned();
@ -111,6 +113,7 @@ where
/// Computing the permutation matrix explicitly is costly and usually not necessary. /// Computing the permutation matrix explicitly is costly and usually not necessary.
/// To permute rows of a matrix or vector, use the method `self.permute(...)` instead. /// To permute rows of a matrix or vector, use the method `self.permute(...)` instead.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn p(&self) -> OMatrix<T, R, R> { pub fn p(&self) -> OMatrix<T, R, R> {
let (dim, _) = self.lu.data.shape(); let (dim, _) = self.lu.data.shape();
let mut id = Matrix::identity_generic(dim, dim); let mut id = Matrix::identity_generic(dim, dim);
@ -124,6 +127,7 @@ where
/// Gets the LAPACK permutation indices. /// Gets the LAPACK permutation indices.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn permutation_indices(&self) -> &OVector<i32, DimMinimum<R, C>> { pub fn permutation_indices(&self) -> &OVector<i32, DimMinimum<R, C>> {
&self.p &self.p
} }

View File

@ -92,6 +92,7 @@ where
/// Retrieves the upper trapezoidal submatrix `R` of this decomposition. /// Retrieves the upper trapezoidal submatrix `R` of this decomposition.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn r(&self) -> OMatrix<T, DimMinimum<R, C>, C> { pub fn r(&self) -> OMatrix<T, DimMinimum<R, C>, C> {
let (nrows, ncols) = self.qr.data.shape(); let (nrows, ncols) = self.qr.data.shape();
self.qr.rows_generic(0, nrows.min(ncols)).upper_triangle() self.qr.rows_generic(0, nrows.min(ncols)).upper_triangle()
@ -117,6 +118,7 @@ where
/// Computes the orthogonal matrix `Q` of this decomposition. /// Computes the orthogonal matrix `Q` of this decomposition.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn q(&self) -> OMatrix<T, R, DimMinimum<R, C>> { pub fn q(&self) -> OMatrix<T, R, DimMinimum<R, C>> {
let (nrows, ncols) = self.qr.data.shape(); let (nrows, ncols) = self.qr.data.shape();
let min_nrows_ncols = nrows.min(ncols); let min_nrows_ncols = nrows.min(ncols);

View File

@ -138,6 +138,7 @@ where
/// Computes the real eigenvalues of the decomposed matrix. /// Computes the real eigenvalues of the decomposed matrix.
/// ///
/// Return `None` if some eigenvalues are complex. /// Return `None` if some eigenvalues are complex.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn eigenvalues(&self) -> Option<OVector<T, D>> { pub fn eigenvalues(&self) -> Option<OVector<T, D>> {
if self.im.iter().all(|e| e.is_zero()) { if self.im.iter().all(|e| e.is_zero()) {
Some(self.re.clone()) Some(self.re.clone())
@ -147,6 +148,7 @@ where
} }
/// Computes the complex eigenvalues of the decomposed matrix. /// Computes the complex eigenvalues of the decomposed matrix.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn complex_eigenvalues(&self) -> OVector<Complex<T>, D> pub fn complex_eigenvalues(&self) -> OVector<Complex<T>, D>
where where
DefaultAllocator: Allocator<Complex<T>, D>, DefaultAllocator: Allocator<Complex<T>, D>,

View File

@ -175,6 +175,7 @@ macro_rules! svd_impl(
/// ///
/// All singular value below epsilon will be set to zero instead of being inverted. /// All singular value below epsilon will be set to zero instead of being inverted.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn pseudo_inverse(&self, epsilon: $t) -> OMatrix<$t, C, R> { pub fn pseudo_inverse(&self, epsilon: $t) -> OMatrix<$t, C, R> {
let nrows = self.u.data.shape().0; let nrows = self.u.data.shape().0;
let ncols = self.vt.data.shape().1; let ncols = self.vt.data.shape().1;
@ -207,6 +208,7 @@ macro_rules! svd_impl(
/// This is the number of singular values that are not too small (i.e. greater than /// This is the number of singular values that are not too small (i.e. greater than
/// the given `epsilon`). /// the given `epsilon`).
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn rank(&self, epsilon: $t) -> usize { pub fn rank(&self, epsilon: $t) -> usize {
let mut i = 0; let mut i = 0;

View File

@ -138,6 +138,7 @@ where
/// The determinant of the decomposed matrix. /// The determinant of the decomposed matrix.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn determinant(&self) -> T { pub fn determinant(&self) -> T {
let mut det = T::one(); let mut det = T::one();
for e in self.eigenvalues.iter() { for e in self.eigenvalues.iter() {
@ -150,6 +151,7 @@ where
/// Rebuild the original matrix. /// Rebuild the original matrix.
/// ///
/// This is useful if some of the eigenvalues have been manually modified. /// This is useful if some of the eigenvalues have been manually modified.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn recompose(&self) -> OMatrix<T, D, D> { pub fn recompose(&self) -> OMatrix<T, D, D> {
let mut u_t = self.eigenvectors.clone(); let mut u_t = self.eigenvectors.clone();
for i in 0..self.eigenvalues.len() { for i in 0..self.eigenvalues.len() {

View File

@ -173,12 +173,14 @@ impl<T> CooMatrix<T> {
/// The number of rows in the matrix. /// The number of rows in the matrix.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nrows(&self) -> usize { pub fn nrows(&self) -> usize {
self.nrows self.nrows
} }
/// The number of columns in the matrix. /// The number of columns in the matrix.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn ncols(&self) -> usize { pub fn ncols(&self) -> usize {
self.ncols self.ncols
} }
@ -189,21 +191,25 @@ impl<T> CooMatrix<T> {
/// entries, then it may have a different number of non-zeros as reported by `nnz()` compared /// entries, then it may have a different number of non-zeros as reported by `nnz()` compared
/// to its CSR representation. /// to its CSR representation.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize { pub fn nnz(&self) -> usize {
self.values.len() self.values.len()
} }
/// The row indices of the explicitly stored entries. /// The row indices of the explicitly stored entries.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn row_indices(&self) -> &[usize] { pub fn row_indices(&self) -> &[usize] {
&self.row_indices &self.row_indices
} }
/// The column indices of the explicitly stored entries. /// The column indices of the explicitly stored entries.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn col_indices(&self) -> &[usize] { pub fn col_indices(&self) -> &[usize] {
&self.col_indices &self.col_indices
} }
/// The values of the explicitly stored entries. /// The values of the explicitly stored entries.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] { pub fn values(&self) -> &[T] {
&self.values &self.values
} }

View File

@ -32,11 +32,13 @@ impl<T> CsMatrix<T> {
} }
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn pattern(&self) -> &SparsityPattern { pub fn pattern(&self) -> &SparsityPattern {
&self.sparsity_pattern &self.sparsity_pattern
} }
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] { pub fn values(&self) -> &[T] {
&self.values &self.values
} }
@ -48,6 +50,7 @@ impl<T> CsMatrix<T> {
/// Returns the raw data represented as a tuple `(major_offsets, minor_indices, values)`. /// Returns the raw data represented as a tuple `(major_offsets, minor_indices, values)`.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn cs_data(&self) -> (&[usize], &[usize], &[T]) { pub fn cs_data(&self) -> (&[usize], &[usize], &[T]) {
let pattern = self.pattern(); let pattern = self.pattern();
( (
@ -88,6 +91,7 @@ impl<T> CsMatrix<T> {
/// Internal method for simplifying access to a lane's data /// Internal method for simplifying access to a lane's data
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn get_index_range(&self, row_index: usize) -> Option<Range<usize>> { pub fn get_index_range(&self, row_index: usize) -> Option<Range<usize>> {
let row_begin = *self.sparsity_pattern.major_offsets().get(row_index)?; let row_begin = *self.sparsity_pattern.major_offsets().get(row_index)?;
let row_end = *self.sparsity_pattern.major_offsets().get(row_index + 1)?; let row_end = *self.sparsity_pattern.major_offsets().get(row_index + 1)?;
@ -111,6 +115,7 @@ impl<T> CsMatrix<T> {
/// Returns an entry for the given major/minor indices, or `None` if the indices are out /// Returns an entry for the given major/minor indices, or `None` if the indices are out
/// of bounds. /// of bounds.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn get_entry(&self, major_index: usize, minor_index: usize) -> Option<SparseEntry<T>> { pub fn get_entry(&self, major_index: usize, minor_index: usize) -> Option<SparseEntry<T>> {
let row_range = self.get_index_range(major_index)?; let row_range = self.get_index_range(major_index)?;
let (_, minor_indices, values) = self.cs_data(); let (_, minor_indices, values) = self.cs_data();
@ -139,6 +144,7 @@ impl<T> CsMatrix<T> {
get_mut_entry_from_slices(minor_dim, minor_indices, values, minor_index) get_mut_entry_from_slices(minor_dim, minor_indices, values, minor_index)
} }
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn get_lane(&self, index: usize) -> Option<CsLane<T>> { pub fn get_lane(&self, index: usize) -> Option<CsLane<T>> {
let range = self.get_index_range(index)?; let range = self.get_index_range(index)?;
let (_, minor_indices, values) = self.cs_data(); let (_, minor_indices, values) = self.cs_data();
@ -172,6 +178,7 @@ impl<T> CsMatrix<T> {
} }
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn filter<P>(&self, predicate: P) -> Self pub fn filter<P>(&self, predicate: P) -> Self
where where
T: Clone, T: Clone,
@ -207,6 +214,7 @@ impl<T> CsMatrix<T> {
} }
/// Returns the diagonal of the matrix as a sparse matrix. /// Returns the diagonal of the matrix as a sparse matrix.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn diagonal_as_matrix(&self) -> Self pub fn diagonal_as_matrix(&self) -> Self
where where
T: Clone, T: Clone,
@ -372,26 +380,31 @@ macro_rules! impl_cs_lane_common_methods {
($name:ty) => { ($name:ty) => {
impl<'a, T> $name { impl<'a, T> $name {
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn minor_dim(&self) -> usize { pub fn minor_dim(&self) -> usize {
self.minor_dim self.minor_dim
} }
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize { pub fn nnz(&self) -> usize {
self.minor_indices.len() self.minor_indices.len()
} }
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn minor_indices(&self) -> &[usize] { pub fn minor_indices(&self) -> &[usize] {
self.minor_indices self.minor_indices
} }
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] { pub fn values(&self) -> &[T] {
self.values self.values
} }
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn get_entry(&self, global_col_index: usize) -> Option<SparseEntry<T>> { pub fn get_entry(&self, global_col_index: usize) -> Option<SparseEntry<T>> {
get_entry_from_slices( get_entry_from_slices(
self.minor_dim, self.minor_dim,

View File

@ -192,12 +192,14 @@ impl<T> CscMatrix<T> {
/// The number of rows in the matrix. /// The number of rows in the matrix.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nrows(&self) -> usize { pub fn nrows(&self) -> usize {
self.cs.pattern().minor_dim() self.cs.pattern().minor_dim()
} }
/// The number of columns in the matrix. /// The number of columns in the matrix.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn ncols(&self) -> usize { pub fn ncols(&self) -> usize {
self.cs.pattern().major_dim() self.cs.pattern().major_dim()
} }
@ -208,24 +210,28 @@ impl<T> CscMatrix<T> {
/// number of algebraically zero entries in the matrix. Explicitly stored entries can still /// number of algebraically zero entries in the matrix. Explicitly stored entries can still
/// be zero. Corresponds to the number of entries in the sparsity pattern. /// be zero. Corresponds to the number of entries in the sparsity pattern.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize { pub fn nnz(&self) -> usize {
self.pattern().nnz() self.pattern().nnz()
} }
/// The column offsets defining part of the CSC format. /// The column offsets defining part of the CSC format.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn col_offsets(&self) -> &[usize] { pub fn col_offsets(&self) -> &[usize] {
self.pattern().major_offsets() self.pattern().major_offsets()
} }
/// The row indices defining part of the CSC format. /// The row indices defining part of the CSC format.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn row_indices(&self) -> &[usize] { pub fn row_indices(&self) -> &[usize] {
self.pattern().minor_indices() self.pattern().minor_indices()
} }
/// The non-zero values defining part of the CSC format. /// The non-zero values defining part of the CSC format.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] { pub fn values(&self) -> &[T] {
self.cs.values() self.cs.values()
} }
@ -298,6 +304,7 @@ impl<T> CscMatrix<T> {
/// ------ /// ------
/// Panics if column index is out of bounds. /// Panics if column index is out of bounds.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn col(&self, index: usize) -> CscCol<T> { pub fn col(&self, index: usize) -> CscCol<T> {
self.get_col(index).expect("Row index must be in bounds") self.get_col(index).expect("Row index must be in bounds")
} }
@ -315,6 +322,7 @@ impl<T> CscMatrix<T> {
/// Return the column at the given column index, or `None` if out of bounds. /// Return the column at the given column index, or `None` if out of bounds.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn get_col(&self, index: usize) -> Option<CscCol<T>> { pub fn get_col(&self, index: usize) -> Option<CscCol<T>> {
self.cs.get_lane(index).map(|lane| CscCol { lane }) self.cs.get_lane(index).map(|lane| CscCol { lane })
} }
@ -381,6 +389,7 @@ impl<T> CscMatrix<T> {
} }
/// Returns a reference to the underlying sparsity pattern. /// Returns a reference to the underlying sparsity pattern.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn pattern(&self) -> &SparsityPattern { pub fn pattern(&self) -> &SparsityPattern {
self.cs.pattern() self.cs.pattern()
} }
@ -397,6 +406,7 @@ impl<T> CscMatrix<T> {
/// ///
/// Each call to this function incurs the cost of a binary search among the explicitly /// Each call to this function incurs the cost of a binary search among the explicitly
/// stored row entries for the given column. /// stored row entries for the given column.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn get_entry(&self, row_index: usize, col_index: usize) -> Option<SparseEntry<T>> { pub fn get_entry(&self, row_index: usize, col_index: usize) -> Option<SparseEntry<T>> {
self.cs.get_entry(col_index, row_index) self.cs.get_entry(col_index, row_index)
} }
@ -422,6 +432,7 @@ impl<T> CscMatrix<T> {
/// Panics /// Panics
/// ------ /// ------
/// Panics if `row_index` or `col_index` is out of bounds. /// Panics if `row_index` or `col_index` is out of bounds.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn index_entry(&self, row_index: usize, col_index: usize) -> SparseEntry<T> { pub fn index_entry(&self, row_index: usize, col_index: usize) -> SparseEntry<T> {
self.get_entry(row_index, col_index) self.get_entry(row_index, col_index)
.expect("Out of bounds matrix indices encountered") .expect("Out of bounds matrix indices encountered")
@ -441,6 +452,7 @@ impl<T> CscMatrix<T> {
} }
/// Returns a triplet of slices `(col_offsets, row_indices, values)` that make up the CSC data. /// Returns a triplet of slices `(col_offsets, row_indices, values)` that make up the CSC data.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn csc_data(&self) -> (&[usize], &[usize], &[T]) { pub fn csc_data(&self) -> (&[usize], &[usize], &[T]) {
self.cs.cs_data() self.cs.cs_data()
} }
@ -453,6 +465,7 @@ impl<T> CscMatrix<T> {
/// Creates a sparse matrix that contains only the explicit entries decided by the /// Creates a sparse matrix that contains only the explicit entries decided by the
/// given predicate. /// given predicate.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn filter<P>(&self, predicate: P) -> Self pub fn filter<P>(&self, predicate: P) -> Self
where where
T: Clone, T: Clone,
@ -470,6 +483,7 @@ impl<T> CscMatrix<T> {
/// Returns a new matrix representing the upper triangular part of this matrix. /// Returns a new matrix representing the upper triangular part of this matrix.
/// ///
/// The result includes the diagonal of the matrix. /// The result includes the diagonal of the matrix.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn upper_triangle(&self) -> Self pub fn upper_triangle(&self) -> Self
where where
T: Clone, T: Clone,
@ -480,6 +494,7 @@ impl<T> CscMatrix<T> {
/// Returns a new matrix representing the lower triangular part of this matrix. /// Returns a new matrix representing the lower triangular part of this matrix.
/// ///
/// The result includes the diagonal of the matrix. /// The result includes the diagonal of the matrix.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn lower_triangle(&self) -> Self pub fn lower_triangle(&self) -> Self
where where
T: Clone, T: Clone,
@ -488,6 +503,7 @@ impl<T> CscMatrix<T> {
} }
/// Returns the diagonal of the matrix as a sparse matrix. /// Returns the diagonal of the matrix as a sparse matrix.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn diagonal_as_csc(&self) -> Self pub fn diagonal_as_csc(&self) -> Self
where where
T: Clone, T: Clone,
@ -498,6 +514,7 @@ impl<T> CscMatrix<T> {
} }
/// Compute the transpose of the matrix. /// Compute the transpose of the matrix.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn transpose(&self) -> CscMatrix<T> pub fn transpose(&self) -> CscMatrix<T>
where where
T: Scalar, T: Scalar,
@ -617,24 +634,28 @@ macro_rules! impl_csc_col_common_methods {
impl<'a, T> $name { impl<'a, T> $name {
/// The number of global rows in the column. /// The number of global rows in the column.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nrows(&self) -> usize { pub fn nrows(&self) -> usize {
self.lane.minor_dim() self.lane.minor_dim()
} }
/// The number of non-zeros in this column. /// The number of non-zeros in this column.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize { pub fn nnz(&self) -> usize {
self.lane.nnz() self.lane.nnz()
} }
/// The row indices corresponding to explicitly stored entries in this column. /// The row indices corresponding to explicitly stored entries in this column.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn row_indices(&self) -> &[usize] { pub fn row_indices(&self) -> &[usize] {
self.lane.minor_indices() self.lane.minor_indices()
} }
/// The values corresponding to explicitly stored entries in this column. /// The values corresponding to explicitly stored entries in this column.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] { pub fn values(&self) -> &[T] {
self.lane.values() self.lane.values()
} }
@ -643,6 +664,7 @@ macro_rules! impl_csc_col_common_methods {
/// ///
/// Each call to this function incurs the cost of a binary search among the explicitly /// Each call to this function incurs the cost of a binary search among the explicitly
/// stored row entries. /// stored row entries.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn get_entry(&self, global_row_index: usize) -> Option<SparseEntry<T>> { pub fn get_entry(&self, global_row_index: usize) -> Option<SparseEntry<T>> {
self.lane.get_entry(global_row_index) self.lane.get_entry(global_row_index)
} }

View File

@ -192,12 +192,14 @@ impl<T> CsrMatrix<T> {
/// The number of rows in the matrix. /// The number of rows in the matrix.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nrows(&self) -> usize { pub fn nrows(&self) -> usize {
self.cs.pattern().major_dim() self.cs.pattern().major_dim()
} }
/// The number of columns in the matrix. /// The number of columns in the matrix.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn ncols(&self) -> usize { pub fn ncols(&self) -> usize {
self.cs.pattern().minor_dim() self.cs.pattern().minor_dim()
} }
@ -208,12 +210,14 @@ impl<T> CsrMatrix<T> {
/// number of algebraically zero entries in the matrix. Explicitly stored entries can still /// number of algebraically zero entries in the matrix. Explicitly stored entries can still
/// be zero. Corresponds to the number of entries in the sparsity pattern. /// be zero. Corresponds to the number of entries in the sparsity pattern.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize { pub fn nnz(&self) -> usize {
self.cs.pattern().nnz() self.cs.pattern().nnz()
} }
/// The row offsets defining part of the CSR format. /// The row offsets defining part of the CSR format.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn row_offsets(&self) -> &[usize] { pub fn row_offsets(&self) -> &[usize] {
let (offsets, _, _) = self.cs.cs_data(); let (offsets, _, _) = self.cs.cs_data();
offsets offsets
@ -221,6 +225,7 @@ impl<T> CsrMatrix<T> {
/// The column indices defining part of the CSR format. /// The column indices defining part of the CSR format.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn col_indices(&self) -> &[usize] { pub fn col_indices(&self) -> &[usize] {
let (_, indices, _) = self.cs.cs_data(); let (_, indices, _) = self.cs.cs_data();
indices indices
@ -228,6 +233,7 @@ impl<T> CsrMatrix<T> {
/// The non-zero values defining part of the CSR format. /// The non-zero values defining part of the CSR format.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] { pub fn values(&self) -> &[T] {
self.cs.values() self.cs.values()
} }
@ -300,6 +306,7 @@ impl<T> CsrMatrix<T> {
/// ------ /// ------
/// Panics if row index is out of bounds. /// Panics if row index is out of bounds.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn row(&self, index: usize) -> CsrRow<T> { pub fn row(&self, index: usize) -> CsrRow<T> {
self.get_row(index).expect("Row index must be in bounds") self.get_row(index).expect("Row index must be in bounds")
} }
@ -317,6 +324,7 @@ impl<T> CsrMatrix<T> {
/// Return the row at the given row index, or `None` if out of bounds. /// Return the row at the given row index, or `None` if out of bounds.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn get_row(&self, index: usize) -> Option<CsrRow<T>> { pub fn get_row(&self, index: usize) -> Option<CsrRow<T>> {
self.cs.get_lane(index).map(|lane| CsrRow { lane }) self.cs.get_lane(index).map(|lane| CsrRow { lane })
} }
@ -383,6 +391,7 @@ impl<T> CsrMatrix<T> {
} }
/// Returns a reference to the underlying sparsity pattern. /// Returns a reference to the underlying sparsity pattern.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn pattern(&self) -> &SparsityPattern { pub fn pattern(&self) -> &SparsityPattern {
self.cs.pattern() self.cs.pattern()
} }
@ -399,6 +408,7 @@ impl<T> CsrMatrix<T> {
/// ///
/// Each call to this function incurs the cost of a binary search among the explicitly /// Each call to this function incurs the cost of a binary search among the explicitly
/// stored column entries for the given row. /// stored column entries for the given row.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn get_entry(&self, row_index: usize, col_index: usize) -> Option<SparseEntry<T>> { pub fn get_entry(&self, row_index: usize, col_index: usize) -> Option<SparseEntry<T>> {
self.cs.get_entry(row_index, col_index) self.cs.get_entry(row_index, col_index)
} }
@ -424,6 +434,7 @@ impl<T> CsrMatrix<T> {
/// Panics /// Panics
/// ------ /// ------
/// Panics if `row_index` or `col_index` is out of bounds. /// Panics if `row_index` or `col_index` is out of bounds.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn index_entry(&self, row_index: usize, col_index: usize) -> SparseEntry<T> { pub fn index_entry(&self, row_index: usize, col_index: usize) -> SparseEntry<T> {
self.get_entry(row_index, col_index) self.get_entry(row_index, col_index)
.expect("Out of bounds matrix indices encountered") .expect("Out of bounds matrix indices encountered")
@ -443,6 +454,7 @@ impl<T> CsrMatrix<T> {
} }
/// Returns a triplet of slices `(row_offsets, col_indices, values)` that make up the CSR data. /// Returns a triplet of slices `(row_offsets, col_indices, values)` that make up the CSR data.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn csr_data(&self) -> (&[usize], &[usize], &[T]) { pub fn csr_data(&self) -> (&[usize], &[usize], &[T]) {
self.cs.cs_data() self.cs.cs_data()
} }
@ -455,6 +467,7 @@ impl<T> CsrMatrix<T> {
/// Creates a sparse matrix that contains only the explicit entries decided by the /// Creates a sparse matrix that contains only the explicit entries decided by the
/// given predicate. /// given predicate.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn filter<P>(&self, predicate: P) -> Self pub fn filter<P>(&self, predicate: P) -> Self
where where
T: Clone, T: Clone,
@ -470,6 +483,7 @@ impl<T> CsrMatrix<T> {
/// Returns a new matrix representing the upper triangular part of this matrix. /// Returns a new matrix representing the upper triangular part of this matrix.
/// ///
/// The result includes the diagonal of the matrix. /// The result includes the diagonal of the matrix.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn upper_triangle(&self) -> Self pub fn upper_triangle(&self) -> Self
where where
T: Clone, T: Clone,
@ -480,6 +494,7 @@ impl<T> CsrMatrix<T> {
/// Returns a new matrix representing the lower triangular part of this matrix. /// Returns a new matrix representing the lower triangular part of this matrix.
/// ///
/// The result includes the diagonal of the matrix. /// The result includes the diagonal of the matrix.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn lower_triangle(&self) -> Self pub fn lower_triangle(&self) -> Self
where where
T: Clone, T: Clone,
@ -488,6 +503,7 @@ impl<T> CsrMatrix<T> {
} }
/// Returns the diagonal of the matrix as a sparse matrix. /// Returns the diagonal of the matrix as a sparse matrix.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn diagonal_as_csr(&self) -> Self pub fn diagonal_as_csr(&self) -> Self
where where
T: Clone, T: Clone,
@ -498,6 +514,7 @@ impl<T> CsrMatrix<T> {
} }
/// Compute the transpose of the matrix. /// Compute the transpose of the matrix.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn transpose(&self) -> CsrMatrix<T> pub fn transpose(&self) -> CsrMatrix<T>
where where
T: Scalar, T: Scalar,
@ -617,24 +634,28 @@ macro_rules! impl_csr_row_common_methods {
impl<'a, T> $name { impl<'a, T> $name {
/// The number of global columns in the row. /// The number of global columns in the row.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn ncols(&self) -> usize { pub fn ncols(&self) -> usize {
self.lane.minor_dim() self.lane.minor_dim()
} }
/// The number of non-zeros in this row. /// The number of non-zeros in this row.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize { pub fn nnz(&self) -> usize {
self.lane.nnz() self.lane.nnz()
} }
/// The column indices corresponding to explicitly stored entries in this row. /// The column indices corresponding to explicitly stored entries in this row.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn col_indices(&self) -> &[usize] { pub fn col_indices(&self) -> &[usize] {
self.lane.minor_indices() self.lane.minor_indices()
} }
/// The values corresponding to explicitly stored entries in this row. /// The values corresponding to explicitly stored entries in this row.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] { pub fn values(&self) -> &[T] {
self.lane.values() self.lane.values()
} }
@ -644,6 +665,7 @@ macro_rules! impl_csr_row_common_methods {
/// Each call to this function incurs the cost of a binary search among the explicitly /// Each call to this function incurs the cost of a binary search among the explicitly
/// stored column entries. /// stored column entries.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn get_entry(&self, global_col_index: usize) -> Option<SparseEntry<T>> { pub fn get_entry(&self, global_col_index: usize) -> Option<SparseEntry<T>> {
self.lane.get_entry(global_col_index) self.lane.get_entry(global_col_index)
} }

View File

@ -42,6 +42,7 @@ impl CscSymbolicCholesky {
} }
/// The pattern of the Cholesky factor `L`. /// The pattern of the Cholesky factor `L`.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn l_pattern(&self) -> &SparsityPattern { pub fn l_pattern(&self) -> &SparsityPattern {
&self.l_pattern &self.l_pattern
} }
@ -171,6 +172,7 @@ impl<T: RealField> CscCholesky<T> {
} }
/// Returns a reference to the Cholesky factor `L`. /// Returns a reference to the Cholesky factor `L`.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn l(&self) -> &CscMatrix<T> { pub fn l(&self) -> &CscMatrix<T> {
&self.l_factor &self.l_factor
} }
@ -260,6 +262,7 @@ impl<T: RealField> CscCholesky<T> {
/// # Panics /// # Panics
/// ///
/// Panics if `B` is not square. /// Panics if `B` is not square.
#[must_use = "Did you mean to use solve_mut()?"]
pub fn solve<'a>(&'a self, b: impl Into<DMatrixSlice<'a, T>>) -> DMatrix<T> { pub fn solve<'a>(&'a self, b: impl Into<DMatrixSlice<'a, T>>) -> DMatrix<T> {
let b = b.into(); let b = b.into();
let mut output = b.clone_owned(); let mut output = b.clone_owned();

View File

@ -170,6 +170,7 @@ pub struct SparseFormatError {
impl SparseFormatError { impl SparseFormatError {
/// The type of error. /// The type of error.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn kind(&self) -> &SparseFormatErrorKind { pub fn kind(&self) -> &SparseFormatErrorKind {
&self.kind &self.kind
} }

View File

@ -140,11 +140,13 @@ pub enum Op<T> {
impl<T> Op<T> { impl<T> Op<T> {
/// Returns a reference to the inner value that the operation applies to. /// Returns a reference to the inner value that the operation applies to.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn inner_ref(&self) -> &T { pub fn inner_ref(&self) -> &T {
self.as_ref().into_inner() self.as_ref().into_inner()
} }
/// Returns an `Op` applied to a reference of the inner value. /// Returns an `Op` applied to a reference of the inner value.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn as_ref(&self) -> Op<&T> { pub fn as_ref(&self) -> Op<&T> {
match self { match self {
Op::NoOp(obj) => Op::NoOp(&obj), Op::NoOp(obj) => Op::NoOp(&obj),

View File

@ -96,11 +96,13 @@ impl OperationError {
} }
/// The operation error kind. /// The operation error kind.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn kind(&self) -> &OperationErrorKind { pub fn kind(&self) -> &OperationErrorKind {
&self.error_kind &self.error_kind
} }
/// The underlying error message. /// The underlying error message.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn message(&self) -> &str { pub fn message(&self) -> &str {
self.message.as_str() self.message.as_str()
} }

View File

@ -60,18 +60,21 @@ impl SparsityPattern {
/// The offsets for the major dimension. /// The offsets for the major dimension.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn major_offsets(&self) -> &[usize] { pub fn major_offsets(&self) -> &[usize] {
&self.major_offsets &self.major_offsets
} }
/// The indices for the minor dimension. /// The indices for the minor dimension.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn minor_indices(&self) -> &[usize] { pub fn minor_indices(&self) -> &[usize] {
&self.minor_indices &self.minor_indices
} }
/// The number of major lanes in the pattern. /// The number of major lanes in the pattern.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn major_dim(&self) -> usize { pub fn major_dim(&self) -> usize {
assert!(self.major_offsets.len() > 0); assert!(self.major_offsets.len() > 0);
self.major_offsets.len() - 1 self.major_offsets.len() - 1
@ -79,12 +82,14 @@ impl SparsityPattern {
/// The number of minor lanes in the pattern. /// The number of minor lanes in the pattern.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn minor_dim(&self) -> usize { pub fn minor_dim(&self) -> usize {
self.minor_dim self.minor_dim
} }
/// The number of "non-zeros", i.e. explicitly stored entries in the pattern. /// The number of "non-zeros", i.e. explicitly stored entries in the pattern.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize { pub fn nnz(&self) -> usize {
self.minor_indices.len() self.minor_indices.len()
} }
@ -96,12 +101,14 @@ impl SparsityPattern {
/// ///
/// Panics if `major_index` is out of bounds. /// Panics if `major_index` is out of bounds.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn lane(&self, major_index: usize) -> &[usize] { pub fn lane(&self, major_index: usize) -> &[usize] {
self.get_lane(major_index).unwrap() self.get_lane(major_index).unwrap()
} }
/// Get the lane at the given index, or `None` if out of bounds. /// Get the lane at the given index, or `None` if out of bounds.
#[inline] #[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn get_lane(&self, major_index: usize) -> Option<&[usize]> { pub fn get_lane(&self, major_index: usize) -> Option<&[usize]> {
let offset_begin = *self.major_offsets().get(major_index)?; let offset_begin = *self.major_offsets().get(major_index)?;
let offset_end = *self.major_offsets().get(major_index + 1)?; let offset_end = *self.major_offsets().get(major_index + 1)?;
@ -197,6 +204,7 @@ impl SparsityPattern {
/// assert_eq!(entries, vec![(0, 0), (0, 2), (1, 1), (2, 0)]); /// assert_eq!(entries, vec![(0, 0), (0, 2), (1, 1), (2, 0)]);
/// ``` /// ```
/// ///
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn entries(&self) -> SparsityPatternIter { pub fn entries(&self) -> SparsityPatternIter {
SparsityPatternIter::from_pattern(self) SparsityPatternIter::from_pattern(self)
} }
@ -228,6 +236,7 @@ impl SparsityPattern {
/// ///
/// This is analogous to matrix transposition, i.e. an entry `(i, j)` becomes `(j, i)` in the /// This is analogous to matrix transposition, i.e. an entry `(i, j)` becomes `(j, i)` in the
/// new pattern. /// new pattern.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn transpose(&self) -> Self { pub fn transpose(&self) -> Self {
// By using unit () values, we can use the same routines as for CSR/CSC matrices // By using unit () values, we can use the same routines as for CSR/CSC matrices
let values = vec![(); self.nnz()]; let values = vec![(); self.nnz()];