Skip to content

Commit

Permalink
WIP: InvWork
Browse files Browse the repository at this point in the history
  • Loading branch information
termoshtt committed Sep 29, 2022
1 parent 07ab31d commit a8cc0ce
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lax/src/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,50 @@ pub trait Solve_: Scalar + Sized {
fn solve(l: MatrixLayout, t: Transpose, a: &[Self], p: &Pivot, b: &mut [Self]) -> Result<()>;
}

pub struct InvWork<T: Scalar> {
pub work: Vec<MaybeUninit<T>>,
}

pub trait InvWorkImpl: Sized {
type Elem: Scalar;
fn new(layout: MatrixLayout) -> Result<Self>;
fn calc(&mut self, a: &mut [Self::Elem], p: &Pivot) -> Result<()>;
}

macro_rules! impl_inv_work {
($s:ty, $tri:path) => {
impl InvWorkImpl for InvWork<c64> {
type Elem = c64;
fn new(layout: MatrixLayout) -> Result<Self> {
let (n, _) = layout.size();
let mut info = 0;
let mut work_size = [Self::Elem::zero()];
unsafe {
$tri(
&n,
std::ptr::null_mut(),
&layout.lda(),
std::ptr::null(),
AsPtr::as_mut_ptr(&mut work_size),
&(-1),
&mut info,
)
};
info.as_lapack_result()?;
let lwork = work_size[0].to_usize().unwrap();
let work = vec_uninit(lwork);
Ok(InvWork { work })
}

fn calc(&mut self, a: &mut [Self::Elem], p: &Pivot) -> Result<()> {
todo!()
}
}
};
}

impl_inv_work!(c64, lapack_sys::zgetri_);

macro_rules! impl_solve {
($scalar:ty, $getrf:path, $getri:path, $getrs:path) => {
impl Solve_ for $scalar {
Expand Down

0 comments on commit a8cc0ce

Please # to comment.