11 #ifndef EIGEN_PERMUTATIONMATRIX_H 12 #define EIGEN_PERMUTATIONMATRIX_H 16 template<
int RowCol,
typename IndicesType,
typename MatrixType,
typename StorageKind>
class PermutedImpl;
44 template<
typename PermutationType,
typename MatrixType,
int S
ide,
bool Transposed=false>
46 template<
typename PermutationType,
typename MatrixType,
int S
ide,
bool Transposed=false>
52 template<
typename Derived>
59 #ifndef EIGEN_PARSED_BY_DOXYGEN 62 Flags = Traits::Flags,
63 CoeffReadCost = Traits::CoeffReadCost,
64 RowsAtCompileTime = Traits::RowsAtCompileTime,
65 ColsAtCompileTime = Traits::ColsAtCompileTime,
66 MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime,
67 MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
69 typedef typename Traits::Scalar
Scalar;
79 template<
typename OtherDerived>
87 template<
typename OtherDerived>
90 setIdentity(tr.
size());
91 for(Index k=size()-1; k>=0; --k)
92 applyTranspositionOnTheRight(k,tr.
coeff(k));
96 #ifndef EIGEN_PARSED_BY_DOXYGEN 108 inline Index
rows()
const {
return Index(indices().size()); }
111 inline Index
cols()
const {
return Index(indices().size()); }
114 inline Index
size()
const {
return Index(indices().
size()); }
116 #ifndef EIGEN_PARSED_BY_DOXYGEN 117 template<
typename DenseDerived>
121 for (
int i=0; i<rows();++i)
122 other.coeffRef(indices().coeff(i),i) =
typename DenseDerived::Scalar(1);
136 const IndicesType&
indices()
const {
return derived().indices(); }
138 IndicesType&
indices() {
return derived().indices(); }
144 indices().resize(newSize);
150 for(Index i = 0; i < size(); ++i)
151 indices().coeffRef(i) = i;
174 for(Index k = 0; k < size(); ++k)
176 if(indices().coeff(k) == i) indices().coeffRef(k) = j;
177 else if(indices().coeff(k) == j) indices().coeffRef(k) = i;
193 std::swap(indices().coeffRef(i), indices().coeffRef(j));
202 {
return derived(); }
208 {
return derived(); }
213 #ifndef EIGEN_PARSED_BY_DOXYGEN 215 template<
typename OtherDerived>
218 for (
int i=0; i<rows();++i) indices().coeffRef(other.
indices().coeff(i)) = i;
220 template<
typename Lhs,
typename Rhs>
224 for (
int i=0; i<rows();++i) indices().coeffRef(i) = lhs.indices().coeff(rhs.indices().coeff(i));
234 template<
typename Other>
242 template<
typename Other>
250 template<
typename Other>
friend 273 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename IndexType>
275 :
traits<Matrix<IndexType,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
282 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename IndexType>
289 #ifndef EIGEN_PARSED_BY_DOXYGEN 302 template<
typename OtherDerived>
304 : m_indices(other.indices()) {}
306 #ifndef EIGEN_PARSED_BY_DOXYGEN 319 template<
typename Other>
324 template<
typename Other>
326 : m_indices(tr.size())
332 template<
typename Other>
340 template<
typename Other>
343 return Base::operator=(tr.
derived());
346 #ifndef EIGEN_PARSED_BY_DOXYGEN 358 const IndicesType&
indices()
const {
return m_indices; }
365 #ifndef EIGEN_PARSED_BY_DOXYGEN 366 template<
typename Other>
368 : m_indices(other.nestedPermutation().size())
370 for (
int i=0; i<m_indices.size();++i) m_indices.coeffRef(other.nestedPermutation().indices().coeff(i)) = i;
372 template<
typename Lhs,
typename Rhs>
374 : m_indices(lhs.indices().size())
376 Base::assignProduct(lhs,rhs);
387 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename IndexType,
int _PacketAccess>
389 :
traits<Matrix<IndexType,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
396 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename IndexType,
int _PacketAccess>
398 :
public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType>,_PacketAccess> >
404 #ifndef EIGEN_PARSED_BY_DOXYGEN 406 typedef typename IndicesType::Scalar
Index;
409 inline Map(
const Index* indicesPtr)
410 : m_indices(indicesPtr)
413 inline Map(
const Index* indicesPtr, Index size)
414 : m_indices(indicesPtr,size)
418 template<
typename Other>
420 {
return Base::operator=(other.
derived()); }
423 template<
typename Other>
425 {
return Base::operator=(tr.
derived()); }
427 #ifndef EIGEN_PARSED_BY_DOXYGEN 433 m_indices = other.m_indices;
439 const IndicesType&
indices()
const {
return m_indices; }
464 template<
typename _IndicesType>
468 typedef typename _IndicesType::Scalar
Scalar;
469 typedef typename _IndicesType::Scalar
Index;
472 RowsAtCompileTime = _IndicesType::SizeAtCompileTime,
473 ColsAtCompileTime = _IndicesType::SizeAtCompileTime,
474 MaxRowsAtCompileTime = IndicesType::MaxRowsAtCompileTime,
475 MaxColsAtCompileTime = IndicesType::MaxColsAtCompileTime,
477 CoeffReadCost = _IndicesType::CoeffReadCost
482 template<
typename _IndicesType>
489 #ifndef EIGEN_PARSED_BY_DOXYGEN 494 : m_indices(a_indices)
508 template<
typename Derived,
typename PermutationDerived>
515 (permutation.
derived(), matrix.derived());
520 template<
typename Derived,
typename PermutationDerived>
528 (permutation.
derived(), matrix.derived());
533 template<
typename PermutationType,
typename MatrixType,
int S
ide,
bool Transposed>
539 template<
typename PermutationType,
typename MatrixType,
int S
ide,
bool Transposed>
541 :
public ReturnByValue<permut_matrix_product_retval<PermutationType, MatrixType, Side, Transposed> >
544 typedef typename MatrixType::Index
Index;
547 : m_permutation(perm), m_matrix(matrix)
550 inline Index
rows()
const {
return m_matrix.rows(); }
551 inline Index
cols()
const {
return m_matrix.cols(); }
553 template<
typename Dest>
inline void evalTo(Dest& dst)
const 555 const Index n = Side==
OnTheLeft ? rows() : cols();
563 while(r < m_permutation.size())
566 while(r<m_permutation.size() && mask[r]) r++;
567 if(r>=m_permutation.size())
572 mask.coeffRef(k0) =
true;
573 for(Index k=m_permutation.indices().coeff(k0); k!=
k0; k=m_permutation.indices().coeff(k))
577 (dst,((Side==
OnTheLeft) ^ Transposed) ? k0 : kPrev));
579 mask.coeffRef(k) =
true;
586 for(
int i = 0; i < n; ++i)
589 (dst, ((Side==
OnTheLeft) ^ Transposed) ? m_permutation.indices().coeff(i) : i)
594 (m_matrix, ((Side==
OnTheRight) ^ Transposed) ? m_permutation.indices().coeff(i) : i);
606 template<
typename Derived>
613 template<
typename Derived>
615 :
public EigenBase<Transpose<PermutationBase<Derived> > >
622 #ifndef EIGEN_PARSED_BY_DOXYGEN 626 Flags = Traits::Flags,
627 CoeffReadCost = Traits::CoeffReadCost,
628 RowsAtCompileTime = Traits::RowsAtCompileTime,
629 ColsAtCompileTime = Traits::ColsAtCompileTime,
630 MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime,
631 MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
636 Transpose(
const PermutationType& p) : m_permutation(p) {}
638 inline int rows()
const {
return m_permutation.rows(); }
639 inline int cols()
const {
return m_permutation.cols(); }
641 #ifndef EIGEN_PARSED_BY_DOXYGEN 642 template<
typename DenseDerived>
646 for (
int i=0; i<rows();++i)
647 other.coeffRef(i, m_permutation.indices().coeff(i)) =
typename DenseDerived::Scalar(1);
652 PlainPermutationType
eval()
const {
return *
this; }
658 template<
typename OtherDerived>
friend 667 template<
typename OtherDerived>
680 template<
typename Derived>
688 #endif // EIGEN_PERMUTATIONMATRIX_H
Matrix< Scalar, RowsAtCompileTime, ColsAtCompileTime, 0, MaxRowsAtCompileTime, MaxColsAtCompileTime > DenseMatrixType
PermutationMatrix(const MatrixBase< Other > &a_indices)
void assignProduct(const Lhs &lhs, const Rhs &rhs)
internal::traits< Map > Traits
Transpose< PermutationBase > transpose() const
const PermutationType & nestedPermutation() const
remove_all< typename MatrixType::Nested >::type MatrixTypeNestedCleaned
Map(const Index *indicesPtr, Index size)
Map & operator=(const TranspositionsBase< Other > &tr)
internal::traits< PermutationMatrix > Traits
IndicesType::Nested m_indices
PermutationMatrix< IndicesType::SizeAtCompileTime, IndicesType::MaxSizeAtCompileTime, Index > PlainPermutationType
Traits::IndicesType IndicesType
_IndicesType::Scalar Index
A matrix or vector expression mapping an existing array of data.
const internal::remove_all< typename IndicesType::Nested >::type & indices() const
Expression of the transpose of a matrix.
Derived & applyTranspositionOnTheRight(Index i, Index j)
void assignTranspose(const PermutationBase< OtherDerived > &other)
Derived::DenseMatrixType DenseMatrixType
iterative scaling algorithm to equilibrate rows and column norms in matrices
PermutationMatrix(const TranspositionsBase< Other > &tr)
const IndicesType & indices() const
const PermutationType & m_permutation
const internal::permut_matrix_product_retval< PermutationDerived, Derived, OnTheRight > operator*(const MatrixBase< Derived > &matrix, const PermutationBase< PermutationDerived > &permutation)
friend PlainPermutationType operator*(const Transpose< PermutationBase< Other > > &other, const PermutationBase &perm)
Map(const Index *indicesPtr)
const internal::permut_matrix_product_retval< PermutationType, OtherDerived, OnTheLeft, true > operator*(const MatrixBase< OtherDerived > &matrix) const
Derived & operator=(const PermutationBase< OtherDerived > &other)
PermutationMatrix(internal::PermPermProduct_t, const Lhs &lhs, const Rhs &rhs)
PermutationMatrix & operator=(const PermutationMatrix &other)
Base class for permutations.
Traits::IndicesType IndicesType
Traits::IndicesType IndicesType
PermutationWrapper(const IndicesType &a_indices)
void evalTo(MatrixBase< DenseDerived > &other) const
PermutationMatrix(const PermutationBase< OtherDerived > &other)
PermutationMatrix & operator=(const PermutationBase< Other > &other)
PlainPermutationType operator*(const PermutationBase< Other > &other) const
Traits::IndicesType IndicesType
Derived & operator=(const TranspositionsBase< OtherDerived > &tr)
MatrixType::Nested m_matrix
PermutationType::IndicesType IndicesType
Map & operator=(const PermutationBase< Other > &other)
Transpose(const PermutationType &p)
DenseMatrixType toDenseMatrix() const
PermutationMatrix(int size)
EigenBase< Derived > Base
Class to view a vector of integers as a permutation matrix.
const IndicesType & indices() const
Derived & operator=(const PermutationBase &other)
PermutationMatrix(const Transpose< PermutationBase< Other > > &other)
MatrixType::PlainObject ReturnType
void evalTo(MatrixBase< DenseDerived > &other) const
Transpose< PermutationBase > inverse() const
_IndicesType::Scalar Scalar
void rhs(const real_t *x, real_t *f)
internal::traits< PermutationWrapper > Traits
const PermutationWrapper< const Derived > asPermutation() const
Expression of a fixed-size or dynamic-size block.
Map< const Matrix< IndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1 >, _PacketAccess > IndicesType
DenseMatrixType toDenseMatrix() const
internal::traits< PermutationType > Traits
Derived & applyTranspositionOnTheLeft(Index i, Index j)
internal::traits< Derived > Traits
PermutationMatrix(const PermutationMatrix &other)
PermutationBase< PermutationMatrix > Base
const IndicesType & indices() const
PermutationType::PlainPermutationType PlainPermutationType
const Index & coeff(Index i) const
Matrix< IndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1 > IndicesType
Map & operator=(const Map &other)
PlainPermutationType eval() const
PermutationStorage StorageKind
PermutationBase< Map > Base
const T::Scalar * extract_data(const T &m)
void setIdentity(Index newSize)
PlainPermutationType operator*(const Transpose< PermutationBase< Other > > &other) const
The matrix class, also used for vectors and row-vectors.
permut_matrix_product_retval(const PermutationType &perm, const MatrixType &matrix)
void resize(Index newSize)
friend const internal::permut_matrix_product_retval< PermutationType, OtherDerived, OnTheRight, true > operator*(const MatrixBase< OtherDerived > &matrix, const Transpose &trPerm)
Base class for all dense matrices, vectors, and expressions.
const PermutationType & m_permutation
void evalTo(Dest &dst) const
IndicesType::Scalar Index
PermutationMatrix & operator=(const TranspositionsBase< Other > &tr)
PermutationBase< PermutationWrapper > Base