Eigen::PermutationBase< Derived > Class Template Reference

Base class for permutations. More...

#include <PermutationMatrix.h>

+ Inheritance diagram for Eigen::PermutationBase< Derived >:

Public Types

enum  {
  Flags = Traits::Flags , RowsAtCompileTime = Traits::RowsAtCompileTime , ColsAtCompileTime = Traits::ColsAtCompileTime , MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime ,
  MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
}
 
typedef Traits::IndicesType IndicesType
 
typedef Traits::StorageIndex StorageIndex
 
typedef Matrix< StorageIndex, RowsAtCompileTime, ColsAtCompileTime, 0, MaxRowsAtCompileTime, MaxColsAtCompileTimeDenseMatrixType
 
typedef PermutationMatrix< IndicesType::SizeAtCompileTime, IndicesType::MaxSizeAtCompileTime, StorageIndexPlainPermutationType
 
typedef PlainPermutationType PlainObject
 
typedef Inverse< Derived > InverseReturnType
 
typedef void Scalar
 
- Public Types inherited from Eigen::EigenBase< Derived >
typedef Eigen::Index Index
 The interface type of indices. More...
 
typedef internal::traits< Derived >::StorageKind StorageKind
 

Public Member Functions

template<typename OtherDerived >
Derived & operator= (const PermutationBase< OtherDerived > &other)
 
template<typename OtherDerived >
Derived & operator= (const TranspositionsBase< OtherDerived > &tr)
 
EIGEN_DEVICE_FUNC Index rows () const
 
EIGEN_DEVICE_FUNC Index cols () const
 
EIGEN_DEVICE_FUNC Index size () const
 
template<typename DenseDerived >
void evalTo (MatrixBase< DenseDerived > &other) const
 
DenseMatrixType toDenseMatrix () const
 
const IndicesTypeindices () const
 
IndicesTypeindices ()
 
void resize (Index newSize)
 
void setIdentity ()
 
void setIdentity (Index newSize)
 
Derived & applyTranspositionOnTheLeft (Index i, Index j)
 
Derived & applyTranspositionOnTheRight (Index i, Index j)
 
InverseReturnType inverse () const
 
InverseReturnType transpose () const
 
template<typename Other >
PlainPermutationType operator* (const PermutationBase< Other > &other) const
 
template<typename Other >
PlainPermutationType operator* (const InverseImpl< Other, PermutationStorage > &other) const
 
Index determinant () const
 
constexpr EIGEN_DEVICE_FUNC Derived & derived ()
 
constexpr EIGEN_DEVICE_FUNC const Derived & derived () const
 
- Public Member Functions inherited from Eigen::EigenBase< Derived >
constexpr EIGEN_DEVICE_FUNC Derived & derived ()
 
constexpr EIGEN_DEVICE_FUNC const Derived & derived () const
 
EIGEN_DEVICE_FUNC Derived & const_cast_derived () const
 
EIGEN_DEVICE_FUNC const Derived & const_derived () const
 
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows () const EIGEN_NOEXCEPT
 
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols () const EIGEN_NOEXCEPT
 
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size () const EIGEN_NOEXCEPT
 
template<typename Dest >
EIGEN_DEVICE_FUNC void evalTo (Dest &dst) const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void addTo (Dest &dst) const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void subTo (Dest &dst) const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void applyThisOnTheRight (Dest &dst) const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void applyThisOnTheLeft (Dest &dst) const
 
template<typename Device >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DeviceWrapper< Derived, Device > device (Device &device)
 
template<typename Device >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DeviceWrapper< const Derived, Device > device (Device &device) const
 

Protected Member Functions

template<typename OtherDerived >
void assignTranspose (const PermutationBase< OtherDerived > &other)
 
template<typename Lhs , typename Rhs >
void assignProduct (const Lhs &lhs, const Rhs &rhs)
 

Private Types

typedef internal::traits< Derived > Traits
 
typedef EigenBase< Derived > Base
 

Friends

template<typename Other >
PlainPermutationType operator* (const InverseImpl< Other, PermutationStorage > &other, const PermutationBase &perm)
 

Detailed Description

template<typename Derived>
class Eigen::PermutationBase< Derived >

Base class for permutations.

Template Parameters
Derivedthe derived class

This class is the base class for all expressions representing a permutation matrix, internally stored as a vector of integers. The convention followed here is that if \( \sigma \) is a permutation, the corresponding permutation matrix \( P_\sigma \) is such that if \( (e_1,\ldots,e_p) \) is the canonical basis, we have:

