示例#1
0
void eta_matrix<T, X>::conjugate_by_permutation(permutation_matrix<T, X> & p) {
    // this = p * this * p(-1)
#ifdef LEAN_DEBUG
    // auto rev = p.get_reverse();
    // auto deb = ((*this) * rev);
    // deb = p * deb;
#endif
    m_column_index = p.get_rev(m_column_index);
    for (auto & pair : m_column_vector.m_data) {
        pair.first = p.get_rev(pair.first);
    }
#ifdef LEAN_DEBUG
    // lean_assert(deb == *this);
#endif
}
void row_eta_matrix<T, X>::conjugate_by_permutation(permutation_matrix<T, X> & p) {
    // this = p * this * p(-1)
#ifdef LEAN_DEBUG
    // auto rev = p.get_reverse();
    // auto deb = ((*this) * rev);
    // deb = p * deb;
#endif
    m_row = p.apply_reverse(m_row);
    // copy aside the column indices
    std::vector<unsigned> columns;
    for (auto & it : m_row_vector.m_data)
        columns.push_back(it.first);
    for (unsigned i = columns.size(); i-- > 0;)
        m_row_vector.m_data[i].first = p.get_rev(columns[i]);
#ifdef LEAN_DEBUG
    // lean_assert(deb == *this);
#endif
}
// this is multiplication in the matrix sense
template <typename T, typename X> void permutation_matrix<T, X>::multiply_by_permutation_from_right(permutation_matrix<T, X> & p) {
    auto clone = clone_m_permutation();
    lean_assert(p.size() == size());
    unsigned i = size();
    while (i-- > 0) {
        set_val(i, p[clone[i]]); // we have m(P)*m(Q) = m(QP), where m is the matrix of the permutation
    }
    delete [] clone;
}
inline unsigned number_of_inversions(permutation_matrix<T, X> & p) {
    unsigned ret = 0;
    unsigned n = p.size();
    for (unsigned i = 0; i < n; i++) {
        for (unsigned j = i + 1; j < n; j++) {
            if (p[i] > p[j]) {
                ret++;
            }
        }
    }
    return ret;
}
示例#5
0
void swap_rows_inverted(permutation_matrix const& P, matrix_expression<M>& A) {
    for(std::size_t i = P.size(); i != 0; --i) {
        swap_rows(A(),i-1,P(i-1));
    }
}
示例#6
0
void swap_columns(permutation_matrix const& P, matrix_expression<M>& A) {
    for(std::size_t i = 0; i != P.size(); ++i)
        swap_columns(A(),i,P(i));
}
示例#7
0
void swap_rows(permutation_matrix const& P, vector_expression<V>& v) {
    for (std::size_t i = 0; i != P.size(); ++ i)
        std::swap(v()(i),v()(P(i)));
}