nalgebra/nalgebra-glm/src/matrix.rs

41 lines
1.2 KiB
Rust
Raw Normal View History

2021-08-08 18:59:40 +08:00
use na::{Const, DimMin, Scalar};
2019-03-23 21:29:07 +08:00
use crate::aliases::{TMat, TVec};
2021-08-08 18:59:40 +08:00
use crate::traits::{Number, RealNumber};
/// The determinant of the matrix `m`.
2021-08-08 18:59:40 +08:00
pub fn determinant<T: RealNumber, 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
{
m.determinant()
}
/// The inverse of the matrix `m`.
2021-08-08 18:59:40 +08:00
pub fn inverse<T: RealNumber, 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-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> {
x.component_mul(y)
}
/// 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> {
c * r.transpose()
}
/// 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> {
x.transpose()
}