rstsr_openblas/linalg_auto_impl/
inv.rs1use crate::DeviceBLAS;
2use rstsr_blas_traits::prelude::*;
3use rstsr_core::prelude_dev::*;
4use rstsr_linalg_traits::prelude_dev::*;
5
6#[duplicate_item(
7 ImplType Tr ;
8 [T, D, R: DataAPI<Data = Vec<T>>] [&TensorAny<R, T, DeviceBLAS, D> ];
9 [T, D ] [TensorView<'_, T, DeviceBLAS, D>];
10)]
11impl<ImplType> InvAPI<DeviceBLAS> for Tr
12where
13 T: BlasFloat,
14 D: DimAPI,
15 DeviceBLAS: LapackDriverAPI<T>,
16{
17 type Out = Tensor<T, DeviceBLAS, D>;
18 fn inv_f(self) -> Result<Self::Out> {
19 rstsr_assert_eq!(self.ndim(), 2, InvalidLayout, "Currently we can only handle 2-D matrix.")?;
20 let a = self.view().into_dim::<Ix2>();
21 let result = ref_impl_inv_f(a.into())?.into_owned();
22 Ok(result.into_dim::<IxD>().into_dim::<D>())
23 }
24}
25
26#[duplicate_item(
27 ImplType Tr ;
28 ['a, T, D] [TensorMut<'a, T, DeviceBLAS, D>];
29 [ T, D] [Tensor<T, DeviceBLAS, D> ];
30)]
31impl<ImplType> InvAPI<DeviceBLAS> for Tr
32where
33 T: BlasFloat,
34 D: DimAPI,
35 DeviceBLAS: LapackDriverAPI<T>,
36{
37 type Out = Tr;
38 fn inv_f(self) -> Result<Self::Out> {
39 rstsr_assert_eq!(self.ndim(), 2, InvalidLayout, "Currently we can only handle 2-D matrix.")?;
40 let mut a = self;
41 let a_view = a.view_mut().into_dim::<Ix2>();
42 let result = ref_impl_inv_f(a_view.into())?;
43 result.clone_to_mut();
44 Ok(a)
45 }
46}