Skip to main content

trueno_solve/
error.rs

1//! Solver error types.
2
3/// Errors from solver operations.
4#[derive(Debug, thiserror::Error)]
5pub enum SolverError {
6    /// Matrix is not square.
7    #[error("matrix must be square: got {rows}x{cols}")]
8    NotSquare {
9        /// Number of rows.
10        rows: usize,
11        /// Number of columns.
12        cols: usize,
13    },
14
15    /// Matrix is singular (zero pivot encountered).
16    #[error("singular matrix: zero pivot at position {0}")]
17    SingularMatrix(usize),
18
19    /// Matrix is not positive definite.
20    #[error("matrix is not positive definite: non-positive diagonal at position {0}")]
21    NotPositiveDefinite(usize),
22
23    /// Dimension mismatch in solve operation.
24    #[error("dimension mismatch: matrix is {matrix_n}x{matrix_n}, rhs has {rhs_len} elements")]
25    DimensionMismatch {
26        /// Matrix dimension.
27        matrix_n: usize,
28        /// RHS vector length.
29        rhs_len: usize,
30    },
31
32    /// SVD dimension mismatch.
33    #[error("SVD: matrix is {m}x{n}, but output buffers have wrong dimensions")]
34    SvdDimensionMismatch {
35        /// Rows.
36        m: usize,
37        /// Columns.
38        n: usize,
39    },
40
41    /// QR dimension mismatch.
42    #[error("QR: matrix is {m}x{n} (requires m >= n)")]
43    QrNotTallSkinny {
44        /// Rows.
45        m: usize,
46        /// Columns.
47        n: usize,
48    },
49
50    /// Invalid input parameter.
51    #[error("invalid input: {reason}")]
52    InvalidInput {
53        /// Reason for invalidity.
54        reason: &'static str,
55    },
56
57    /// Buffer length mismatch for BLAS operations.
58    #[error("buffer length {got} does not match expected {expected} for {rows}x{cols} matrix")]
59    BufferLengthMismatch {
60        /// Expected length.
61        expected: usize,
62        /// Actual length.
63        got: usize,
64        /// Matrix rows.
65        rows: usize,
66        /// Matrix cols.
67        cols: usize,
68    },
69}