11 #ifndef EIGEN_PERMUTATIONMATRIX_H
12 #define EIGEN_PERMUTATIONMATRIX_H
14 #include "./InternalHeaderCheck.h"
20 enum PermPermProduct_t {PermPermProduct};
47 template<
typename Derived>
50 typedef internal::traits<Derived> Traits;
54 #ifndef EIGEN_PARSED_BY_DOXYGEN
55 typedef typename Traits::IndicesType IndicesType;
57 Flags = Traits::Flags,
58 RowsAtCompileTime = Traits::RowsAtCompileTime,
59 ColsAtCompileTime = Traits::ColsAtCompileTime,
60 MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime,
61 MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
63 typedef typename Traits::StorageIndex StorageIndex;
68 typedef PlainPermutationType PlainObject;
75 template<
typename OtherDerived>
83 template<
typename OtherDerived>
84 Derived&
operator=(
const TranspositionsBase<OtherDerived>& tr)
101 #ifndef EIGEN_PARSED_BY_DOXYGEN
102 template<
typename DenseDerived>
107 other.
coeffRef(
indices().coeff(i),i) =
typename DenseDerived::Scalar(1);
135 StorageIndex n = StorageIndex(
size());
136 for(StorageIndex i = 0; i < n; ++i)
159 eigen_assert(i>=0 && j>=0 && i<
size() && j<
size());
162 if(
indices().coeff(k) == i)
indices().coeffRef(k) = StorageIndex(j);
163 else if(
indices().coeff(k) == j)
indices().coeffRef(k) = StorageIndex(i);
178 eigen_assert(i>=0 && j>=0 && i<
size() && j<
size());
188 {
return InverseReturnType(
derived()); }
194 {
return InverseReturnType(
derived()); }
199 #ifndef EIGEN_PARSED_BY_DOXYGEN
201 template<
typename OtherDerived>
206 template<
typename Lhs,
typename Rhs>
207 void assignProduct(
const Lhs& lhs,
const Rhs& rhs)
209 eigen_assert(lhs.cols() == rhs.rows());
210 for (
Index i=0; i<
rows();++i)
indices().coeffRef(i) = lhs.indices().coeff(rhs.indices().coeff(i));
220 template<
typename Other>
222 {
return PlainPermutationType(internal::PermPermProduct,
derived(), other.
derived()); }
228 template<
typename Other>
229 inline PlainPermutationType
operator*(
const InverseImpl<Other,PermutationStorage>& other)
const
230 {
return PlainPermutationType(internal::PermPermProduct, *
this, other.eval()); }
236 template<
typename Other>
friend
238 {
return PlainPermutationType(internal::PermPermProduct, other.eval(), perm); }
254 while(r<n && mask[r]) r++;
274 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_>
275 struct traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> >
276 : traits<Matrix<StorageIndex_,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
278 typedef PermutationStorage StorageKind;
279 typedef Matrix<StorageIndex_, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
280 typedef StorageIndex_ StorageIndex;
298 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_>
302 typedef internal::traits<PermutationMatrix> Traits;
307 #ifndef EIGEN_PARSED_BY_DOXYGEN
308 typedef typename Traits::IndicesType IndicesType;
309 typedef typename Traits::StorageIndex StorageIndex;
323 template<
typename OtherDerived>
325 : m_indices(other.
indices()) {}
334 template<
typename Other>
339 template<
typename Other>
341 : m_indices(tr.
size())
347 template<
typename Other>
355 template<
typename Other>
362 const IndicesType&
indices()
const {
return m_indices; }
369 #ifndef EIGEN_PARSED_BY_DOXYGEN
370 template<
typename Other>
372 : m_indices(other.
derived().nestedExpression().
size())
375 StorageIndex
end = StorageIndex(m_indices.size());
376 for (StorageIndex i=0; i<
end;++i)
377 m_indices.coeffRef(other.derived().nestedExpression().indices().coeff(i)) = i;
379 template<
typename Lhs,
typename Rhs>
380 PermutationMatrix(internal::PermPermProduct_t,
const Lhs& lhs,
const Rhs& rhs)
383 Base::assignProduct(lhs,rhs);
389 IndicesType m_indices;
394 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_,
int PacketAccess_>
395 struct traits<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>,PacketAccess_> >
396 : traits<Matrix<StorageIndex_,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
398 typedef PermutationStorage StorageKind;
399 typedef Map<const Matrix<StorageIndex_, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>, PacketAccess_> IndicesType;
400 typedef StorageIndex_ StorageIndex;
405 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_,
int PacketAccess_>
406 class Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>,PacketAccess_>
407 :
public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>,PacketAccess_> >
409 typedef PermutationBase<Map> Base;
410 typedef internal::traits<Map> Traits;
413 #ifndef EIGEN_PARSED_BY_DOXYGEN
414 typedef typename Traits::IndicesType IndicesType;
415 typedef typename IndicesType::Scalar StorageIndex;
418 inline Map(
const StorageIndex* indicesPtr)
419 : m_indices(indicesPtr)
422 inline Map(
const StorageIndex* indicesPtr,
Index size)
423 : m_indices(indicesPtr,size)
427 template<
typename Other>
428 Map& operator=(
const PermutationBase<Other>& other)
429 {
return Base::operator=(other.derived()); }
432 template<
typename Other>
433 Map& operator=(
const TranspositionsBase<Other>& tr)
434 {
return Base::operator=(tr.derived()); }
436 #ifndef EIGEN_PARSED_BY_DOXYGEN
440 Map& operator=(
const Map& other)
442 m_indices = other.m_indices;
448 const IndicesType& indices()
const {
return m_indices; }
450 IndicesType& indices() {
return m_indices; }
454 IndicesType m_indices;
457 template<
typename IndicesType_>
class TranspositionsWrapper;
459 template<
typename IndicesType_>
460 struct traits<PermutationWrapper<IndicesType_> >
462 typedef PermutationStorage StorageKind;
464 typedef typename IndicesType_::Scalar StorageIndex;
465 typedef IndicesType_ IndicesType;
467 RowsAtCompileTime = IndicesType_::SizeAtCompileTime,
468 ColsAtCompileTime = IndicesType_::SizeAtCompileTime,
469 MaxRowsAtCompileTime = IndicesType::MaxSizeAtCompileTime,
470 MaxColsAtCompileTime = IndicesType::MaxSizeAtCompileTime,
487 template<
typename IndicesType_>
491 typedef internal::traits<PermutationWrapper> Traits;
494 #ifndef EIGEN_PARSED_BY_DOXYGEN
495 typedef typename Traits::IndicesType IndicesType;
503 const internal::remove_all_t<typename IndicesType::Nested>&
508 typename IndicesType::Nested m_indices;
514 template<
typename MatrixDerived,
typename PermutationDerived>
516 const Product<MatrixDerived, PermutationDerived, AliasFreeProduct>
526 template<
typename PermutationDerived,
typename MatrixDerived>
528 const Product<PermutationDerived, MatrixDerived, AliasFreeProduct>
537 template<
typename PermutationType>
538 class InverseImpl<PermutationType, PermutationStorage>
539 :
public EigenBase<Inverse<PermutationType> >
541 typedef typename PermutationType::PlainPermutationType PlainPermutationType;
542 typedef internal::traits<PermutationType> PermTraits;
546 typedef Inverse<PermutationType> InverseType;
547 using EigenBase<Inverse<PermutationType> >::derived;
549 #ifndef EIGEN_PARSED_BY_DOXYGEN
550 typedef typename PermutationType::DenseMatrixType DenseMatrixType;
552 RowsAtCompileTime = PermTraits::RowsAtCompileTime,
553 ColsAtCompileTime = PermTraits::ColsAtCompileTime,
554 MaxRowsAtCompileTime = PermTraits::MaxRowsAtCompileTime,
555 MaxColsAtCompileTime = PermTraits::MaxColsAtCompileTime
559 #ifndef EIGEN_PARSED_BY_DOXYGEN
560 template<
typename DenseDerived>
561 void evalTo(MatrixBase<DenseDerived>& other)
const
564 for (
Index i=0; i<derived().rows();++i)
565 other.coeffRef(i, derived().nestedExpression().indices().coeff(i)) =
typename DenseDerived::Scalar(1);
570 PlainPermutationType eval()
const {
return derived(); }
572 DenseMatrixType toDenseMatrix()
const {
return derived(); }
576 template<
typename OtherDerived>
friend
577 const Product<OtherDerived, InverseType, AliasFreeProduct>
578 operator*(
const MatrixBase<OtherDerived>& matrix,
const InverseType& trPerm)
580 return Product<OtherDerived, InverseType, AliasFreeProduct>(matrix.derived(), trPerm.derived());
585 template<
typename OtherDerived>
586 const Product<InverseType, OtherDerived, AliasFreeProduct>
587 operator*(
const MatrixBase<OtherDerived>& matrix)
const
589 return Product<InverseType, OtherDerived, AliasFreeProduct>(derived(), matrix.derived());
593 template<
typename Derived>
594 const PermutationWrapper<const Derived> MatrixBase<Derived>::asPermutation()
const
601 template<>
struct AssignmentKind<DenseShape,PermutationShape> {
typedef EigenBase2EigenBase Kind; };
void fill(const Scalar &value)
Definition: CwiseNullaryOp.h:337
Derived & setZero()
Definition: CwiseNullaryOp.h:548
Derived & derived()
Definition: EigenBase.h:48
Scalar & coeffRef(Index row, Index col)
Definition: DenseCoeffsBase.h:344
Expression of the inverse of another expression.
Definition: Inverse.h:46
Map(PointerArgType dataPtr, const StrideType &stride=StrideType())
Definition: Map.h:131
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
Base class for permutations.
Definition: PermutationMatrix.h:49
InverseReturnType transpose() const
Definition: PermutationMatrix.h:193
void resize(Index newSize)
Definition: PermutationMatrix.h:127
IndicesType & indices()
Definition: PermutationMatrix.h:123
Index determinant() const
Definition: PermutationMatrix.h:244
Index size() const
Definition: PermutationMatrix.h:99
Index cols() const
Definition: PermutationMatrix.h:96
friend PlainPermutationType operator*(const InverseImpl< Other, PermutationStorage > &other, const PermutationBase &perm)
Definition: PermutationMatrix.h:237
Derived & applyTranspositionOnTheLeft(Index i, Index j)
Definition: PermutationMatrix.h:157
Derived & applyTranspositionOnTheRight(Index i, Index j)
Definition: PermutationMatrix.h:176
void setIdentity()
Definition: PermutationMatrix.h:133
void setIdentity(Index newSize)
Definition: PermutationMatrix.h:142
PlainPermutationType operator*(const InverseImpl< Other, PermutationStorage > &other) const
Definition: PermutationMatrix.h:229
Derived & operator=(const PermutationBase< OtherDerived > &other)
Definition: PermutationMatrix.h:76
Derived & operator=(const TranspositionsBase< OtherDerived > &tr)
Definition: PermutationMatrix.h:84
Index rows() const
Definition: PermutationMatrix.h:93
InverseReturnType inverse() const
Definition: PermutationMatrix.h:187
DenseMatrixType toDenseMatrix() const
Definition: PermutationMatrix.h:115
const IndicesType & indices() const
Definition: PermutationMatrix.h:121
PlainPermutationType operator*(const PermutationBase< Other > &other) const
Definition: PermutationMatrix.h:221
Permutation matrix.
Definition: PermutationMatrix.h:300
PermutationMatrix & operator=(const TranspositionsBase< Other > &tr)
Definition: PermutationMatrix.h:356
PermutationMatrix(const PermutationBase< OtherDerived > &other)
Definition: PermutationMatrix.h:324
PermutationMatrix(const TranspositionsBase< Other > &tr)
Definition: PermutationMatrix.h:340
const IndicesType & indices() const
Definition: PermutationMatrix.h:362
IndicesType & indices()
Definition: PermutationMatrix.h:364
PermutationMatrix(const MatrixBase< Other > &indices)
Definition: PermutationMatrix.h:335
PermutationMatrix(Index size)
Definition: PermutationMatrix.h:317
PermutationMatrix & operator=(const PermutationBase< Other > &other)
Definition: PermutationMatrix.h:348
Class to view a vector of integers as a permutation matrix.
Definition: PermutationMatrix.h:489
const internal::remove_all_t< typename IndicesType::Nested > & indices() const
Definition: PermutationMatrix.h:504
Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:187
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:77
static const lastp1_t end
Definition: IndexedViewHelper.h:183
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:517
Definition: EigenBase.h:32
Derived & derived()
Definition: EigenBase.h:48
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:231