use mdarray::{DSlice, DTensor, Layout};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum InvError {
#[error("Matrix must be square: got {rows}x{cols}")]
NotSquare { rows: i32, cols: i32 },
#[error("Backend error code: {0}")]
BackendError(i32),
#[error("Matrix is singular: zero pivot at position {pivot}")]
Singular { pivot: i32 },
#[error("The leading principal minor is not positive")]
NotPositiveDefinite { lpm: i32 },
}
pub type InvResult<T> = Result<DTensor<T, 2>, InvError>;
pub trait LU<T> {
fn lu_overwrite<L: Layout, Ll: Layout, Lu: Layout, Lp: Layout>(
&self,
a: &mut DSlice<T, 2, L>,
l: &mut DSlice<T, 2, Ll>,
u: &mut DSlice<T, 2, Lu>,
p: &mut DSlice<T, 2, Lp>,
);
fn lu<L: Layout>(
&self,
a: &mut DSlice<T, 2, L>,
) -> (DTensor<T, 2>, DTensor<T, 2>, DTensor<T, 2>);
fn inv_overwrite<L: Layout>(&self, a: &mut DSlice<T, 2, L>) -> Result<(), InvError>;
fn inv<L: Layout>(&self, a: &mut DSlice<T, 2, L>) -> InvResult<T>;
fn det<L: Layout>(&self, a: &mut DSlice<T, 2, L>) -> T;
fn choleski<L: Layout>(&self, a: &mut DSlice<T, 2, L>) -> InvResult<T>;
fn choleski_overwrite<L: Layout>(&self, a: &mut DSlice<T, 2, L>) -> Result<(), InvError>;
}