rlst_suitesparse/umfpack/
error.rs1use std::error::Error;
2use std::fmt::{Display, Formatter};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum UmfpackError {
7 EmptyMatrix,
9 NonSquareMatrix {
11 rows: usize,
13 columns: usize,
15 },
16 InvalidCsr(&'static str),
18 IndexOutOfRange(usize),
21 DimensionMismatch {
23 expected: usize,
25 actual: usize,
27 },
28 NonContiguousArray(&'static str),
30 DataUnavailable(&'static str),
32 NativeFailure {
34 operation: &'static str,
36 status: i32,
38 },
39 NullHandle(&'static str),
41}
42
43impl Display for UmfpackError {
44 fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
45 match self {
46 Self::EmptyMatrix => write!(formatter, "UMFPACK does not accept an empty matrix"),
47 Self::NonSquareMatrix { rows, columns } => {
48 write!(
49 formatter,
50 "UMFPACK requires a square matrix, got {rows}x{columns}"
51 )
52 }
53 Self::InvalidCsr(message) => write!(formatter, "invalid CSR matrix: {message}"),
54 Self::IndexOutOfRange(index) => {
55 write!(
56 formatter,
57 "sparse index {index} cannot be represented by UMFPACK"
58 )
59 }
60 Self::DimensionMismatch { expected, actual } => {
61 write!(
62 formatter,
63 "dimension mismatch: expected {expected}, got {actual}"
64 )
65 }
66 Self::NonContiguousArray(name) => {
67 write!(formatter, "{name} must be stored contiguously")
68 }
69 Self::DataUnavailable(name) => write!(formatter, "{name} does not expose raw data"),
70 Self::NativeFailure { operation, status } => {
71 write!(formatter, "UMFPACK {operation} failed with status {status}")
72 }
73 Self::NullHandle(operation) => {
74 write!(formatter, "UMFPACK {operation} returned a null handle")
75 }
76 }
77 }
78}
79
80impl Error for UmfpackError {}
81
82pub type UmfpackResult<T> = Result<T, UmfpackError>;