10#ifndef EIGEN_TRANSPOSITIONS_H
11#define EIGEN_TRANSPOSITIONS_H
13#include "./InternalHeaderCheck.h"
17template<
typename Derived>
18class TranspositionsBase
20 typedef internal::traits<Derived> Traits;
24 typedef typename Traits::IndicesType IndicesType;
25 typedef typename IndicesType::Scalar StorageIndex;
29 Derived& derived() {
return *
static_cast<Derived*
>(
this); }
31 const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
34 template<
typename OtherDerived>
35 Derived& operator=(
const TranspositionsBase<OtherDerived>& other)
37 indices() = other.indices();
43 Index size()
const {
return indices().size(); }
46 Index rows()
const {
return indices().size(); }
49 Index cols()
const {
return indices().size(); }
53 inline const StorageIndex& coeff(
Index i)
const {
return indices().coeff(i); }
55 inline StorageIndex& coeffRef(
Index i) {
return indices().coeffRef(i); }
57 inline const StorageIndex& operator()(
Index i)
const {
return indices()(i); }
59 inline StorageIndex& operator()(
Index i) {
return indices()(i); }
61 inline const StorageIndex& operator[](
Index i)
const {
return indices()(i); }
63 inline StorageIndex& operator[](
Index i) {
return indices()(i); }
67 const IndicesType& indices()
const {
return derived().indices(); }
70 IndicesType& indices() {
return derived().indices(); }
73 inline void resize(
Index newSize)
75 indices().resize(newSize);
81 for(StorageIndex i = 0; i < indices().size(); ++i)
107 inline Transpose<TranspositionsBase>
inverse()
const
108 {
return Transpose<TranspositionsBase>(derived()); }
111 inline Transpose<TranspositionsBase> transpose()
const
112 {
return Transpose<TranspositionsBase>(derived()); }
118template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_>
119struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,StorageIndex_> >
120 : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,StorageIndex_> >
122 typedef Matrix<StorageIndex_, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
123 typedef TranspositionsStorage StorageKind;
156template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_>
157class Transpositions :
public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,StorageIndex_> >
159 typedef internal::traits<Transpositions> Traits;
162 typedef TranspositionsBase<Transpositions> Base;
163 typedef typename Traits::IndicesType IndicesType;
164 typedef typename IndicesType::Scalar StorageIndex;
169 template<
typename OtherDerived>
171 : m_indices(other.
indices()) {}
174 template<
typename Other>
179 template<
typename OtherDerived>
182 return Base::operator=(other);
192 const IndicesType&
indices()
const {
return m_indices; }
199 IndicesType m_indices;
204template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_,
int _PacketAccess>
205struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,StorageIndex_>,_PacketAccess> >
206 : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,StorageIndex_> >
208 typedef Map<const Matrix<StorageIndex_,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1>, _PacketAccess> IndicesType;
209 typedef StorageIndex_ StorageIndex;
210 typedef TranspositionsStorage StorageKind;
214template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_,
int PacketAccess>
215class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,StorageIndex_>,PacketAccess>
216 :
public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,StorageIndex_>,PacketAccess> >
218 typedef internal::traits<Map> Traits;
221 typedef TranspositionsBase<Map> Base;
222 typedef typename Traits::IndicesType IndicesType;
223 typedef typename IndicesType::Scalar StorageIndex;
225 explicit inline Map(
const StorageIndex* indicesPtr)
226 : m_indices(indicesPtr)
229 inline Map(
const StorageIndex* indicesPtr,
Index size)
230 : m_indices(indicesPtr,size)
234 template<
typename OtherDerived>
235 Map& operator=(
const TranspositionsBase<OtherDerived>& other)
237 return Base::operator=(other);
240 #ifndef EIGEN_PARSED_BY_DOXYGEN
244 Map& operator=(
const Map& other)
246 m_indices = other.m_indices;
253 const IndicesType& indices()
const {
return m_indices; }
257 IndicesType& indices() {
return m_indices; }
261 IndicesType m_indices;
265template<
typename IndicesType_>
266struct traits<TranspositionsWrapper<IndicesType_> >
267 : traits<PermutationWrapper<IndicesType_> >
269 typedef TranspositionsStorage StorageKind;
273template<
typename IndicesType_>
274class TranspositionsWrapper
275 :
public TranspositionsBase<TranspositionsWrapper<IndicesType_> >
277 typedef internal::traits<TranspositionsWrapper> Traits;
280 typedef TranspositionsBase<TranspositionsWrapper> Base;
281 typedef typename Traits::IndicesType IndicesType;
282 typedef typename IndicesType::Scalar StorageIndex;
284 explicit inline TranspositionsWrapper(IndicesType& indices)
289 template<
typename OtherDerived>
290 TranspositionsWrapper& operator=(
const TranspositionsBase<OtherDerived>& other)
292 return Base::operator=(other);
297 const IndicesType& indices()
const {
return m_indices; }
301 IndicesType& indices() {
return m_indices; }
305 typename IndicesType::Nested m_indices;
312template<
typename MatrixDerived,
typename TranspositionsDerived>
314const Product<MatrixDerived, TranspositionsDerived, AliasFreeProduct>
316 const TranspositionsBase<TranspositionsDerived>& transpositions)
319 (matrix.
derived(), transpositions.derived());
324template<
typename TranspositionsDerived,
typename MatrixDerived>
326const Product<TranspositionsDerived, MatrixDerived, AliasFreeProduct>
327operator*(
const TranspositionsBase<TranspositionsDerived> &transpositions,
331 (transpositions.derived(), matrix.
derived());
338template<
typename Derived>
339struct traits<Transpose<TranspositionsBase<Derived> > >
345template<
typename TranspositionsDerived>
346class Transpose<TranspositionsBase<TranspositionsDerived> >
348 typedef TranspositionsDerived TranspositionType;
349 typedef typename TranspositionType::IndicesType IndicesType;
352 explicit Transpose(
const TranspositionType& t) : m_transpositions(t) {}
354 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
355 Index size() const EIGEN_NOEXCEPT {
return m_transpositions.size(); }
356 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
357 Index rows() const EIGEN_NOEXCEPT {
return m_transpositions.size(); }
358 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
359 Index cols() const EIGEN_NOEXCEPT {
return m_transpositions.size(); }
363 template<
typename OtherDerived>
friend
364 const Product<OtherDerived, Transpose, AliasFreeProduct>
365 operator*(
const MatrixBase<OtherDerived>& matrix,
const Transpose& trt)
367 return Product<OtherDerived, Transpose, AliasFreeProduct>(matrix.derived(), trt);
372 template<
typename OtherDerived>
373 const Product<Transpose, OtherDerived, AliasFreeProduct>
374 operator*(
const MatrixBase<OtherDerived>& matrix)
const
376 return Product<Transpose, OtherDerived, AliasFreeProduct>(*
this, matrix.derived());
380 const TranspositionType&
nestedExpression()
const {
return m_transpositions; }
383 const TranspositionType& m_transpositions;
Derived & derived()
Definition: EigenBase.h:48
Map(PointerArgType dataPtr, const StrideType &stride=StrideType())
Definition: Map.h:131
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:77
const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition: Transpose.h:78
Represents a sequence of transpositions (row/column interchange)
Definition: Transpositions.h:158
Transpositions(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:170
const IndicesType & indices() const
Definition: Transpositions.h:192
Transpositions & operator=(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:180
IndicesType & indices()
Definition: Transpositions.h:195
Transpositions(Index size)
Definition: Transpositions.h:187
Transpositions(const MatrixBase< Other > &indices)
Definition: Transpositions.h:175
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_inverse_op< typename Derived::Scalar >, const Derived > inverse(const Eigen::ArrayBase< Derived > &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:517