pub mod eig;
pub mod lu;
pub mod matmul;
pub mod qr;
pub mod solve;
pub mod svd;
#[derive(Default)]
pub struct Faer;
use mdarray::{DSlice, DTensor, Layout, Strided, StridedMapping, View};
use std::mem::ManuallyDrop;
pub fn into_faer<T, L: Layout>(mat: &DSlice<T, 2, L>) -> faer::mat::MatRef<'static, T> {
let (nrows, ncols) = *mat.shape();
let strides = (mat.stride(0), mat.stride(1));
unsafe { faer::MatRef::from_raw_parts(mat.as_ptr(), nrows, ncols, strides.0, strides.1) }
}
pub fn into_faer_mut<T, L: Layout>(mat: &mut DSlice<T, 2, L>) -> faer::mat::MatMut<'static, T> {
let (nrows, ncols) = *mat.shape();
let strides = (mat.stride(0), mat.stride(1));
unsafe {
faer::MatMut::from_raw_parts_mut(
mat.as_mut_ptr() as *mut _,
nrows,
ncols,
strides.0,
strides.1,
)
}
}
pub fn into_mdarray<T: std::clone::Clone>(mat: faer::Mat<T>) -> DTensor<T, 2> {
let mut mat = ManuallyDrop::new(mat);
let (nrows, ncols) = (mat.nrows(), mat.ncols());
let mapping = StridedMapping::new((nrows, ncols), &[mat.row_stride(), mat.col_stride()]);
let view_strided: View<'_, _, (usize, usize), Strided> =
unsafe { mdarray::View::new_unchecked(mat.as_ptr_mut(), mapping) };
DTensor::<T, 2>::from(view_strided)
}
pub fn into_faer_mut_transpose<T, L: Layout>(
mat: &mut DSlice<T, 2, L>,
) -> faer::mat::MatMut<'static, T> {
let (nrows, ncols) = *mat.shape();
let strides = (mat.stride(0), mat.stride(1));
unsafe {
faer::MatMut::from_raw_parts_mut(
mat.as_mut_ptr() as *mut _,
nrows,
ncols,
strides.1,
strides.0,
)
}
}
pub fn into_faer_diag_mut<T, L: Layout>(
mat: &mut DSlice<T, 2, L>,
) -> faer::diag::DiagMut<'static, T> {
let (n, _) = *mat.shape();
unsafe { faer::diag::DiagMut::from_raw_parts_mut(mat.as_mut_ptr() as *mut _, n, mat.stride(1)) }
}