Changeset 3855


Ignore:
Timestamp:
Mar 3, 2015, 10:11:06 PM (7 years ago)
Author:
guite
Message:

matrix: adding permutation determinant

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/math/matrix.h

    r3854 r3855  
    612612
    613613template<typename T, int N>
    614 mat_t<T, N, N> permute(mat_t<T, N, N> const & m, vec_t<int, N> const & permutation)
     614mat_t<T, N, N> permute_rows(mat_t<T, N, N> const & m, vec_t<int, N> const & permutation)
    615615{
    616616    mat_t<T, N, N> result;
     
    622622            result[i][j] = m[i][permutation[j]];
    623623        }
     624    }
     625
     626    return result;
     627}
     628
     629/*
     630 * Compute the determinant of a permutation square matrix corresponding to the permutation vector
     631 */
     632
     633template<int N>
     634int permutation_det(vec_t<int, N> const & permutation)
     635{
     636    int result = 1;
     637
     638    for (int i = 0 ; i < N ; ++i)
     639    {
     640        int relative_index = permutation[i];
     641
     642        for (int j = 0 ; j < i ; ++j)
     643            if (permutation[j] < permutation[i])
     644                --relative_index;
     645
     646        result *= (relative_index % 2 ? -1 : 1);
    624647    }
    625648
  • trunk/src/t/math/matrix.cpp

    r3854 r3855  
    104104
    105105        vec_t<int, 4> perm1 = p_vector(m1);
    106         m1 = permute(m1, perm1);
     106        m1 = permute_rows(m1, perm1);
    107107
    108108        for (int i = 0 ; i < 4 ; ++i)
     
    123123
    124124        vec_t<int, 4> perm2 = p_vector(m2);
    125         m2 = permute(m2, perm2);
     125        m2 = permute_rows(m2, perm2);
    126126
    127127        for (int i = 0 ; i < 4 ; ++i)
Note: See TracChangeset for help on using the changeset viewer.