1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
#ifndef LU_APPLY_PERM_H
#define LU_APPLY_PERM_H 1

#include <flens/flens.cxx>

namespace flens {

// Compute A = P*A
template <typename VP, typename MA>
void
apply_perm(const DenseVector<VP> &p, GeMatrix<MA> &A)
{
    typedef typename GeMatrix<MA>::IndexType    IndexType;
    const Underscore<IndexType> _;

    const IndexType m = p.length();

    // reverse row interchanges
    for (IndexType i=m; i>=1; --i) {
        if (i!=p(i)) {
            blas::swap(A(i,_), A(p(i),_));
        }
    }
}

// namespace flens

#endif // LU_APPLY_PERM_H