11 #ifndef EIGEN_PERMUTATIONMATRIX_H 12 #define EIGEN_PERMUTATIONMATRIX_H 42 enum PermPermProduct_t {PermPermProduct};
46 template<
typename Derived>
49 typedef internal::traits<Derived> Traits;
53 #ifndef EIGEN_PARSED_BY_DOXYGEN 54 typedef typename Traits::IndicesType IndicesType;
56 Flags = Traits::Flags,
57 RowsAtCompileTime = Traits::RowsAtCompileTime,
58 ColsAtCompileTime = Traits::ColsAtCompileTime,
59 MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime,
60 MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
62 typedef typename Traits::StorageIndex StorageIndex;
67 typedef PlainPermutationType PlainObject;
74 template<
typename OtherDerived>
82 template<
typename OtherDerived>
83 Derived&
operator=(
const TranspositionsBase<OtherDerived>& tr)
85 setIdentity(tr.size());
86 for(
Index k=size()-1; k>=0; --k)
87 applyTranspositionOnTheRight(k,tr.coeff(k));
91 #ifndef EIGEN_PARSED_BY_DOXYGEN 111 #ifndef EIGEN_PARSED_BY_DOXYGEN 112 template<
typename DenseDerived>
116 for (
Index i=0; i<rows(); ++i)
117 other.coeffRef(indices().coeff(i),i) =
typename DenseDerived::Scalar(1);
131 const IndicesType&
indices()
const {
return derived().indices(); }
133 IndicesType&
indices() {
return derived().indices(); }
139 indices().resize(newSize);
145 StorageIndex n = StorageIndex(size());
146 for(StorageIndex i = 0; i < n; ++i)
147 indices().coeffRef(i) = i;
169 eigen_assert(i>=0 && j>=0 && i<size() && j<size());
170 for(
Index k = 0; k < size(); ++k)
172 if(indices().coeff(k) == i) indices().coeffRef(k) = StorageIndex(j);
173 else if(indices().coeff(k) == j) indices().coeffRef(k) = StorageIndex(i);
188 eigen_assert(i>=0 && j>=0 && i<size() && j<size());
189 std::swap(indices().coeffRef(i), indices().coeffRef(j));
198 {
return InverseReturnType(derived()); }
204 {
return InverseReturnType(derived()); }
209 #ifndef EIGEN_PARSED_BY_DOXYGEN 211 template<
typename OtherDerived>
214 for (
Index i=0; i<rows();++i) indices().coeffRef(other.
indices().coeff(i)) = i;
216 template<
typename Lhs,
typename Rhs>
217 void assignProduct(
const Lhs& lhs,
const Rhs& rhs)
219 eigen_assert(lhs.cols() == rhs.rows());
220 for (
Index i=0; i<rows();++i) indices().coeffRef(i) = lhs.indices().coeff(rhs.indices().coeff(i));
230 template<
typename Other>
232 {
return PlainPermutationType(internal::PermPermProduct, derived(), other.
derived()); }
238 template<
typename Other>
239 inline PlainPermutationType
operator*(
const InverseImpl<Other,PermutationStorage>& other)
const 240 {
return PlainPermutationType(internal::PermPermProduct, *
this, other.eval()); }
246 template<
typename Other>
friend 248 {
return PlainPermutationType(internal::PermPermProduct, other.eval(), perm); }
264 while(r<n && mask[r]) r++;
269 mask.coeffRef(k0) =
true;
270 for(
Index k=indices().coeff(k0); k!=k0; k=indices().coeff(k))
272 mask.coeffRef(k) =
true;
298 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex>
299 struct traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex> >
300 : traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
304 typedef _StorageIndex StorageIndex;
309 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex>
313 typedef internal::traits<PermutationMatrix> Traits;
318 #ifndef EIGEN_PARSED_BY_DOXYGEN 319 typedef typename Traits::IndicesType IndicesType;
320 typedef typename Traits::StorageIndex StorageIndex;
334 template<
typename OtherDerived>
336 : m_indices(other.indices()) {}
338 #ifndef EIGEN_PARSED_BY_DOXYGEN 351 template<
typename Other>
356 template<
typename Other>
358 : m_indices(tr.size())
364 template<
typename Other>
372 template<
typename Other>
375 return Base::operator=(tr.derived());
378 #ifndef EIGEN_PARSED_BY_DOXYGEN 384 m_indices = other.m_indices;
390 const IndicesType&
indices()
const {
return m_indices; }
397 #ifndef EIGEN_PARSED_BY_DOXYGEN 398 template<
typename Other>
400 : m_indices(other.derived().nestedExpression().size())
403 StorageIndex end = StorageIndex(m_indices.size());
404 for (StorageIndex i=0; i<end;++i)
405 m_indices.coeffRef(other.derived().nestedExpression().indices().coeff(i)) = i;
407 template<
typename Lhs,
typename Rhs>
409 : m_indices(lhs.indices().size())
411 Base::assignProduct(lhs,rhs);
417 IndicesType m_indices;
422 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex,
int _PacketAccess>
423 struct traits<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> >
424 : traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
428 typedef _StorageIndex StorageIndex;
433 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex,
int _PacketAccess>
434 class Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess>
435 :
public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> >
438 typedef internal::traits<Map> Traits;
441 #ifndef EIGEN_PARSED_BY_DOXYGEN 443 typedef typename IndicesType::Scalar StorageIndex;
446 inline Map(
const StorageIndex* indicesPtr)
447 : m_indices(indicesPtr)
450 inline Map(
const StorageIndex* indicesPtr,
Index size)
451 : m_indices(indicesPtr,size)
455 template<
typename Other>
457 {
return Base::operator=(other.
derived()); }
460 template<
typename Other>
461 Map& operator=(
const TranspositionsBase<Other>& tr)
462 {
return Base::operator=(tr.derived()); }
464 #ifndef EIGEN_PARSED_BY_DOXYGEN 468 Map& operator=(
const Map& other)
470 m_indices = other.m_indices;
476 const IndicesType& indices()
const {
return m_indices; }
478 IndicesType& indices() {
return m_indices; }
482 IndicesType m_indices;
497 template<
typename _IndicesType>
class TranspositionsWrapper;
499 template<
typename _IndicesType>
500 struct traits<PermutationWrapper<_IndicesType> >
504 typedef typename _IndicesType::Scalar StorageIndex;
505 typedef _IndicesType IndicesType;
507 RowsAtCompileTime = _IndicesType::SizeAtCompileTime,
508 ColsAtCompileTime = _IndicesType::SizeAtCompileTime,
509 MaxRowsAtCompileTime = IndicesType::MaxSizeAtCompileTime,
510 MaxColsAtCompileTime = IndicesType::MaxSizeAtCompileTime,
516 template<
typename _IndicesType>
520 typedef internal::traits<PermutationWrapper> Traits;
523 #ifndef EIGEN_PARSED_BY_DOXYGEN 524 typedef typename Traits::IndicesType IndicesType;
532 const typename internal::remove_all<typename IndicesType::Nested>::type&
537 typename IndicesType::Nested m_indices;
543 template<
typename MatrixDerived,
typename PermutationDerived>
550 (matrix.derived(), permutation.
derived());
555 template<
typename PermutationDerived,
typename MatrixDerived>
562 (permutation.
derived(), matrix.derived());
566 template<
typename PermutationType>
567 class InverseImpl<PermutationType, PermutationStorage>
568 :
public EigenBase<Inverse<PermutationType> >
570 typedef typename PermutationType::PlainPermutationType PlainPermutationType;
571 typedef internal::traits<PermutationType> PermTraits;
578 #ifndef EIGEN_PARSED_BY_DOXYGEN 579 typedef typename PermutationType::DenseMatrixType DenseMatrixType;
581 RowsAtCompileTime = PermTraits::RowsAtCompileTime,
582 ColsAtCompileTime = PermTraits::ColsAtCompileTime,
583 MaxRowsAtCompileTime = PermTraits::MaxRowsAtCompileTime,
584 MaxColsAtCompileTime = PermTraits::MaxColsAtCompileTime
588 #ifndef EIGEN_PARSED_BY_DOXYGEN 589 template<
typename DenseDerived>
593 for (
Index i=0; i<derived().rows();++i)
594 other.coeffRef(i, derived().nestedExpression().indices().coeff(i)) =
typename DenseDerived::Scalar(1);
599 PlainPermutationType eval()
const {
return derived(); }
601 DenseMatrixType toDenseMatrix()
const {
return derived(); }
605 template<
typename OtherDerived>
friend 614 template<
typename OtherDerived>
622 template<
typename Derived>
630 template<>
struct AssignmentKind<DenseShape,PermutationShape> {
typedef EigenBase2EigenBase Kind; };
636 #endif // EIGEN_PERMUTATIONMATRIX_H Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:107
PermutationMatrix(const MatrixBase< Other > &indices)
Definition: PermutationMatrix.h:352
friend PlainPermutationType operator*(const InverseImpl< Other, PermutationStorage > &other, const PermutationBase &perm)
Definition: PermutationMatrix.h:247
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:89
const internal::remove_all< typename IndicesType::Nested >::type & indices() const
Definition: PermutationMatrix.h:533
Definition: Constants.h:499
Derived & applyTranspositionOnTheRight(Index i, Index j)
Definition: PermutationMatrix.h:186
Index size() const
Definition: PermutationMatrix.h:109
const IndicesType & indices() const
Definition: PermutationMatrix.h:131
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:107
Derived & derived()
Definition: EigenBase.h:44
Derived & operator=(const PermutationBase< OtherDerived > &other)
Definition: PermutationMatrix.h:75
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:37
PermutationMatrix & operator=(const PermutationBase< Other > &other)
Definition: PermutationMatrix.h:365
Index rows() const
Definition: PermutationMatrix.h:103
Base class for permutations.
Definition: PermutationMatrix.h:47
Definition: EigenBase.h:28
Expression of the inverse of another expression.
Definition: Inverse.h:43
Permutation matrix.
Definition: PermutationMatrix.h:310
PermutationMatrix & operator=(const TranspositionsBase< Other > &tr)
Definition: PermutationMatrix.h:373
IndicesType & indices()
Definition: PermutationMatrix.h:133
PlainPermutationType operator*(const PermutationBase< Other > &other) const
Definition: PermutationMatrix.h:231
void fill(const Scalar &value)
Definition: CwiseNullaryOp.h:326
Derived & operator=(const TranspositionsBase< OtherDerived > &tr)
Definition: PermutationMatrix.h:83
DenseMatrixType toDenseMatrix() const
Definition: PermutationMatrix.h:125
Index determinant() const
Definition: PermutationMatrix.h:254
Class to view a vector of integers as a permutation matrix.
Definition: PermutationMatrix.h:517
InverseReturnType transpose() const
Definition: PermutationMatrix.h:203
void setIdentity()
Definition: PermutationMatrix.h:143
PermutationMatrix(const TranspositionsBase< Other > &tr)
Definition: PermutationMatrix.h:357
InverseReturnType inverse() const
Definition: PermutationMatrix.h:197
Definition: Eigen_Colamd.h:54
Derived & setZero()
Definition: CwiseNullaryOp.h:504
Derived & applyTranspositionOnTheLeft(Index i, Index j)
Definition: PermutationMatrix.h:167
PermutationMatrix(Index size)
Definition: PermutationMatrix.h:328
const IndicesType & indices() const
Definition: PermutationMatrix.h:390
IndicesType & indices()
Definition: PermutationMatrix.h:392
void setIdentity(Index newSize)
Definition: PermutationMatrix.h:152
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
void resize(Index newSize)
Definition: PermutationMatrix.h:137
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Index cols() const
Definition: PermutationMatrix.h:106
PermutationMatrix(const PermutationBase< OtherDerived > &other)
Definition: PermutationMatrix.h:335
PlainPermutationType operator*(const InverseImpl< Other, PermutationStorage > &other) const
Definition: PermutationMatrix.h:239