1use mdarray::{DSlice, DTensor, Layout};
3use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum InvError {
8 #[error("Matrix must be square: got {rows}x{cols}")]
10 NotSquare { rows: i32, cols: i32 },
11
12 #[error("Backend error code: {0}")]
14 BackendError(i32),
15
16 #[error("Matrix is singular: zero pivot at position {pivot}")]
18 Singular { pivot: i32 },
19
20 #[error("The leading principal minor is not positive")]
22 NotPositiveDefinite { lpm: i32 },
23}
24
25pub type InvResult<T> = Result<DTensor<T, 2>, InvError>;
27
28pub trait LU<T> {
30 fn lu_overwrite<L: Layout, Ll: Layout, Lu: Layout, Lp: Layout>(
32 &self,
33 a: &mut DSlice<T, 2, L>,
34 l: &mut DSlice<T, 2, Ll>,
35 u: &mut DSlice<T, 2, Lu>,
36 p: &mut DSlice<T, 2, Lp>,
37 );
38
39 fn lu<L: Layout>(
41 &self,
42 a: &mut DSlice<T, 2, L>,
43 ) -> (DTensor<T, 2>, DTensor<T, 2>, DTensor<T, 2>);
44
45 fn inv_overwrite<L: Layout>(&self, a: &mut DSlice<T, 2, L>) -> Result<(), InvError>;
47
48 fn inv<L: Layout>(&self, a: &mut DSlice<T, 2, L>) -> InvResult<T>;
50
51 fn det<L: Layout>(&self, a: &mut DSlice<T, 2, L>) -> T;
54
55 fn choleski<L: Layout>(&self, a: &mut DSlice<T, 2, L>) -> InvResult<T>;
57
58 fn choleski_overwrite<L: Layout>(&self, a: &mut DSlice<T, 2, L>) -> Result<(), InvError>;
60}