forked from M-Labs/nalgebra
Updated more error messages
This commit is contained in:
parent
7e67d920a7
commit
3be81be2e3
@ -64,7 +64,7 @@ where
|
|||||||
// TODO: Avoid "try_from" since it validates the data? (requires unsafe, should benchmark
|
// TODO: Avoid "try_from" since it validates the data? (requires unsafe, should benchmark
|
||||||
// to see if it can be justified for performance reasons)
|
// to see if it can be justified for performance reasons)
|
||||||
CsrMatrix::try_from_csr_data(coo.nrows(), coo.ncols(), offsets, indices, values)
|
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`].
|
/// Converts a [`CsrMatrix`] to a [`CooMatrix`].
|
||||||
@ -120,7 +120,7 @@ where
|
|||||||
// TODO: Consider circumventing the data validity check here
|
// TODO: Consider circumventing the data validity check here
|
||||||
// (would require unsafe, should benchmark)
|
// (would require unsafe, should benchmark)
|
||||||
CsrMatrix::try_from_csr_data(dense.nrows(), dense.ncols(), row_offsets, col_idx, values)
|
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`].
|
/// Converts a [`CooMatrix`] to a [`CscMatrix`].
|
||||||
@ -138,7 +138,7 @@ where
|
|||||||
// TODO: Avoid "try_from" since it validates the data? (requires unsafe, should benchmark
|
// TODO: Avoid "try_from" since it validates the data? (requires unsafe, should benchmark
|
||||||
// to see if it can be justified for performance reasons)
|
// to see if it can be justified for performance reasons)
|
||||||
CscMatrix::try_from_csc_data(coo.nrows(), coo.ncols(), offsets, indices, values)
|
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`].
|
/// Converts a [`CscMatrix`] to a [`CooMatrix`].
|
||||||
@ -194,7 +194,7 @@ where
|
|||||||
// TODO: Consider circumventing the data validity check here
|
// TODO: Consider circumventing the data validity check here
|
||||||
// (would require unsafe, should benchmark)
|
// (would require unsafe, should benchmark)
|
||||||
CscMatrix::try_from_csc_data(dense.nrows(), dense.ncols(), col_offsets, row_idx, values)
|
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`].
|
/// Converts a [`CsrMatrix`] to a [`CscMatrix`].
|
||||||
@ -212,7 +212,7 @@ where
|
|||||||
|
|
||||||
// TODO: Avoid data validity check?
|
// TODO: Avoid data validity check?
|
||||||
CscMatrix::try_from_csc_data(csr.nrows(), csr.ncols(), offsets, indices, values)
|
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`].
|
/// Converts a [`CscMatrix`] to a [`CsrMatrix`].
|
||||||
@ -230,7 +230,7 @@ where
|
|||||||
|
|
||||||
// TODO: Avoid data validity check?
|
// TODO: Avoid data validity check?
|
||||||
CsrMatrix::try_from_csr_data(csc.nrows(), csc.ncols(), offsets, indices, values)
|
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<T>(
|
fn convert_coo_cs<T>(
|
||||||
|
@ -31,7 +31,7 @@ impl CscSymbolicCholesky {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
pattern.major_dim(),
|
pattern.major_dim(),
|
||||||
pattern.minor_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);
|
let (l_pattern, u_pattern) = nonzero_pattern(&pattern);
|
||||||
Self {
|
Self {
|
||||||
@ -82,7 +82,7 @@ pub enum CholeskyError {
|
|||||||
|
|
||||||
impl Display for CholeskyError {
|
impl Display for CholeskyError {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
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<T: RealField> CscCholesky<T> {
|
|||||||
///
|
///
|
||||||
/// Panics if `b` is not square.
|
/// Panics if `b` is not square.
|
||||||
pub fn solve_mut<'a>(&'a self, b: impl Into<DMatrixSliceMut<'a, T>>) {
|
pub fn solve_mut<'a>(&'a self, b: impl Into<DMatrixSliceMut<'a, T>>) {
|
||||||
let expect_msg = "If the Cholesky factorization succeeded,\
|
let expect_msg = "if the Cholesky factorization succeeded,\
|
||||||
then the triangular solve should never fail";
|
then the triangular solve should never fail";
|
||||||
// Solve LY = B
|
// Solve LY = B
|
||||||
let mut y = b.into();
|
let mut y = b.into();
|
||||||
|
@ -8,7 +8,7 @@ use num_traits::{One, Zero};
|
|||||||
fn spmm_cs_unexpected_entry() -> OperationError {
|
fn spmm_cs_unexpected_entry() -> OperationError {
|
||||||
OperationError::from_kind_and_message(
|
OperationError::from_kind_and_message(
|
||||||
OperationErrorKind::InvalidPattern,
|
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 {
|
fn spadd_cs_unexpected_entry() -> OperationError {
|
||||||
OperationError::from_kind_and_message(
|
OperationError::from_kind_and_message(
|
||||||
OperationErrorKind::InvalidPattern,
|
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`"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,12 +132,12 @@ pub fn spsolve_csc_lower_triangular<'a, T: RealField>(
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
l_matrix.nrows(),
|
l_matrix.nrows(),
|
||||||
l_matrix.ncols(),
|
l_matrix.ncols(),
|
||||||
"Matrix must be square for triangular solve."
|
"matrix must be square for triangular solve"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
l_matrix.nrows(),
|
l_matrix.nrows(),
|
||||||
b.nrows(),
|
b.nrows(),
|
||||||
"Dimension mismatch in sparse lower triangular solver."
|
"dimension mismatch in sparse lower triangular solver"
|
||||||
);
|
);
|
||||||
match l {
|
match l {
|
||||||
Op::NoOp(a) => spsolve_csc_lower_triangular_no_transpose(a, b),
|
Op::NoOp(a) => spsolve_csc_lower_triangular_no_transpose(a, b),
|
||||||
@ -196,7 +196,7 @@ fn spsolve_csc_lower_triangular_no_transpose<T: RealField>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn spsolve_encountered_zero_diagonal() -> Result<(), OperationError> {
|
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(
|
Err(OperationError::from_kind_and_message(
|
||||||
OperationErrorKind::Singular,
|
OperationErrorKind::Singular,
|
||||||
String::from(message),
|
String::from(message),
|
||||||
|
@ -108,16 +108,16 @@ impl OperationError {
|
|||||||
|
|
||||||
impl fmt::Display for OperationError {
|
impl fmt::Display for OperationError {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "Sparse matrix operation error: ")?;
|
write!(f, "sparse matrix operation error: ")?;
|
||||||
match self.kind() {
|
match self.kind() {
|
||||||
OperationErrorKind::InvalidPattern => {
|
OperationErrorKind::InvalidPattern => {
|
||||||
write!(f, "InvalidPattern")?;
|
write!(f, "invalid pattern")?;
|
||||||
}
|
}
|
||||||
OperationErrorKind::Singular => {
|
OperationErrorKind::Singular => {
|
||||||
write!(f, "Singular")?;
|
write!(f, "singular")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write!(f, " Message: {}", self.message)
|
write!(f, " message: {}", self.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,12 +16,12 @@ pub fn spadd_pattern(a: &SparsityPattern, b: &SparsityPattern) -> SparsityPatter
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
a.major_dim(),
|
a.major_dim(),
|
||||||
b.major_dim(),
|
b.major_dim(),
|
||||||
"Patterns must have identical major dimensions."
|
"patterns must have identical major dimensions"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
a.minor_dim(),
|
a.minor_dim(),
|
||||||
b.minor_dim(),
|
b.minor_dim(),
|
||||||
"Patterns must have identical minor dimensions."
|
"patterns must have identical minor dimensions"
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut offsets = Vec::new();
|
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)
|
// TODO: Consider circumventing format checks? (requires unsafe, should benchmark first)
|
||||||
SparsityPattern::try_from_offsets_and_indices(a.major_dim(), a.minor_dim(), offsets, indices)
|
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`.
|
/// 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)
|
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
|
/// Iterate over the union of the two sets represented by sorted slices
|
||||||
|
@ -259,7 +259,7 @@ impl SparsityPattern {
|
|||||||
new_offsets,
|
new_offsets,
|
||||||
new_indices,
|
new_indices,
|
||||||
)
|
)
|
||||||
.expect("internal error: Transpose should never fail")
|
.expect("internal error: transpose should never fail")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user