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.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn l(&self) -> OMatrix<T, D, D> {
let mut res = self.l.clone();
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
/// 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> {
&self.l
}

View File

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

View File

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

View File

@ -85,6 +85,7 @@ where
/// Gets the lower-triangular matrix part of the decomposition.
#[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>> {
let (nrows, ncols) = self.lu.data.shape();
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.
#[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> {
let (nrows, ncols) = self.lu.data.shape();
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.
/// To permute rows of a matrix or vector, use the method `self.permute(...)` instead.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn p(&self) -> OMatrix<T, R, R> {
let (dim, _) = self.lu.data.shape();
let mut id = Matrix::identity_generic(dim, dim);
@ -124,6 +127,7 @@ where
/// Gets the LAPACK permutation indices.
#[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>> {
&self.p
}

View File

@ -92,6 +92,7 @@ where
/// Retrieves the upper trapezoidal submatrix `R` of this decomposition.
#[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> {
let (nrows, ncols) = self.qr.data.shape();
self.qr.rows_generic(0, nrows.min(ncols)).upper_triangle()
@ -117,6 +118,7 @@ where
/// Computes the orthogonal matrix `Q` of this decomposition.
#[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>> {
let (nrows, ncols) = self.qr.data.shape();
let min_nrows_ncols = nrows.min(ncols);

View File

@ -138,6 +138,7 @@ where
/// Computes the real eigenvalues of the decomposed matrix.
///
/// 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>> {
if self.im.iter().all(|e| e.is_zero()) {
Some(self.re.clone())
@ -147,6 +148,7 @@ where
}
/// 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>
where
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.
#[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> {
let nrows = self.u.data.shape().0;
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
/// the given `epsilon`).
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn rank(&self, epsilon: $t) -> usize {
let mut i = 0;

View File

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

View File

@ -173,12 +173,14 @@ impl<T> CooMatrix<T> {
/// The number of rows in the matrix.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nrows(&self) -> usize {
self.nrows
}
/// The number of columns in the matrix.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn ncols(&self) -> usize {
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
/// to its CSR representation.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize {
self.values.len()
}
/// 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] {
&self.row_indices
}
/// 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] {
&self.col_indices
}
/// 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] {
&self.values
}

View File

