11 #ifndef EIGEN_PERMUTATIONMATRIX_H 12 #define EIGEN_PERMUTATIONMATRIX_H 18 enum PermPermProduct_t {PermPermProduct};
45 template<
typename Derived>
52 #ifndef EIGEN_PARSED_BY_DOXYGEN 53 typedef typename Traits::IndicesType IndicesType;
55 Flags = Traits::Flags,
56 RowsAtCompileTime = Traits::RowsAtCompileTime,
57 ColsAtCompileTime = Traits::ColsAtCompileTime,
58 MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime,
59 MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
61 typedef typename Traits::StorageIndex StorageIndex;
73 template<
typename OtherDerived>
81 template<
typename OtherDerived>
84 setIdentity(tr.
size());
85 for(
Index k=size()-1; k>=0; --k)
86 applyTranspositionOnTheRight(k,tr.
coeff(k));
90 #ifndef EIGEN_PARSED_BY_DOXYGEN 110 #ifndef EIGEN_PARSED_BY_DOXYGEN 111 template<
typename DenseDerived>
115 for (
Index i=0; i<rows(); ++i)
116 other.coeffRef(indices().coeff(i),i) =
typename DenseDerived::Scalar(1);
130 const IndicesType&
indices()
const {
return derived().indices(); }
132 IndicesType&
indices() {
return derived().indices(); }
138 indices().resize(newSize);
144 StorageIndex n = StorageIndex(size());
145 for(StorageIndex i = 0; i < n; ++i)
146 indices().coeffRef(i) = i;
168 eigen_assert(i>=0 && j>=0 && i<size() && j<size());
169 for(
Index k = 0; k < size(); ++k)
171 if(indices().coeff(k) == i) indices().coeffRef(k) = StorageIndex(j);
172 else if(indices().coeff(k) == j) indices().coeffRef(k) = StorageIndex(i);
187 eigen_assert(i>=0 && j>=0 && i<size() && j<size());
188 std::swap(indices().coeffRef(i), indices().coeffRef(j));
197 {
return InverseReturnType(derived()); }
203 {
return InverseReturnType(derived()); }
208 #ifndef EIGEN_PARSED_BY_DOXYGEN 210 template<
typename OtherDerived>
213 for (
Index i=0; i<rows();++i) indices().coeffRef(other.
indices().coeff(i)) = i;
215 template<
typename Lhs,
typename Rhs>
216 void assignProduct(
const Lhs& lhs,
const Rhs& rhs)
218 eigen_assert(lhs.cols() == rhs.rows());
219 for (
Index i=0; i<rows();++i) indices().coeffRef(i) = lhs.indices().coeff(rhs.indices().coeff(i));
229 template<
typename Other>
231 {
return PlainPermutationType(internal::PermPermProduct, derived(), other.
derived()); }
237 template<
typename Other>
239 {
return PlainPermutationType(internal::PermPermProduct, *
this, other.eval()); }
245 template<
typename Other>
friend 247 {
return PlainPermutationType(internal::PermPermProduct, other.eval(), perm); }
263 while(r<n && mask[r]) r++;
269 for(
Index k=indices().coeff(k0); k!=k0; k=indices().coeff(k))
283 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex>
285 :
traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
289 typedef _StorageIndex StorageIndex;
307 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex>
316 #ifndef EIGEN_PARSED_BY_DOXYGEN 317 typedef typename Traits::IndicesType IndicesType;
318 typedef typename Traits::StorageIndex StorageIndex;
332 template<
typename OtherDerived>
334 : m_indices(other.indices()) {}
336 #ifndef EIGEN_PARSED_BY_DOXYGEN 349 template<
typename Other>
354 template<
typename Other>
356 : m_indices(tr.size())
362 template<
typename Other>
370 template<
typename Other>
373 return Base::operator=(tr.derived());
376 #ifndef EIGEN_PARSED_BY_DOXYGEN 382 m_indices = other.m_indices;
388 const IndicesType&
indices()
const {
return m_indices; }
395 #ifndef EIGEN_PARSED_BY_DOXYGEN 396 template<
typename Other>
398 : m_indices(other.derived().nestedExpression().size())
401 StorageIndex end = StorageIndex(m_indices.size());
402 for (StorageIndex i=0; i<end;++i)
403 m_indices.coeffRef(other.derived().nestedExpression().indices().coeff(i)) = i;
405 template<
typename Lhs,
typename Rhs>
407 : m_indices(lhs.indices().size())
409 Base::assignProduct(lhs,rhs);
415 IndicesType m_indices;
420 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex,
int _PacketAccess>
422 :
traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
426 typedef _StorageIndex StorageIndex;
431 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex,
int _PacketAccess>
433 :
public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> >
439 #ifndef EIGEN_PARSED_BY_DOXYGEN 440 typedef typename Traits::IndicesType IndicesType;
441 typedef typename IndicesType::Scalar StorageIndex;
444 inline Map(
const StorageIndex* indicesPtr)
445 : m_indices(indicesPtr)
448 inline Map(
const StorageIndex* indicesPtr,
Index size)
449 : m_indices(indicesPtr,size)
453 template<
typename Other>
455 {
return Base::operator=(other.
derived()); }
458 template<
typename Other>
460 {
return Base::operator=(tr.derived()); }
462 #ifndef EIGEN_PARSED_BY_DOXYGEN 468 m_indices = other.m_indices;
474 const IndicesType&
indices()
const {
return m_indices; }
480 IndicesType m_indices;
485 template<
typename _IndicesType>
490 typedef typename _IndicesType::Scalar StorageIndex;
491 typedef _IndicesType IndicesType;
493 RowsAtCompileTime = _IndicesType::SizeAtCompileTime,
494 ColsAtCompileTime = _IndicesType::SizeAtCompileTime,
495 MaxRowsAtCompileTime = IndicesType::MaxSizeAtCompileTime,
496 MaxColsAtCompileTime = IndicesType::MaxSizeAtCompileTime,
513 template<
typename _IndicesType>
520 #ifndef EIGEN_PARSED_BY_DOXYGEN 521 typedef typename Traits::IndicesType IndicesType;
534 typename IndicesType::Nested m_indices;
540 template<
typename MatrixDerived,
typename PermutationDerived>
547 (matrix.derived(), permutation.
derived());
552 template<
typename PermutationDerived,
typename MatrixDerived>
559 (permutation.
derived(), matrix.derived());
563 template<
typename PermutationType>
565 :
public EigenBase<Inverse<PermutationType> >
567 typedef typename PermutationType::PlainPermutationType PlainPermutationType;
575 #ifndef EIGEN_PARSED_BY_DOXYGEN 576 typedef typename PermutationType::DenseMatrixType DenseMatrixType;
578 RowsAtCompileTime = PermTraits::RowsAtCompileTime,
579 ColsAtCompileTime = PermTraits::ColsAtCompileTime,
580 MaxRowsAtCompileTime = PermTraits::MaxRowsAtCompileTime,
581 MaxColsAtCompileTime = PermTraits::MaxColsAtCompileTime
585 #ifndef EIGEN_PARSED_BY_DOXYGEN 586 template<
typename DenseDerived>
590 for (
Index i=0; i<derived().rows();++i)
591 other.coeffRef(i, derived().nestedExpression().indices().coeff(i)) =
typename DenseDerived::Scalar(1);
596 PlainPermutationType
eval()
const {
return derived(); }
598 DenseMatrixType toDenseMatrix()
const {
return derived(); }
602 template<
typename OtherDerived>
friend 611 template<
typename OtherDerived>
619 template<
typename Derived>
633 #endif // EIGEN_PERMUTATIONMATRIX_H friend const Product< OtherDerived, InverseType, AliasFreeProduct > operator*(const MatrixBase< OtherDerived > &matrix, const InverseType &trPerm)
Definition: PermutationMatrix.h:604
Map & operator=(const PermutationBase< Other > &other)
Copies the other permutation into *this.
Definition: PermutationMatrix.h:454
Definition: PermutationMatrix.h:483
Index size() const
Definition: Transpositions.h:49
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:71
PlainPermutationType operator*(const PermutationBase< Other > &other) const
Definition: PermutationMatrix.h:230
PermutationMatrix(const MatrixBase< Other > &indices)
Generic constructor from expression of the indices.
Definition: PermutationMatrix.h:350
friend PlainPermutationType operator*(const InverseImpl< Other, PermutationStorage > &other, const PermutationBase &perm)
Definition: PermutationMatrix.h:246
PlainPermutationType eval() const
Definition: PermutationMatrix.h:596
InverseReturnType inverse() const
Definition: PermutationMatrix.h:196
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:88
PlainPermutationType operator*(const InverseImpl< Other, PermutationStorage > &other) const
Definition: PermutationMatrix.h:238
The type used to identify a permutation storage.
Definition: Constants.h:500
DenseMatrixType toDenseMatrix() const
Definition: PermutationMatrix.h:124
Derived & applyTranspositionOnTheRight(Index i, Index j)
Multiplies *this by the transposition on the right.
Definition: PermutationMatrix.h:185
PermutationMatrix & operator=(const PermutationMatrix &other)
This is a special case of the templated operator=.
Definition: PermutationMatrix.h:380
EIGEN_DEVICE_FUNC Derived & setZero()
Sets all coefficients in this expression to zero.
Definition: CwiseNullaryOp.h:499
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Holds information about the various numeric (i.e.
Definition: NumTraits.h:150
Derived & operator=(const PermutationBase< OtherDerived > &other)
Copies the other permutation into *this.
Definition: PermutationMatrix.h:74
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:37
PermutationMatrix & operator=(const PermutationBase< Other > &other)
Copies the other permutation into *this.
Definition: PermutationMatrix.h:363
Definition: Constants.h:512
Base class for permutations.
Definition: PermutationMatrix.h:46
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:28
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,Index) const provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.
Definition: PlainObjectBase.h:177
PermutationMatrix(const PermutationMatrix &other)
Standard copy constructor.
Definition: PermutationMatrix.h:339
Expression of the inverse of another expression.
Definition: Inverse.h:43
Permutation matrix.
Definition: PermutationMatrix.h:308
Index size() const
Definition: PermutationMatrix.h:108
const StorageIndex & coeff(Index i) const
Direct access to the underlying index vector.
Definition: Transpositions.h:56
PermutationMatrix & operator=(const TranspositionsBase< Other > &tr)
Assignment from the Transpositions tr.
Definition: PermutationMatrix.h:371
IndicesType & indices()
Definition: PermutationMatrix.h:132
Index cols() const
Definition: PermutationMatrix.h:105
const IndicesType & indices() const
const version of indices().
Definition: PermutationMatrix.h:388
Derived & operator=(const TranspositionsBase< OtherDerived > &tr)
Assignment from the Transpositions tr.
Definition: PermutationMatrix.h:82
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: AssignEvaluator.h:744
Class to view a vector of integers as a permutation matrix.
Definition: PermutationMatrix.h:514
Derived & operator=(const PermutationBase &other)
This is a special case of the templated operator=.
Definition: PermutationMatrix.h:94
void setIdentity()
Sets *this to be the identity permutation matrix.
Definition: PermutationMatrix.h:142
const IndicesType & indices() const
const version of indices().
Definition: PermutationMatrix.h:130
PermutationMatrix(const TranspositionsBase< Other > &tr)
Convert the Transpositions tr to a permutation matrix.
Definition: PermutationMatrix.h:355
Definition: BandTriangularSolver.h:13
Derived & applyTranspositionOnTheLeft(Index i, Index j)
Multiplies *this by the transposition on the left.
Definition: PermutationMatrix.h:166
PermutationMatrix(Index size)
Constructs an uninitialized permutation matrix of given size.
Definition: PermutationMatrix.h:326
Map & operator=(const TranspositionsBase< Other > &tr)
Assignment from the Transpositions tr.
Definition: PermutationMatrix.h:459
Definition: AssignEvaluator.h:740
InverseReturnType transpose() const
Definition: PermutationMatrix.h:202
IndicesType & indices()
Definition: PermutationMatrix.h:390
const Product< InverseType, OtherDerived, AliasFreeProduct > operator*(const MatrixBase< OtherDerived > &matrix) const
Definition: PermutationMatrix.h:613
const internal::remove_all< typename IndicesType::Nested >::type & indices() const
const version of indices().
Definition: PermutationMatrix.h:530
IndicesType & indices()
Definition: PermutationMatrix.h:476
Definition: Transpositions.h:16
void setIdentity(Index newSize)
Sets *this to be the identity permutation matrix of given size.
Definition: PermutationMatrix.h:151
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
void resize(Index newSize)
Resizes to given size.
Definition: PermutationMatrix.h:136
Index determinant() const
Definition: PermutationMatrix.h:253
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:44
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
PermutationMatrix(const PermutationBase< OtherDerived > &other)
Copy constructor.
Definition: PermutationMatrix.h:333
const IndicesType & indices() const
const version of indices().
Definition: PermutationMatrix.h:474
Map & operator=(const Map &other)
This is a special case of the templated operator=.
Definition: PermutationMatrix.h:466
Index rows() const
Definition: PermutationMatrix.h:102
Definition: Constants.h:519