diff --git a/src/lol/math/matrix.h b/src/lol/math/matrix.h index 6f883c1e..01e25171 100644 --- a/src/lol/math/matrix.h +++ b/src/lol/math/matrix.h @@ -496,15 +496,13 @@ void lu_decomposition(mat_t const &m, mat_t & L, mat_t LOL_ATTR_NODISCARD T determinant(mat_t const &m) { - mat_t L, U; - vec_t P = p_vector(m); - lu_decomposition(permute_rows(m, P), L, U); + auto lup = lu_decomposition(m); - T det = 1; - for (int i = 0 ; i < N ; ++i) - det *= U[i][i]; + T det = std::get<1>(lup)[N]; + for (int i = 0; i < N; ++i) + det *= std::get<0>(lup)[i][i]; - return permutation_det(P) * det; + return det; } template LOL_ATTR_NODISCARD @@ -587,29 +585,6 @@ vec_t p_transpose(vec_t P) return result; } -/* - * Compute the determinant of a permutation square matrix corresponding to the permutation vector - */ - -template LOL_ATTR_NODISCARD -int permutation_det(vec_t const & permutation) -{ - int result = 1; - - for (int i = 0 ; i < N ; ++i) - { - int relative_index = permutation[i]; - - for (int j = 0 ; j < i ; ++j) - if (permutation[j] < permutation[i]) - --relative_index; - - result *= (relative_index % 2 ? -1 : 1); - } - - return result; -} - /* * Compute L matrix inverse */