2018-09-20 16:50:34 +08:00
|
|
|
use num::Num;
|
2018-09-20 20:23:31 +08:00
|
|
|
use na::{Scalar, Real, DefaultAllocator, U1};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-20 20:23:31 +08:00
|
|
|
use traits::{Alloc, Dimension, Number};
|
2018-09-20 16:50:34 +08:00
|
|
|
use aliases::{Mat, Vec};
|
|
|
|
|
|
|
|
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn determinant<N: Real, D: Dimension>(m: &Mat<N, D, D>) -> N
|
|
|
|
where DefaultAllocator: Alloc<N, D, D> {
|
|
|
|
m.determinant()
|
|
|
|
}
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn inverse<N: Real, D: Dimension>(m: &Mat<N, D, D>) -> Mat<N, D, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D, D> {
|
|
|
|
m.clone().try_inverse().unwrap_or(Mat::<N, D, D>::zeros())
|
|
|
|
}
|
|
|
|
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn matrix_comp_mult<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R, C>, y: &Mat<N, R, C>) -> Mat<N, R, C>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, R, C> {
|
|
|
|
x.component_mul(y)
|
|
|
|
}
|
|
|
|
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn outer_product<N: Number, R: Dimension, C: Dimension>(c: &Vec<N, R>, r: &Vec<N, C>) -> Mat<N, R, C>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, R, C> {
|
|
|
|
c * r.transpose()
|
|
|
|
}
|
|
|
|
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn transpose<N: Scalar, R: Dimension, C: Dimension>(x: &Mat<N, R, C>) -> Mat<N, C, R>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, R, C> {
|
|
|
|
x.transpose()
|
|
|
|
}
|