nalgebra_glm/
matrix.rs

1use na::{Const, DimMin, Scalar};
2
3use crate::aliases::{TMat, TVec};
4use crate::traits::{Number, RealNumber};
5
6/// The determinant of the matrix `m`.
7pub fn determinant<T: RealNumber, const D: usize>(m: &TMat<T, D, D>) -> T
8where
9    Const<D>: DimMin<Const<D>, Output = Const<D>>,
10{
11    m.determinant()
12}
13
14/// The inverse of the matrix `m`.
15pub fn inverse<T: RealNumber, const D: usize>(m: &TMat<T, D, D>) -> TMat<T, D, D> {
16    m.clone()
17        .try_inverse()
18        .unwrap_or_else(TMat::<T, D, D>::zeros)
19}
20
21/// Component-wise multiplication of two matrices.
22pub fn matrix_comp_mult<T: Number, const R: usize, const C: usize>(
23    x: &TMat<T, R, C>,
24    y: &TMat<T, R, C>,
25) -> TMat<T, R, C> {
26    x.component_mul(y)
27}
28
29/// 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`.
30pub fn outer_product<T: Number, const R: usize, const C: usize>(
31    c: &TVec<T, R>,
32    r: &TVec<T, C>,
33) -> TMat<T, R, C> {
34    c * r.transpose()
35}
36
37/// The transpose of the matrix `m`.
38pub fn transpose<T: Scalar, const R: usize, const C: usize>(x: &TMat<T, R, C>) -> TMat<T, C, R> {
39    x.transpose()
40}