10#ifndef EIGEN_TRANSPOSITIONS_H
11#define EIGEN_TRANSPOSITIONS_H
15template<
typename Derived>
16class TranspositionsBase
18 typedef internal::traits<Derived> Traits;
22 typedef typename Traits::IndicesType IndicesType;
23 typedef typename IndicesType::Scalar StorageIndex;
26 Derived& derived() {
return *
static_cast<Derived*
>(
this); }
27 const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
30 template<
typename OtherDerived>
31 Derived& operator=(
const TranspositionsBase<OtherDerived>& other)
33 indices() = other.indices();
38 Index size()
const {
return indices().size(); }
40 Index rows()
const {
return indices().size(); }
42 Index cols()
const {
return indices().size(); }
45 inline const StorageIndex& coeff(Index i)
const {
return indices().coeff(i); }
47 inline StorageIndex& coeffRef(Index i) {
return indices().coeffRef(i); }
49 inline const StorageIndex& operator()(Index i)
const {
return indices()(i); }
51 inline StorageIndex& operator()(Index i) {
return indices()(i); }
53 inline const StorageIndex& operator[](Index i)
const {
return indices()(i); }
55 inline StorageIndex& operator[](Index i) {
return indices()(i); }
58 const IndicesType& indices()
const {
return derived().indices(); }
60 IndicesType& indices() {
return derived().indices(); }
63 inline void resize(Index newSize)
65 indices().resize(newSize);
71 for(StorageIndex i = 0; i < indices().size(); ++i)
97 inline Transpose<TranspositionsBase> inverse()
const
98 {
return Transpose<TranspositionsBase>(derived()); }
101 inline Transpose<TranspositionsBase> transpose()
const
102 {
return Transpose<TranspositionsBase>(derived()); }
108template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex>
109struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
110 : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
112 typedef Matrix<_StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
113 typedef TranspositionsStorage StorageKind;
146template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex>
147class Transpositions :
public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
149 typedef internal::traits<Transpositions> Traits;
152 typedef TranspositionsBase<Transpositions> Base;
153 typedef typename Traits::IndicesType IndicesType;
154 typedef typename IndicesType::Scalar StorageIndex;
156 inline Transpositions() {}
159 template<
typename OtherDerived>
161 : m_indices(other.
indices()) {}
164 template<
typename Other>
169 template<
typename OtherDerived>
170 Transpositions&
operator=(
const TranspositionsBase<OtherDerived>& other)
172 return Base::operator=(other);
181 const IndicesType&
indices()
const {
return m_indices; }
187 IndicesType m_indices;
192template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex,
int _PacketAccess>
193struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,_PacketAccess> >
194 : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
196 typedef Map<const Matrix<_StorageIndex,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1>, _PacketAccess> IndicesType;
197 typedef _StorageIndex StorageIndex;
198 typedef TranspositionsStorage StorageKind;
202template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex,
int PacketAccess>
203class Map<
Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,PacketAccess>
204 :
public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,PacketAccess> >
206 typedef internal::traits<Map> Traits;
209 typedef TranspositionsBase<Map> Base;
210 typedef typename Traits::IndicesType IndicesType;
211 typedef typename IndicesType::Scalar StorageIndex;
213 explicit inline Map(
const StorageIndex* indicesPtr)
214 : m_indices(indicesPtr)
217 inline Map(
const StorageIndex* indicesPtr,
Index size)
218 : m_indices(indicesPtr,size)
222 template<
typename OtherDerived>
223 Map& operator=(
const TranspositionsBase<OtherDerived>& other)
225 return Base::operator=(other);
228 #ifndef EIGEN_PARSED_BY_DOXYGEN
232 Map& operator=(
const Map& other)
234 m_indices = other.m_indices;
240 const IndicesType& indices()
const {
return m_indices; }
243 IndicesType& indices() {
return m_indices; }
247 IndicesType m_indices;
251template<
typename _IndicesType>
252struct traits<TranspositionsWrapper<_IndicesType> >
253 : traits<PermutationWrapper<_IndicesType> >
255 typedef TranspositionsStorage StorageKind;
259template<
typename _IndicesType>
260class TranspositionsWrapper
261 :
public TranspositionsBase<TranspositionsWrapper<_IndicesType> >
263 typedef internal::traits<TranspositionsWrapper> Traits;
266 typedef TranspositionsBase<TranspositionsWrapper> Base;
267 typedef typename Traits::IndicesType IndicesType;
268 typedef typename IndicesType::Scalar StorageIndex;
270 explicit inline TranspositionsWrapper(IndicesType& indices)
275 template<
typename OtherDerived>
276 TranspositionsWrapper& operator=(
const TranspositionsBase<OtherDerived>& other)
278 return Base::operator=(other);
282 const IndicesType& indices()
const {
return m_indices; }
285 IndicesType& indices() {
return m_indices; }
289 typename IndicesType::Nested m_indices;
296template<
typename MatrixDerived,
typename TranspositionsDerived>
300 const TranspositionsBase<TranspositionsDerived>& transpositions)
303 (matrix.derived(), transpositions.derived());
308template<
typename TranspositionsDerived,
typename MatrixDerived>
310const Product<TranspositionsDerived, MatrixDerived, AliasFreeProduct>
311operator*(
const TranspositionsBase<TranspositionsDerived> &transpositions,
315 (transpositions.derived(), matrix.derived());
322template<
typename Derived>
323struct traits<Transpose<TranspositionsBase<Derived> > >
329template<
typename TranspositionsDerived>
330class Transpose<TranspositionsBase<TranspositionsDerived> >
332 typedef TranspositionsDerived TranspositionType;
333 typedef typename TranspositionType::IndicesType IndicesType;
336 explicit Transpose(
const TranspositionType& t) : m_transpositions(t) {}
338 Index size()
const {
return m_transpositions.size(); }
339 Index rows()
const {
return m_transpositions.size(); }
340 Index cols()
const {
return m_transpositions.size(); }
344 template<
typename OtherDerived>
friend
345 const Product<OtherDerived, Transpose, AliasFreeProduct>
346 operator*(
const MatrixBase<OtherDerived>& matrix,
const Transpose& trt)
348 return Product<OtherDerived, Transpose, AliasFreeProduct>(matrix.derived(), trt);
353 template<
typename OtherDerived>
354 const Product<Transpose, OtherDerived, AliasFreeProduct>
355 operator*(
const MatrixBase<OtherDerived>& matrix)
const
357 return Product<Transpose, OtherDerived, AliasFreeProduct>(*
this, matrix.derived());
360 const TranspositionType&
nestedExpression()
const {
return m_transpositions; }
363 const TranspositionType& m_transpositions;
A matrix or vector expression mapping an existing array of data.
Definition Map.h:96
Map(PointerArgType dataPtr, const StrideType &stride=StrideType())
Definition Map.h:129
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Expression of the product of two arbitrary matrices or vectors.
Definition Product.h:75
Expression of the transpose of a matrix.
Definition Transpose.h:54
const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition Transpose.h:74
Represents a sequence of transpositions (row/column interchange)
Definition Transpositions.h:148
Transpositions(const MatrixBase< Other > &indices)
Definition Transpositions.h:165
IndicesType & indices()
Definition Transpositions.h:183
const IndicesType & indices() const
Definition Transpositions.h:181
Transpositions(Index size)
Definition Transpositions.h:177
Transpositions & operator=(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:170
Transpositions(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:160
Namespace containing all symbols from the Eigen library.
Definition A05_PortingFrom2To3.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:65
const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition PermutationMatrix.h:515