From 3be81be2e3298c882eed75a49334dfac1dd686f1 Mon Sep 17 00:00:00 2001 From: Fabian Loeschner Date: Tue, 9 Nov 2021 17:15:40 +0100 Subject: [PATCH] Updated more error messages --- nalgebra-sparse/src/convert/serial.rs | 12 ++++++------ nalgebra-sparse/src/factorization/cholesky.rs | 6 +++--- nalgebra-sparse/src/ops/serial/cs.rs | 4 ++-- nalgebra-sparse/src/ops/serial/csc.rs | 6 +++--- nalgebra-sparse/src/ops/serial/mod.rs | 8 ++++---- nalgebra-sparse/src/ops/serial/pattern.rs | 8 ++++---- nalgebra-sparse/src/pattern.rs | 2 +- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/nalgebra-sparse/src/convert/serial.rs b/nalgebra-sparse/src/convert/serial.rs index ecbe1dab..9fc3d04e 100644 --- a/nalgebra-sparse/src/convert/serial.rs +++ b/nalgebra-sparse/src/convert/serial.rs @@ -64,7 +64,7 @@ where // TODO: Avoid "try_from" since it validates the data? (requires unsafe, should benchmark // to see if it can be justified for performance reasons) CsrMatrix::try_from_csr_data(coo.nrows(), coo.ncols(), offsets, indices, values) - .expect("Internal error: Invalid CSR data during COO->CSR conversion") + .expect("internal error: invalid CSR data during COO->CSR conversion") } /// Converts a [`CsrMatrix`] to a [`CooMatrix`]. @@ -120,7 +120,7 @@ where // TODO: Consider circumventing the data validity check here // (would require unsafe, should benchmark) CsrMatrix::try_from_csr_data(dense.nrows(), dense.ncols(), row_offsets, col_idx, values) - .expect("Internal error: Invalid CsrMatrix format during dense-> CSR conversion") + .expect("internal error: invalid CsrMatrix format during dense -> CSR conversion") } /// Converts a [`CooMatrix`] to a [`CscMatrix`]. @@ -138,7 +138,7 @@ where // TODO: Avoid "try_from" since it validates the data? (requires unsafe, should benchmark // to see if it can be justified for performance reasons) CscMatrix::try_from_csc_data(coo.nrows(), coo.ncols(), offsets, indices, values) - .expect("Internal error: Invalid CSC data during COO->CSC conversion") + .expect("internal error: invalid CSC data during COO -> CSC conversion") } /// Converts a [`CscMatrix`] to a [`CooMatrix`]. @@ -194,7 +194,7 @@ where // TODO: Consider circumventing the data validity check here // (would require unsafe, should benchmark) CscMatrix::try_from_csc_data(dense.nrows(), dense.ncols(), col_offsets, row_idx, values) - .expect("Internal error: Invalid CscMatrix format during dense-> CSC conversion") + .expect("internal error: invalid CscMatrix format during dense -> CSC conversion") } /// Converts a [`CsrMatrix`] to a [`CscMatrix`]. @@ -212,7 +212,7 @@ where // TODO: Avoid data validity check? CscMatrix::try_from_csc_data(csr.nrows(), csr.ncols(), offsets, indices, values) - .expect("Internal error: Invalid CSC data during CSR->CSC conversion") + .expect("internal error: invalid CSC data during CSR -> CSC conversion") } /// Converts a [`CscMatrix`] to a [`CsrMatrix`]. @@ -230,7 +230,7 @@ where // TODO: Avoid data validity check? CsrMatrix::try_from_csr_data(csc.nrows(), csc.ncols(), offsets, indices, values) - .expect("Internal error: Invalid CSR data during CSC->CSR conversion") + .expect("internal error: invalid CSR data during CSC -> CSR conversion") } fn convert_coo_cs( diff --git a/nalgebra-sparse/src/factorization/cholesky.rs b/nalgebra-sparse/src/factorization/cholesky.rs index 1f653278..b306f104 100644 --- a/nalgebra-sparse/src/factorization/cholesky.rs +++ b/nalgebra-sparse/src/factorization/cholesky.rs @@ -31,7 +31,7 @@ impl CscSymbolicCholesky { assert_eq!( pattern.major_dim(), pattern.minor_dim(), - "Major and minor dimensions must be the same (square matrix)." + "major and minor dimensions must be the same (square matrix)" ); let (l_pattern, u_pattern) = nonzero_pattern(&pattern); Self { @@ -82,7 +82,7 @@ pub enum CholeskyError { impl Display for CholeskyError { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "Matrix is not positive definite") + write!(f, "matrix is not positive definite") } } @@ -279,7 +279,7 @@ impl CscCholesky { /// /// Panics if `b` is not square. pub fn solve_mut<'a>(&'a self, b: impl Into>) { - let expect_msg = "If the Cholesky factorization succeeded,\ + let expect_msg = "if the Cholesky factorization succeeded,\ then the triangular solve should never fail"; // Solve LY = B let mut y = b.into(); diff --git a/nalgebra-sparse/src/ops/serial/cs.rs b/nalgebra-sparse/src/ops/serial/cs.rs index 86484053..9cd46152 100644 --- a/nalgebra-sparse/src/ops/serial/cs.rs +++ b/nalgebra-sparse/src/ops/serial/cs.rs @@ -8,7 +8,7 @@ use num_traits::{One, Zero}; fn spmm_cs_unexpected_entry() -> OperationError { OperationError::from_kind_and_message( OperationErrorKind::InvalidPattern, - String::from("Found unexpected entry that is not present in `c`."), + String::from("found unexpected entry that is not present in `c`"), ) } @@ -62,7 +62,7 @@ where fn spadd_cs_unexpected_entry() -> OperationError { OperationError::from_kind_and_message( OperationErrorKind::InvalidPattern, - String::from("Found entry in `op(a)` that is not present in `c`."), + String::from("found entry in `op(a)` that is not present in `c`"), ) } diff --git a/nalgebra-sparse/src/ops/serial/csc.rs b/nalgebra-sparse/src/ops/serial/csc.rs index e5c9ae4e..db7b81ba 100644 --- a/nalgebra-sparse/src/ops/serial/csc.rs +++ b/nalgebra-sparse/src/ops/serial/csc.rs @@ -132,12 +132,12 @@ pub fn spsolve_csc_lower_triangular<'a, T: RealField>( assert_eq!( l_matrix.nrows(), l_matrix.ncols(), - "Matrix must be square for triangular solve." + "matrix must be square for triangular solve" ); assert_eq!( l_matrix.nrows(), b.nrows(), - "Dimension mismatch in sparse lower triangular solver." + "dimension mismatch in sparse lower triangular solver" ); match l { Op::NoOp(a) => spsolve_csc_lower_triangular_no_transpose(a, b), @@ -196,7 +196,7 @@ fn spsolve_csc_lower_triangular_no_transpose( } fn spsolve_encountered_zero_diagonal() -> Result<(), OperationError> { - let message = "Matrix contains at least one diagonal entry that is zero."; + let message = "matrix contains at least one diagonal entry that is zero"; Err(OperationError::from_kind_and_message( OperationErrorKind::Singular, String::from(message), diff --git a/nalgebra-sparse/src/ops/serial/mod.rs b/nalgebra-sparse/src/ops/serial/mod.rs index d8f1a343..3ce47a66 100644 --- a/nalgebra-sparse/src/ops/serial/mod.rs +++ b/nalgebra-sparse/src/ops/serial/mod.rs @@ -108,16 +108,16 @@ impl OperationError { impl fmt::Display for OperationError { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "Sparse matrix operation error: ")?; + write!(f, "sparse matrix operation error: ")?; match self.kind() { OperationErrorKind::InvalidPattern => { - write!(f, "InvalidPattern")?; + write!(f, "invalid pattern")?; } OperationErrorKind::Singular => { - write!(f, "Singular")?; + write!(f, "singular")?; } } - write!(f, " Message: {}", self.message) + write!(f, " message: {}", self.message) } } diff --git a/nalgebra-sparse/src/ops/serial/pattern.rs b/nalgebra-sparse/src/ops/serial/pattern.rs index b73f3375..97137e46 100644 --- a/nalgebra-sparse/src/ops/serial/pattern.rs +++ b/nalgebra-sparse/src/ops/serial/pattern.rs @@ -16,12 +16,12 @@ pub fn spadd_pattern(a: &SparsityPattern, b: &SparsityPattern) -> SparsityPatter assert_eq!( a.major_dim(), b.major_dim(), - "Patterns must have identical major dimensions." + "patterns must have identical major dimensions" ); assert_eq!( a.minor_dim(), b.minor_dim(), - "Patterns must have identical minor dimensions." + "patterns must have identical minor dimensions" ); let mut offsets = Vec::new(); @@ -40,7 +40,7 @@ pub fn spadd_pattern(a: &SparsityPattern, b: &SparsityPattern) -> SparsityPatter // TODO: Consider circumventing format checks? (requires unsafe, should benchmark first) SparsityPattern::try_from_offsets_and_indices(a.major_dim(), a.minor_dim(), offsets, indices) - .expect("Internal error: Pattern must be valid by definition") + .expect("internal error: pattern must be valid by definition") } /// Sparse matrix multiplication pattern construction, `C <- A * B`. @@ -114,7 +114,7 @@ pub fn spmm_csr_pattern(a: &SparsityPattern, b: &SparsityPattern) -> SparsityPat } SparsityPattern::try_from_offsets_and_indices(a.major_dim(), b.minor_dim(), offsets, indices) - .expect("Internal error: Invalid pattern during matrix multiplication pattern construction") + .expect("internal error: invalid pattern during matrix multiplication pattern construction") } /// Iterate over the union of the two sets represented by sorted slices diff --git a/nalgebra-sparse/src/pattern.rs b/nalgebra-sparse/src/pattern.rs index 1d92dae3..818cf748 100644 --- a/nalgebra-sparse/src/pattern.rs +++ b/nalgebra-sparse/src/pattern.rs @@ -259,7 +259,7 @@ impl SparsityPattern { new_offsets, new_indices, ) - .expect("internal error: Transpose should never fail") + .expect("internal error: transpose should never fail") } }