11 #ifndef EIGEN_PERMUTATIONMATRIX_H 12 #define EIGEN_PERMUTATIONMATRIX_H 18 enum PermPermProduct_t {PermPermProduct};
45 template<
typename Derived>
48 typedef internal::traits<Derived> Traits;
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;
66 typedef PlainPermutationType PlainObject;
73 template<
typename OtherDerived>
81 template<
typename OtherDerived>
82 Derived&
operator=(
const TranspositionsBase<OtherDerived>& tr)
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>
238 inline PlainPermutationType
operator*(
const InverseImpl<Other,PermutationStorage>& other)
const 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>
284 struct traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex> >
285 : traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
289 typedef _StorageIndex StorageIndex;
307 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex>
311 typedef internal::traits<PermutationMatrix> Traits;
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>
421 struct traits<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> >
422 : traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
426 typedef _StorageIndex StorageIndex;
431 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex,
int _PacketAccess>
432 class Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess>
433 :
public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> >
436 typedef internal::traits<Map> Traits;
439 #ifndef EIGEN_PARSED_BY_DOXYGEN 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>
459 Map& operator=(
const TranspositionsBase<Other>& tr)
460 {
return Base::operator=(tr.derived()); }
462 #ifndef EIGEN_PARSED_BY_DOXYGEN 466 Map& operator=(
const Map& other)
468 m_indices = other.m_indices;
474 const IndicesType& indices()
const {
return m_indices; }
476 IndicesType& indices() {
return m_indices; }
480 IndicesType m_indices;
483 template<
typename _IndicesType>
class TranspositionsWrapper;
485 template<
typename _IndicesType>
486 struct traits<PermutationWrapper<_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>
517 typedef internal::traits<PermutationWrapper> Traits;
520 #ifndef EIGEN_PARSED_BY_DOXYGEN 521 typedef typename Traits::IndicesType IndicesType;
529 const typename internal::remove_all<typename IndicesType::Nested>::type&
534 typename IndicesType::Nested m_indices;
540 template<
typename MatrixDerived,
typename PermutationDerived>
552 template<
typename PermutationDerived,
typename MatrixDerived>
563 template<
typename PermutationType>
564 class InverseImpl<PermutationType, PermutationStorage>
565 :
public EigenBase<Inverse<PermutationType> >
567 typedef typename PermutationType::PlainPermutationType PlainPermutationType;
568 typedef internal::traits<PermutationType> PermTraits;
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>
627 template<>
struct AssignmentKind<DenseShape,PermutationShape> {
typedef EigenBase2EigenBase Kind; };
633 #endif // EIGEN_PERMUTATIONMATRIX_H 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)
Definition: PermutationMatrix.h:350
friend PlainPermutationType operator*(const InverseImpl< Other, PermutationStorage > &other, const PermutationBase &perm)
Definition: PermutationMatrix.h:246
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
Definition: Constants.h:500
DenseMatrixType toDenseMatrix() const
Definition: PermutationMatrix.h:124
Derived & applyTranspositionOnTheRight(Index i, Index j)
Definition: PermutationMatrix.h:185
Namespace containing all symbols from the Eigen library.
Definition: Core:287
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:150
Derived & derived()
Definition: EigenBase.h:45
Derived & operator=(const PermutationBase< OtherDerived > &other)
Definition: PermutationMatrix.h:74
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:38
PermutationMatrix & operator=(const PermutationBase< Other > &other)
Definition: PermutationMatrix.h:363
Base class for permutations.
Definition: PermutationMatrix.h:46
Definition: EigenBase.h:29
Expression of the inverse of another expression.
Definition: Inverse.h:43
Permutation matrix.
Definition: PermutationMatrix.h:308
Index size() const
Definition: PermutationMatrix.h:108
Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:183
PermutationMatrix & operator=(const TranspositionsBase< Other > &tr)
Definition: PermutationMatrix.h:371
IndicesType & indices()
Definition: PermutationMatrix.h:132
Index cols() const
Definition: PermutationMatrix.h:105
const IndicesType & indices() const
Definition: PermutationMatrix.h:388
void fill(const Scalar &value)
Definition: CwiseNullaryOp.h:315
Derived & operator=(const TranspositionsBase< OtherDerived > &tr)
Definition: PermutationMatrix.h:82
const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:543
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Class to view a vector of integers as a permutation matrix.
Definition: PermutationMatrix.h:514
void setIdentity()
Definition: PermutationMatrix.h:142
const IndicesType & indices() const
Definition: PermutationMatrix.h:130
PermutationMatrix(const TranspositionsBase< Other > &tr)
Definition: PermutationMatrix.h:355
Definition: Eigen_Colamd.h:50
Derived & setZero()
Definition: CwiseNullaryOp.h:499
Derived & applyTranspositionOnTheLeft(Index i, Index j)
Definition: PermutationMatrix.h:166
PermutationMatrix(Index size)
Definition: PermutationMatrix.h:326
InverseReturnType transpose() const
Definition: PermutationMatrix.h:202
IndicesType & indices()
Definition: PermutationMatrix.h:390
const internal::remove_all< typename IndicesType::Nested >::type & indices() const
Definition: PermutationMatrix.h:530
void setIdentity(Index newSize)
Definition: PermutationMatrix.h:151
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
void resize(Index newSize)
Definition: PermutationMatrix.h:136
Scalar & coeffRef(Index row, Index col)
Definition: DenseCoeffsBase.h:340
Index determinant() const
Definition: PermutationMatrix.h:253
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
PermutationMatrix(const PermutationBase< OtherDerived > &other)
Definition: PermutationMatrix.h:333
Index rows() const
Definition: PermutationMatrix.h:102