2021-04-11 17:00:38 +08:00
use na ::{ Const , DimMin , RealField , Scalar } ;
2018-09-20 16:50:34 +08:00
2019-03-23 21:29:07 +08:00
use crate ::aliases ::{ TMat , TVec } ;
2021-04-11 17:00:38 +08:00
use crate ::traits ::Number ;
2018-09-20 16:50:34 +08:00
2018-09-22 19:18:59 +08:00
/// The determinant of the matrix `m`.
2021-04-11 17:00:38 +08:00
pub fn determinant < T : RealField , const D : usize > ( m : & TMat < T , D , D > ) -> T
2020-04-06 00:49:48 +08:00
where
2021-04-11 17:00:38 +08:00
Const < D > : DimMin < Const < D > , Output = Const < D > > ,
2020-04-06 00:49:48 +08:00
{
2018-09-20 20:23:31 +08:00
m . determinant ( )
}
2018-09-20 16:50:34 +08:00
2018-09-22 19:18:59 +08:00
/// The inverse of the matrix `m`.
2021-04-11 17:00:38 +08:00
pub fn inverse < T : RealField , const D : usize > ( m : & TMat < T , D , D > ) -> TMat < T , D , D > {
2018-10-22 04:11:27 +08:00
m . clone ( )
. try_inverse ( )
2021-04-11 17:00:38 +08:00
. unwrap_or_else ( TMat ::< T , D , D > ::zeros )
2018-09-20 16:50:34 +08:00
}
2018-09-22 19:21:02 +08:00
/// Component-wise multiplication of two matrices.
2021-04-11 17:00:38 +08:00
pub fn matrix_comp_mult < T : Number , const R : usize , const C : usize > (
x : & TMat < T , R , C > ,
y : & TMat < T , R , C > ,
) -> TMat < T , R , C > {
2018-09-20 16:50:34 +08:00
x . component_mul ( y )
}
2018-09-22 19:18:59 +08:00
/// Treats the first parameter `c` as a column vector and the second parameter `r` as a row vector and does a linear algebraic matrix multiply `c * r`.
2021-04-11 17:00:38 +08:00
pub fn outer_product < T : Number , const R : usize , const C : usize > (
c : & TVec < T , R > ,
r : & TVec < T , C > ,
) -> TMat < T , R , C > {
2018-09-20 16:50:34 +08:00
c * r . transpose ( )
}
2018-09-22 19:18:59 +08:00
/// The transpose of the matrix `m`.
2021-04-11 17:00:38 +08:00
pub fn transpose < T : Scalar , const R : usize , const C : usize > ( x : & TMat < T , R , C > ) -> TMat < T , C , R > {
2018-09-20 16:50:34 +08:00
x . transpose ( )
2018-10-05 11:21:38 +08:00
}