diff --git a/src/lol/math/matrix.h b/src/lol/math/matrix.h index 20ad6102..2ab6d4bb 100644 --- a/src/lol/math/matrix.h +++ b/src/lol/math/matrix.h @@ -611,7 +611,7 @@ vec_t p_vector(mat_t const & m) */ template -mat_t permute(mat_t const & m, vec_t const & permutation) +mat_t permute_rows(mat_t const & m, vec_t const & permutation) { mat_t result; @@ -626,6 +626,29 @@ mat_t permute(mat_t const & m, vec_t const & permutati return result; } +/* + * Compute the determinant of a permutation square matrix corresponding to the permutation vector + */ + +template +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 */ diff --git a/src/t/math/matrix.cpp b/src/t/math/matrix.cpp index 3f01a8db..d4cc292d 100644 --- a/src/t/math/matrix.cpp +++ b/src/t/math/matrix.cpp @@ -103,7 +103,7 @@ lolunit_declare_fixture(MatrixTest) vec4(0, 0, 1, 0)); vec_t perm1 = p_vector(m1); - m1 = permute(m1, perm1); + m1 = permute_rows(m1, perm1); for (int i = 0 ; i < 4 ; ++i) { @@ -122,7 +122,7 @@ lolunit_declare_fixture(MatrixTest) vec4(1, 0, 0, 0)); vec_t perm2 = p_vector(m2); - m2 = permute(m2, perm2); + m2 = permute_rows(m2, perm2); for (int i = 0 ; i < 4 ; ++i) {