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