/// Computes the determinant of matrix `a`.
///
/// Note: This implementation is written to be clearly correct so that it's
/// useful for verification, but it's very inefficient.
Computes the determinant of matrix `a`.
Note: This implementation is written to be clearly correct so that it's
useful for verification, but it's very inefficient.
Computes the determinant of matrix ` a ` . Note : This implementation is written to be clearly correct so that it ' s useful for verification but it ' s very inefficient .
fn det_naive<A, S>(a: &ArrayBase<S, Ix2>) -> A
where
    A: Scalar,
    S: Data<Elem = A>,
{
    assert_eq!(a.nrows(), a.ncols());
    match a.ncols() {
        0 => A::one(),
        1 => a[(0, 0)],
        cols => (0..cols)
            .map(|col| {
                let sign = if col % 2 == 0 { A::one() } else { -A::one() };
                sign * a[(0, col)] * det_naive(&matrix_minor(a, (0, col)))
            })
            .fold(A::zero(), |sum, subdet| sum + subdet),
    }
}
fn det_naive < A , S > ( a : & ArrayBase < S , Ix2 > ) -> A where A : Scalar , S : Data < Elem = A > , { assert_eq ! ( a nrows ( ) a ncols ( ) ) ; match a . ncols ( ) { 0 => A :: one ( ) , 1 => a [ ( 0 , 0 ) ] , cols => ( 0 .. cols ) . map ( | col | { let sign = if col % 2 == 0 { A :: one ( ) } else { - A :: one ( ) } ; sign * a [ ( 0 , col ) ] * det_naive ( & matrix_minor ( a , ( 0 , col ) ) ) } ) . fold ( A :: zero ( ) , | sum , subdet | sum + subdet ) , } }
Computes the determinant of matrix `a`.
Computes the determinant of matrix ` a ` .
a
&ArrayBase<S, Ix2>