1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use std::error::Error;
use std::fmt::{Display, Formatter};
/// Errors returned by UMFPACK bindings.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum UmfpackError {
/// The input matrix has a zero-sized dimension.
EmptyMatrix,
/// UMFPACK's direct solver requires a square matrix.
NonSquareMatrix {
/// Number of rows in the matrix.
rows: usize,
/// Number of columns in the matrix.
columns: usize,
},
/// The CSR data does not satisfy the expected storage invariants.
InvalidCsr(&'static str),
/// A matrix dimension or sparse index cannot be represented by UMFPACK's
/// 64-bit index type.
IndexOutOfRange(usize),
/// A right-hand side or solution has the wrong length.
DimensionMismatch {
/// Required vector length.
expected: usize,
/// Actual vector length.
actual: usize,
},
/// An array argument is not contiguous in memory.
NonContiguousArray(&'static str),
/// An array argument does not expose its backing data.
DataUnavailable(&'static str),
/// UMFPACK returned a failure status.
NativeFailure {
/// Native operation that failed.
operation: &'static str,
/// UMFPACK status code.
status: i32,
},
/// UMFPACK reported success but did not return the expected native handle.
NullHandle(&'static str),
}
impl Display for UmfpackError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::EmptyMatrix => write!(formatter, "UMFPACK does not accept an empty matrix"),
Self::NonSquareMatrix { rows, columns } => {
write!(
formatter,
"UMFPACK requires a square matrix, got {rows}x{columns}"
)
}
Self::InvalidCsr(message) => write!(formatter, "invalid CSR matrix: {message}"),
Self::IndexOutOfRange(index) => {
write!(
formatter,
"sparse index {index} cannot be represented by UMFPACK"
)
}
Self::DimensionMismatch { expected, actual } => {
write!(
formatter,
"dimension mismatch: expected {expected}, got {actual}"
)
}
Self::NonContiguousArray(name) => {
write!(formatter, "{name} must be stored contiguously")
}
Self::DataUnavailable(name) => write!(formatter, "{name} does not expose raw data"),
Self::NativeFailure { operation, status } => {
write!(formatter, "UMFPACK {operation} failed with status {status}")
}
Self::NullHandle(operation) => {
write!(formatter, "UMFPACK {operation} returned a null handle")
}
}
}
}
impl Error for UmfpackError {}
/// Result type returned by this crate.
pub type UmfpackResult<T> = Result<T, UmfpackError>;