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;
27 Derived& derived() {
return *
static_cast<Derived*
>(
this); }
29 const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
32 template<
typename OtherDerived>
33 Derived& operator=(
const TranspositionsBase<OtherDerived>& other)
35 indices() = other.indices();
41 Index size()
const {
return indices().size(); }
44 Index rows()
const {
return indices().size(); }
47 Index cols()
const {
return indices().size(); }
51 inline const StorageIndex& coeff(Index i)
const {
return indices().coeff(i); }
53 inline StorageIndex& coeffRef(Index i) {
return indices().coeffRef(i); }
55 inline const StorageIndex& operator()(Index i)
const {
return indices()(i); }
57 inline StorageIndex& operator()(Index i) {
return indices()(i); }
59 inline const StorageIndex& operator[](Index i)
const {
return indices()(i); }
61 inline StorageIndex& operator[](Index i) {
return indices()(i); }
65 const IndicesType& indices()
const {
return derived().indices(); }
68 IndicesType& indices() {
return derived().indices(); }
71 inline void resize(Index newSize)
73 indices().resize(newSize);
79 for(StorageIndex i = 0; i < indices().size(); ++i)
105 inline Transpose<TranspositionsBase>
inverse()
const
106 {
return Transpose<TranspositionsBase>(derived()); }
109 inline Transpose<TranspositionsBase> transpose()
const
110 {
return Transpose<TranspositionsBase>(derived()); }
116template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex>
117struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
118 : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
120 typedef Matrix<_StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
121 typedef TranspositionsStorage StorageKind;
154template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex>
155class Transpositions :
public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
157 typedef internal::traits<Transpositions> Traits;
160 typedef TranspositionsBase<Transpositions> Base;
161 typedef typename Traits::IndicesType IndicesType;
162 typedef typename IndicesType::Scalar StorageIndex;
167 template<
typename OtherDerived>
169 : m_indices(other.
indices()) {}
172 template<
typename Other>
177 template<
typename OtherDerived>
180 return Base::operator=(other);
190 const IndicesType&
indices()
const {
return m_indices; }
197 IndicesType m_indices;
202template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex,
int _PacketAccess>
203struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,_PacketAccess> >
204 : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
206 typedef Map<const Matrix<_StorageIndex,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1>, _PacketAccess> IndicesType;
207 typedef _StorageIndex StorageIndex;
208 typedef TranspositionsStorage StorageKind;
212template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex,
int PacketAccess>
213class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,PacketAccess>
214 :
public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,PacketAccess> >
216 typedef internal::traits<Map> Traits;
219 typedef TranspositionsBase<Map> Base;
220 typedef typename Traits::IndicesType IndicesType;
221 typedef typename IndicesType::Scalar StorageIndex;
223 explicit inline Map(
const StorageIndex* indicesPtr)
224 : m_indices(indicesPtr)
227 inline Map(
const StorageIndex* indicesPtr,
Index size)
228 : m_indices(indicesPtr,size)
232 template<
typename OtherDerived>
233 Map& operator=(
const TranspositionsBase<OtherDerived>& other)
235 return Base::operator=(other);
238 #ifndef EIGEN_PARSED_BY_DOXYGEN
242 Map& operator=(
const Map& other)
244 m_indices = other.m_indices;
251 const IndicesType& indices()
const {
return m_indices; }
255 IndicesType& indices() {
return m_indices; }
259 IndicesType m_indices;
263template<
typename _IndicesType>
264struct traits<TranspositionsWrapper<_IndicesType> >
265 : traits<PermutationWrapper<_IndicesType> >
267 typedef TranspositionsStorage StorageKind;
271template<
typename _IndicesType>
272class TranspositionsWrapper
273 :
public TranspositionsBase<TranspositionsWrapper<_IndicesType> >
275 typedef internal::traits<TranspositionsWrapper> Traits;
278 typedef TranspositionsBase<TranspositionsWrapper> Base;
279 typedef typename Traits::IndicesType IndicesType;
280 typedef typename IndicesType::Scalar StorageIndex;
282 explicit inline TranspositionsWrapper(IndicesType& indices)
287 template<
typename OtherDerived>
288 TranspositionsWrapper& operator=(
const TranspositionsBase<OtherDerived>& other)
290 return Base::operator=(other);
295 const IndicesType& indices()
const {
return m_indices; }
299 IndicesType& indices() {
return m_indices; }
303 typename IndicesType::Nested m_indices;
310template<
typename MatrixDerived,
typename TranspositionsDerived>
312const Product<MatrixDerived, TranspositionsDerived, AliasFreeProduct>
314 const TranspositionsBase<TranspositionsDerived>& transpositions)
317 (matrix.
derived(), transpositions.derived());
322template<
typename TranspositionsDerived,
typename MatrixDerived>
324const Product<TranspositionsDerived, MatrixDerived, AliasFreeProduct>
325operator*(
const TranspositionsBase<TranspositionsDerived> &transpositions,
329 (transpositions.derived(), matrix.
derived());
336template<
typename Derived>
337struct traits<Transpose<TranspositionsBase<Derived> > >
343template<
typename TranspositionsDerived>
344class Transpose<TranspositionsBase<TranspositionsDerived> >
346 typedef TranspositionsDerived TranspositionType;
347 typedef typename TranspositionType::IndicesType IndicesType;
350 explicit Transpose(
const TranspositionType& t) : m_transpositions(t) {}
352 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
353 Index size() const EIGEN_NOEXCEPT {
return m_transpositions.size(); }
354 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
355 Index rows() const EIGEN_NOEXCEPT {
return m_transpositions.size(); }
356 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
357 Index cols() const EIGEN_NOEXCEPT {
return m_transpositions.size(); }
361 template<
typename OtherDerived>
friend
362 const Product<OtherDerived, Transpose, AliasFreeProduct>
363 operator*(
const MatrixBase<OtherDerived>& matrix,
const Transpose& trt)
365 return Product<OtherDerived, Transpose, AliasFreeProduct>(matrix.derived(), trt);
370 template<
typename OtherDerived>
371 const Product<Transpose, OtherDerived, AliasFreeProduct>
372 operator*(
const MatrixBase<OtherDerived>& matrix)
const
374 return Product<Transpose, OtherDerived, AliasFreeProduct>(*
this, matrix.derived());
378 const TranspositionType&
nestedExpression()
const {
return m_transpositions; }
381 const TranspositionType& m_transpositions;
Derived & derived()
Definition: EigenBase.h:46
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
const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition: Transpose.h:76
Represents a sequence of transpositions (row/column interchange)
Definition: Transpositions.h:156
Transpositions(const MatrixBase< Other > &indices)
Definition: Transpositions.h:173
IndicesType & indices()
Definition: Transpositions.h:193
const IndicesType & indices() const
Definition: Transpositions.h:190
Transpositions(Index size)
Definition: Transpositions.h:185
Transpositions & operator=(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:178
Transpositions(const TranspositionsBase< OtherDerived > &other)
Definition: Transpositions.h:168
Namespace containing all symbols from the Eigen library.
Definition: Core:141
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:74
const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:515