\[ P_\sigma(e_i) = e_{\sigma(i)}. \]

This convention ensures that for any two permutations \( \sigma, \tau \), we have:

\[ P_{\sigma\circ\tau} = P_\sigma P_\tau. \]

Permutation matrices are square and invertible.

Notice that in addition to the member functions and operators listed here, there also are non-member operator* to multiply any kind of permutation object with any kind of matrix expression (MatrixBase) on either side.

See also
class PermutationMatrix, class PermutationWrapper

Member Typedef Documentation

◆ Base

template<typename Derived >
typedef EigenBase<Derived> Eigen::PermutationBase< Derived >::Base
private

◆ DenseMatrixType

◆ IndicesType

template<typename Derived >
typedef Traits::IndicesType Eigen::PermutationBase< Derived >::IndicesType

◆ InverseReturnType

template<typename Derived >
typedef Inverse<Derived> Eigen::PermutationBase< Derived >::InverseReturnType

◆ PlainObject

template<typename Derived >
typedef PlainPermutationType Eigen::PermutationBase< Derived >::PlainObject

◆ PlainPermutationType

template<typename Derived >
typedef PermutationMatrix<IndicesType::SizeAtCompileTime, IndicesType::MaxSizeAtCompileTime, StorageIndex> Eigen::PermutationBase< Derived >::PlainPermutationType

◆ Scalar

template<typename Derived >
typedef void Eigen::PermutationBase< Derived >::Scalar

◆ StorageIndex

template<typename Derived >
typedef Traits::StorageIndex Eigen::PermutationBase< Derived >::StorageIndex

◆ Traits

template<typename Derived >
typedef internal::traits<Derived> Eigen::PermutationBase< Derived >::Traits
private

Member Enumeration Documentation

◆ anonymous enum

template<typename Derived >
anonymous enum
Enumerator
Flags 
RowsAtCompileTime 
ColsAtCompileTime 
MaxRowsAtCompileTime 
MaxColsAtCompileTime 
56  {
57  Flags = Traits::Flags,
58  RowsAtCompileTime = Traits::RowsAtCompileTime,
59  ColsAtCompileTime = Traits::ColsAtCompileTime,
60  MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime,
61  MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
62  };
@ MaxRowsAtCompileTime
Definition: PermutationMatrix.h:60
@ RowsAtCompileTime
Definition: PermutationMatrix.h:58
@ MaxColsAtCompileTime
Definition: PermutationMatrix.h:61
@ ColsAtCompileTime
Definition: PermutationMatrix.h:59
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56

Member Function Documentation

◆ applyTranspositionOnTheLeft()

template<typename Derived >
Derived& Eigen::PermutationBase< Derived >::applyTranspositionOnTheLeft ( Index  i,
Index  j 
)
inline

Multiplies *this by the transposition \((ij)\) on the left.