@ -32,11 +32,13 @@ impl<T> CsMatrix<T> {
}
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn pattern(&self) -> &SparsityPattern {
&self.sparsity_pattern
}
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] {
&self.values
}
@ -48,6 +50,7 @@ impl<T> CsMatrix<T> {
/// Returns the raw data represented as a tuple `(major_offsets, minor_indices, values)`.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn cs_data(&self) -> (&[usize], &[usize], &[T]) {
let pattern = self.pattern();
(
@ -88,6 +91,7 @@ impl<T> CsMatrix<T> {
/// Internal method for simplifying access to a lane's data
#[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>> {
let row_begin = *self.sparsity_pattern.major_offsets().get(row_index)?;
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
/// 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>> {
let row_range = self.get_index_range(major_index)?;
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)
}
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn get_lane(&self, index: usize) -> Option<CsLane<T>> {
let range = self.get_index_range(index)?;
let (_, minor_indices, values) = self.cs_data();
@ -172,6 +178,7 @@ impl<T> CsMatrix<T> {
}
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn filter<P>(&self, predicate: P) -> Self
where
T: Clone,
@ -207,6 +214,7 @@ impl<T> CsMatrix<T> {
}
/// 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
where
T: Clone,
@ -372,26 +380,31 @@ macro_rules! impl_cs_lane_common_methods {
($name:ty) => {
impl<'a, T> $name {
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn minor_dim(&self) -> usize {
self.minor_dim
}
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize {
self.minor_indices.len()
}
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn minor_indices(&self) -> &[usize] {
self.minor_indices
}
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] {
self.values
}
#[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>> {
get_entry_from_slices(
self.minor_dim,

View File

@ -192,12 +192,14 @@ impl<T> CscMatrix<T> {
/// The number of rows in the matrix.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nrows(&self) -> usize {
self.cs.pattern().minor_dim()
}
/// The number of columns in the matrix.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn ncols(&self) -> usize {
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
/// be zero. Corresponds to the number of entries in the sparsity pattern.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize {
self.pattern().nnz()
}
/// The column offsets defining part of the CSC format.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn col_offsets(&self) -> &[usize] {
self.pattern().major_offsets()
}
/// The row indices defining part of the CSC format.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn row_indices(&self) -> &[usize] {
self.pattern().minor_indices()
}
/// The non-zero values defining part of the CSC format.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] {
self.cs.values()
}
@ -298,6 +304,7 @@ impl<T> CscMatrix<T> {
/// ------
/// Panics if column index is out of bounds.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn col(&self, index: usize) -> CscCol<T> {
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.
#[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>> {
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.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn pattern(&self) -> &SparsityPattern {
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
/// 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>> {
self.cs.get_entry(col_index, row_index)
}
@ -422,6 +432,7 @@ impl<T> CscMatrix<T> {
/// Panics
/// ------
/// 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> {
self.get_entry(row_index, col_index)
.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.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn csc_data(&self) -> (&[usize], &[usize], &[T]) {
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
/// given predicate.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn filter<P>(&self, predicate: P) -> Self
where
T: Clone,
@ -470,6 +483,7 @@ impl<T> CscMatrix<T> {
/// Returns a new matrix representing the upper triangular part of this 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
where
T: Clone,
@ -480,6 +494,7 @@ impl<T> CscMatrix<T> {
/// Returns a new matrix representing the lower triangular part of this 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
where
T: Clone,
@ -488,6 +503,7 @@ impl<T> CscMatrix<T> {
}
/// 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
where
T: Clone,
@ -498,6 +514,7 @@ impl<T> CscMatrix<T> {
}
/// 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>
where
T: Scalar,
@ -617,24 +634,28 @@ macro_rules! impl_csc_col_common_methods {
impl<'a, T> $name {
/// The number of global rows in the column.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nrows(&self) -> usize {
self.lane.minor_dim()
}
/// The number of non-zeros in this column.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize {
self.lane.nnz()
}
/// The row indices corresponding to explicitly stored entries in this column.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn row_indices(&self) -> &[usize] {
self.lane.minor_indices()
}
/// The values corresponding to explicitly stored entries in this column.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] {
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
/// 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>> {
self.lane.get_entry(global_row_index)
}

View File

@ -192,12 +192,14 @@ impl<T> CsrMatrix<T> {
/// The number of rows in the matrix.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nrows(&self) -> usize {
self.cs.pattern().major_dim()
}
/// The number of columns in the matrix.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn ncols(&self) -> usize {
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
/// be zero. Corresponds to the number of entries in the sparsity pattern.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize {
self.cs.pattern().nnz()
}
/// The row offsets defining part of the CSR format.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn row_offsets(&self) -> &[usize] {
let (offsets, _, _) = self.cs.cs_data();
offsets
@ -221,6 +225,7 @@ impl<T> CsrMatrix<T> {
/// The column indices defining part of the CSR format.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn col_indices(&self) -> &[usize] {
let (_, indices, _) = self.cs.cs_data();
indices
@ -228,6 +233,7 @@ impl<T> CsrMatrix<T> {
/// The non-zero values defining part of the CSR format.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] {
self.cs.values()
}
@ -300,6 +306,7 @@ impl<T> CsrMatrix<T> {
/// ------
/// Panics if row index is out of bounds.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn row(&self, index: usize) -> CsrRow<T> {
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.
#[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>> {
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.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn pattern(&self) -> &SparsityPattern {
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
/// 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>> {
self.cs.get_entry(row_index, col_index)
}
@ -424,6 +434,7 @@ impl<T> CsrMatrix<T> {
/// Panics
/// ------
/// 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> {
self.get_entry(row_index, col_index)
.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.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn csr_data(&self) -> (&[usize], &[usize], &[T]) {
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
/// given predicate.
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn filter<P>(&self, predicate: P) -> Self
where
T: Clone,
@ -470,6 +483,7 @@ impl<T> CsrMatrix<T> {
/// Returns a new matrix representing the upper triangular part of this 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
where
T: Clone,
@ -480,6 +494,7 @@ impl<T> CsrMatrix<T> {
/// Returns a new matrix representing the lower triangular part of this 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
where
T: Clone,
@ -488,6 +503,7 @@ impl<T> CsrMatrix<T> {
}
/// 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
where
T: Clone,
@ -498,6 +514,7 @@ impl<T> CsrMatrix<T> {
}
/// 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>
where
T: Scalar,
@ -617,24 +634,28 @@ macro_rules! impl_csr_row_common_methods {
impl<'a, T> $name {
/// The number of global columns in the row.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn ncols(&self) -> usize {
self.lane.minor_dim()
}
/// The number of non-zeros in this row.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn nnz(&self) -> usize {
self.lane.nnz()
}
/// The column indices corresponding to explicitly stored entries in this row.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn col_indices(&self) -> &[usize] {
self.lane.minor_indices()
}
/// The values corresponding to explicitly stored entries in this row.
#[inline]
#[must_use = "This function does not mutate self. You should use the return value."]
pub fn values(&self) -> &[T] {
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
/// stored column entries.
#[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>> {
self.lane.get_entry(global_col_index)
}

View File

@ -42,6 +42,7 @@ impl CscSymbolicCholesky {
}
/// 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 {
&self.l_pattern
}
@ -171,6 +172,7 @@ impl<T: RealField> CscCholesky<T> {
}
/// 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> {
&self.l_factor
}
@ -260,6 +262,7 @@ impl<T: RealField> CscCholesky<T> {
/// # Panics
///
/// 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> {
let b = b.into();
let mut output = b.clone_owned();

View File

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

View File

@ -140,11 +140,13 @@ pub enum Op<T> {
impl<T> Op<T> {
/// 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 {
self.as_ref().into_inner()
}
/// 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> {
match self {
Op::NoOp(obj) => Op::NoOp(&obj),

View File

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

View File

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