2019-03-25 18:21:41 +08:00
use na ::{ DefaultAllocator , RealField , Scalar } ;
2018-09-20 16:50:34 +08:00
2019-03-23 21:29:07 +08:00
use crate ::aliases ::{ TMat , TVec } ;
use crate ::traits ::{ Alloc , Dimension , Number } ;
2018-09-20 16:50:34 +08:00
2018-09-22 19:18:59 +08:00
/// The determinant of the matrix `m`.
2019-03-25 18:21:41 +08:00
pub fn determinant < N : RealField , D : Dimension > ( m : & TMat < N , D , D > ) -> N
2018-10-22 13:00:10 +08:00
where DefaultAllocator : Alloc < N , D , D > {
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`.
2019-03-25 18:21:41 +08:00
pub fn inverse < N : RealField , D : Dimension > ( m : & TMat < N , D , D > ) -> TMat < N , D , D >
2018-10-22 13:00:10 +08:00
where DefaultAllocator : Alloc < N , D , D > {
2018-10-22 04:11:27 +08:00
m . clone ( )
. try_inverse ( )
. unwrap_or_else ( TMat ::< N , 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.
2018-10-22 04:11:27 +08:00
pub fn matrix_comp_mult < N : Number , R : Dimension , C : Dimension > (
x : & TMat < N , R , C > ,
y : & TMat < N , R , C > ,
) -> TMat < N , R , C >
where
DefaultAllocator : Alloc < N , 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`.
2018-10-22 04:11:27 +08:00
pub fn outer_product < N : Number , R : Dimension , C : Dimension > (
c : & TVec < N , R > ,
r : & TVec < N , C > ,
) -> TMat < N , R , C >
where
DefaultAllocator : Alloc < N , 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`.
2019-12-17 07:09:14 +08:00
pub fn transpose < N : Scalar , R : Dimension , C : Dimension > ( x : & TMat < N , R , C > ) -> TMat < N , C , R >
2018-10-22 13:00:10 +08:00
where DefaultAllocator : Alloc < N , R , C > {
2018-09-20 16:50:34 +08:00
x . transpose ( )
2018-10-05 11:21:38 +08:00
}