Returns
a reference to *this.
Warning
This is much slower than applyTranspositionOnTheRight(Index,Index): this has linear complexity and requires a lot of branching.
See also
applyTranspositionOnTheRight(Index,Index)
143  {
144  eigen_assert(i >= 0 && j >= 0 && i < size() && j < size());
145  for (Index k = 0; k < size(); ++k) {
146  if (indices().coeff(k) == i)
147  indices().coeffRef(k) = StorageIndex(j);
148  else if (indices().coeff(k) == j)
149  indices().coeffRef(k) = StorageIndex(i);
150  }
151  return derived();
152  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define eigen_assert(x)
Definition: Macros.h:910
Traits::StorageIndex StorageIndex
Definition: PermutationMatrix.h:63
constexpr EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:49
EIGEN_DEVICE_FUNC Index size() const
Definition: PermutationMatrix.h:96
const IndicesType & indices() const
Definition: PermutationMatrix.h:113
char char char int int * k
Definition: level2_impl.h:374
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Eigen::PermutationBase< Derived >::derived(), eigen_assert, i, Eigen::PermutationBase< Derived >::indices(), j, k, and Eigen::PermutationBase< Derived >::size().

◆ applyTranspositionOnTheRight()

template<typename Derived >
Derived& Eigen::PermutationBase< Derived >::applyTranspositionOnTheRight ( Index  i,
Index  j 
)
inline

Multiplies *this by the transposition \((ij)\) on the right.

Returns
a reference to *this.

This is a fast operation, it only consists in swapping two indices.

See also
applyTranspositionOnTheLeft(Index,Index)
162  {
163  eigen_assert(i >= 0 && j >= 0 && i < size() && j < size());
164  std::swap(indices().coeffRef(i), indices().coeffRef(j));
165  return derived();
166  }
EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:117

References Eigen::PermutationBase< Derived >::derived(), eigen_assert, i, Eigen::PermutationBase< Derived >::indices(), j, Eigen::PermutationBase< Derived >::size(), and swap().

Referenced by Eigen::ColPivHouseholderQR< MatrixType_, PermutationIndex_ >::computeInPlace(), Eigen::FullPivHouseholderQR< MatrixType_, PermutationIndex_ >::computeInPlace(), and Eigen::PermutationBase< Derived >::operator=().

◆ assignProduct()

template<typename Derived >
template<typename Lhs , typename Rhs >
void Eigen::PermutationBase< Derived >::assignProduct ( const Lhs &  lhs,
const Rhs &  rhs 
)
inlineprotected
188  {
189  eigen_assert(lhs.cols() == rhs.rows());
190  for (Index i = 0; i < rows(); ++i) indices().coeffRef(i) = lhs.indices().coeff(rhs.indices().coeff(i));
191  }
EIGEN_DEVICE_FUNC Index rows() const
Definition: PermutationMatrix.h:90

References eigen_assert, i, Eigen::PermutationBase< Derived >::indices(), and Eigen::PermutationBase< Derived >::rows().

Referenced by Eigen::PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_ >::PermutationMatrix().

◆ assignTranspose()

template<typename Derived >
template<typename OtherDerived >
void Eigen::PermutationBase< Derived >::assignTranspose ( const PermutationBase< OtherDerived > &  other)
inlineprotected
184  {
185  for (Index i = 0; i < rows(); ++i) indices().coeffRef(other.indices().coeff(i)) = i;
186  }

References i, Eigen::PermutationBase< Derived >::indices(), and Eigen::PermutationBase< Derived >::rows().

◆ cols()

◆ derived() [1/2]

◆ derived() [2/2]

template<typename Derived >
constexpr EIGEN_DEVICE_FUNC const Derived& Eigen::EigenBase< Derived >::derived
inlineconstexpr
Returns
a const reference to the derived object
51 { return *static_cast<const Derived*>(this); }

◆ determinant()

template<typename Derived >
Index Eigen::PermutationBase< Derived >::determinant ( ) const
inline
Returns
the determinant of the permutation matrix, which is either 1 or -1 depending on the parity of the permutation.

This function is O(n) procedure allocating a buffer of n booleans.

228  {
229  Index res = 1;
230  Index n = size();
231  Matrix<bool, RowsAtCompileTime, 1, 0, MaxRowsAtCompileTime> mask(n);
232  mask.fill(false);
233  Index r = 0;
234  while (r < n) {
235  // search for the next seed
236  while (r < n && mask[r]) r++;
237  if (r >= n) break;
238  // we got one, let's follow it until we are back to the seed
239  Index k0 = r++;
240  mask.coeffRef(k0) = true;
241  for (Index k = indices().coeff(k0); k != k0; k = indices().coeff(k)) {
242  mask.coeffRef(k) = true;
243  res = -res;
244  }
245  }
246  return res;
247  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
r
Definition: UniformPSDSelfTest.py:20

References Eigen::Matrix< Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_ >::coeffRef(), Eigen::PermutationBase< Derived >::indices(), k, n, UniformPSDSelfTest::r, res, and Eigen::PermutationBase< Derived >::size().

◆ evalTo()

template<typename Derived >
template<typename DenseDerived >
void Eigen::PermutationBase< Derived >::evalTo ( MatrixBase< DenseDerived > &  other) const
inline
100  {
101  other.setZero();
102  for (Index i = 0; i < rows(); ++i) other.coeffRef(indices().coeff(i), i) = typename DenseDerived::Scalar(1);
103  }
SCALAR Scalar
Definition: bench_gemm.cpp:45

References i, Eigen::PermutationBase< Derived >::indices(), Eigen::PermutationBase< Derived >::rows(), and Eigen::DenseBase< Derived >::setZero().

◆ indices() [1/2]

template<typename Derived >
IndicesType& Eigen::PermutationBase< Derived >::indices ( )
inline
Returns
a reference to the stored array representing the permutation.
115 { return derived().indices(); }

References Eigen::PermutationBase< Derived >::derived().

◆ indices() [2/2]

◆ inverse()

template<typename Derived >
InverseReturnType Eigen::PermutationBase< Derived >::inverse ( ) const
inline
Returns
the inverse permutation matrix.
Note
\blank \note_try_to_help_rvo
172 { return InverseReturnType(derived()); }
Inverse< Derived > InverseReturnType
Definition: PermutationMatrix.h:70

References Eigen::PermutationBase< Derived >::derived().

Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::_solve_impl(), and Eigen::FullPivLU< MatrixType_, PermutationIndex_ >::_solve_impl_transposed().

◆ operator*() [1/2]

template<typename Derived >
template<typename Other >
PlainPermutationType Eigen::PermutationBase< Derived >::operator* ( const InverseImpl< Other, PermutationStorage > &  other) const
inline
Returns
the product of a permutation with another inverse permutation.
Note
\blank \note_try_to_help_rvo
209  {
210  return PlainPermutationType(internal::PermPermProduct, *this, other.eval());
211  }
PermutationMatrix< IndicesType::SizeAtCompileTime, IndicesType::MaxSizeAtCompileTime, StorageIndex > PlainPermutationType
Definition: PermutationMatrix.h:67
@ PermPermProduct
Definition: PermutationMatrix.h:21

References Eigen::internal::PermPermProduct.

◆ operator*() [2/2]

template<typename Derived >
template<typename Other >
PlainPermutationType Eigen::PermutationBase< Derived >::operator* ( const PermutationBase< Other > &  other) const
inline
Returns
the product permutation matrix.
Note
\blank \note_try_to_help_rvo
200  {
201  return PlainPermutationType(internal::PermPermProduct, derived(), other.derived());
202  }

References Eigen::PermutationBase< Derived >::derived(), and Eigen::internal::PermPermProduct.

◆ operator=() [1/2]

template<typename Derived >
template<typename OtherDerived >
Derived& Eigen::PermutationBase< Derived >::operator= ( const PermutationBase< OtherDerived > &  other)
inline

Copies the other permutation into *this

76  {
77  indices() = other.indices();
78  return derived();
79  }

References Eigen::PermutationBase< Derived >::derived(), and Eigen::PermutationBase< Derived >::indices().

Referenced by Eigen::PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_ >::operator=().

◆ operator=() [2/2]

template<typename Derived >
template<typename OtherDerived >
Derived& Eigen::PermutationBase< Derived >::operator= ( const TranspositionsBase< OtherDerived > &  tr)
inline

Assignment from the Transpositions tr

83  {
84  setIdentity(tr.size());
85  for (Index k = size() - 1; k >= 0; --k) applyTranspositionOnTheRight(k, tr.coeff(k));
86  return derived();
87  }
Derived & applyTranspositionOnTheRight(Index i, Index j)
Definition: PermutationMatrix.h:162
void setIdentity()
Definition: PermutationMatrix.h:122

References Eigen::PermutationBase< Derived >::applyTranspositionOnTheRight(), Eigen::TranspositionsBase< Derived >::coeff(), Eigen::PermutationBase< Derived >::derived(), k, Eigen::PermutationBase< Derived >::setIdentity(), Eigen::PermutationBase< Derived >::size(), and Eigen::TranspositionsBase< Derived >::size().

◆ resize()

◆ rows()

◆ setIdentity() [1/2]

◆ setIdentity() [2/2]

template<typename Derived >
void Eigen::PermutationBase< Derived >::setIdentity ( Index  newSize)
inline

Sets *this to be the identity permutation matrix of given size.

129  {
130  resize(newSize);
131  setIdentity();
132  }
void resize(Index newSize)
Definition: PermutationMatrix.h:119

References Eigen::PermutationBase< Derived >::resize(), and Eigen::PermutationBase< Derived >::setIdentity().

◆ size()

◆ toDenseMatrix()

template<typename Derived >
DenseMatrixType Eigen::PermutationBase< Derived >::toDenseMatrix ( ) const
inline
Returns
a Matrix object initialized from this permutation matrix. Notice that it is inefficient to return this Matrix object by value. For efficiency, favor using the Matrix constructor taking EigenBase objects.
110 { return derived(); }

References Eigen::PermutationBase< Derived >::derived().

◆ transpose()

Friends And Related Function Documentation

◆ operator*

template<typename Derived >
template<typename Other >
PlainPermutationType operator* ( const InverseImpl< Other, PermutationStorage > &  other,
const PermutationBase< Derived > &  perm 
)
friend
Returns
the product of an inverse permutation with another permutation.
Note
\blank \note_try_to_help_rvo
219  {
220  return PlainPermutationType(internal::PermPermProduct, other.eval(), perm);
221  }

The documentation for this class was generated from the following file: