Browse Source

matrix: adding permutation determinant

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> 10 years ago
parent
commit
ace6e55975
2 changed files with 26 additions and 3 deletions
  1. +24
    -1
      src/lol/math/matrix.h
  2. +2
    -2
      src/t/math/matrix.cpp

+ 24
- 1
src/lol/math/matrix.h View File

@@ -611,7 +611,7 @@ vec_t<int, N> p_vector(mat_t<T, N, N> const & m)
*/

template<typename T, int N>
mat_t<T, N, N> permute(mat_t<T, N, N> const & m, vec_t<int, N> const & permutation)
mat_t<T, N, N> permute_rows(mat_t<T, N, N> const & m, vec_t<int, N> const & permutation)
{
mat_t<T, N, N> result;

@@ -626,6 +626,29 @@ mat_t<T, N, N> permute(mat_t<T, N, N> const & m, vec_t<int, N> const & permutati
return result;
}

/*
* Compute the determinant of a permutation square matrix corresponding to the permutation vector
*/

template<int N>
int permutation_det(vec_t<int, N> 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
*/


+ 2
- 2
src/t/math/matrix.cpp View File

@@ -103,7 +103,7 @@ lolunit_declare_fixture(MatrixTest)
vec4(0, 0, 1, 0));

vec_t<int, 4> 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<int, 4> perm2 = p_vector(m2);
m2 = permute(m2, perm2);
m2 = permute_rows(m2, perm2);

for (int i = 0 ; i < 4 ; ++i)
{


Loading…
Cancel
Save