use mdarray::{DSlice, DTensor, Layout};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum SolveError {
#[error("Backend error code: {0}")]
BackendError(i32),
#[error("Matrix is singular: U({diagonal},{diagonal}) is exactly zero")]
SingularMatrix { diagonal: i32 },
#[error("Invalid matrix dimensions")]
InvalidDimensions,
}
pub struct SolveResult<T> {
pub x: DTensor<T, 2>,
pub p: DTensor<T, 2>,
}
pub type SolveResultType<T> = Result<SolveResult<T>, SolveError>;
pub trait Solve<T> {
fn solve_overwrite<La: Layout, Lb: Layout, Lp: Layout>(
&self,
a: &mut DSlice<T, 2, La>,
b: &mut DSlice<T, 2, Lb>,
p: &mut DSlice<T, 2, Lp>,
) -> Result<(), SolveError>;
fn solve<La: Layout, Lb: Layout>(
&self,
a: &mut DSlice<T, 2, La>,
b: &DSlice<T, 2, Lb>,
) -> SolveResultType<T>;
}