10#ifndef EIGEN_TRANSPOSITIONS_H
11#define EIGEN_TRANSPOSITIONS_H
14#include "./InternalHeaderCheck.h"
18template <
typename Derived>
19class TranspositionsBase {
20 typedef internal::traits<Derived> Traits;
23 typedef typename Traits::IndicesType IndicesType;
24 typedef typename IndicesType::Scalar StorageIndex;
27 EIGEN_DEVICE_FUNC Derived& derived() {
return *
static_cast<Derived*
>(
this); }
28 EIGEN_DEVICE_FUNC
const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
31 template <
typename OtherDerived>
32 Derived& operator=(
const TranspositionsBase<OtherDerived>& other) {
33 indices() = other.indices();
38 EIGEN_DEVICE_FUNC Index size()
const {
return indices().size(); }
40 EIGEN_DEVICE_FUNC Index rows()
const {
return indices().size(); }
42 EIGEN_DEVICE_FUNC Index cols()
const {
return indices().size(); }
45 EIGEN_DEVICE_FUNC
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 EIGEN_DEVICE_FUNC
const IndicesType& indices()
const {
return derived().indices(); }
60 EIGEN_DEVICE_FUNC IndicesType& indices() {
return derived().indices(); }
63 inline void resize(Index newSize) { indices().resize(newSize); }
67 for (StorageIndex i = 0; i < indices().size(); ++i) coeffRef(i) = i;
92 inline Transpose<TranspositionsBase> inverse()
const {
return Transpose<TranspositionsBase>(derived()); }
95 inline Transpose<TranspositionsBase> transpose()
const {
return Transpose<TranspositionsBase>(derived()); }
101template <
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_>
102struct traits<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> >
103 : traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> > {
104 typedef Matrix<StorageIndex_, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
105 typedef TranspositionsStorage StorageKind;
139template <
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_>
141 :
public TranspositionsBase<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> > {
142 typedef internal::traits<Transpositions> Traits;
145 typedef TranspositionsBase<Transpositions> Base;
146 typedef typename Traits::IndicesType IndicesType;
147 typedef typename IndicesType::Scalar StorageIndex;
152 template <
typename OtherDerived>
156 template <
typename Other>
160 template <
typename OtherDerived>
162 return Base::operator=(other);
170 EIGEN_DEVICE_FUNC
const IndicesType&
indices()
const {
return m_indices; }
172 EIGEN_DEVICE_FUNC IndicesType&
indices() {
return m_indices; }
175 IndicesType m_indices;
179template <
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_,
int PacketAccess_>
180struct traits<Map<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>, PacketAccess_> >
181 : traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> > {
182 typedef Map<const Matrix<StorageIndex_, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>, PacketAccess_> IndicesType;
183 typedef StorageIndex_ StorageIndex;
184 typedef TranspositionsStorage StorageKind;
188template <
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_,
int PacketAccess>
189class Map<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>, PacketAccess>
190 :
public TranspositionsBase<
191 Map<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>, PacketAccess> > {
192 typedef internal::traits<Map> Traits;
195 typedef TranspositionsBase<Map> Base;
196 typedef typename Traits::IndicesType IndicesType;
197 typedef typename IndicesType::Scalar StorageIndex;
199 explicit inline Map(
const StorageIndex* indicesPtr) : m_indices(indicesPtr) {}
201 inline Map(
const StorageIndex* indicesPtr, Index size) : m_indices(indicesPtr, size) {}
204 template <
typename OtherDerived>
205 Map& operator=(
const TranspositionsBase<OtherDerived>& other) {
206 return Base::operator=(other);
209#ifndef EIGEN_PARSED_BY_DOXYGEN
213 Map& operator=(
const Map& other) {
214 m_indices = other.m_indices;
220 EIGEN_DEVICE_FUNC
const IndicesType& indices()
const {
return m_indices; }
223 EIGEN_DEVICE_FUNC IndicesType& indices() {
return m_indices; }
226 IndicesType m_indices;
230template <
typename IndicesType_>
231struct traits<TranspositionsWrapper<IndicesType_> > : traits<PermutationWrapper<IndicesType_> > {
232 typedef TranspositionsStorage StorageKind;
236template <
typename IndicesType_>
237class TranspositionsWrapper :
public TranspositionsBase<TranspositionsWrapper<IndicesType_> > {
238 typedef internal::traits<TranspositionsWrapper> Traits;
241 typedef TranspositionsBase<TranspositionsWrapper> Base;
242 typedef typename Traits::IndicesType IndicesType;
243 typedef typename IndicesType::Scalar StorageIndex;
245 explicit inline TranspositionsWrapper(IndicesType& indices) : m_indices(indices) {}
248 template <
typename OtherDerived>
249 TranspositionsWrapper& operator=(
const TranspositionsBase<OtherDerived>& other) {
250 return Base::operator=(other);
254 EIGEN_DEVICE_FUNC
const IndicesType& indices()
const {
return m_indices; }
257 EIGEN_DEVICE_FUNC IndicesType& indices() {
return m_indices; }
260 typename IndicesType::Nested m_indices;
265template <
typename MatrixDerived,
typename TranspositionsDerived>
273template <
typename TranspositionsDerived,
typename MatrixDerived>
283template <
typename Derived>
284struct traits<Transpose<TranspositionsBase<Derived> > > : traits<Derived> {};
288template <
typename TranspositionsDerived>
289class Transpose<TranspositionsBase<TranspositionsDerived> > {
290 typedef TranspositionsDerived TranspositionType;
291 typedef typename TranspositionType::IndicesType IndicesType;
294 explicit Transpose(
const TranspositionType& t) : m_transpositions(t) {}
296 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT {
return m_transpositions.size(); }
297 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT {
return m_transpositions.size(); }
298 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT {
return m_transpositions.size(); }
302 template <
typename OtherDerived>
303 friend const Product<OtherDerived, Transpose, AliasFreeProduct>
operator*(
const MatrixBase<OtherDerived>& matrix,
304 const Transpose& trt) {
305 return Product<OtherDerived, Transpose, AliasFreeProduct>(matrix.derived(), trt);
310 template <
typename OtherDerived>
311 const Product<Transpose, OtherDerived, AliasFreeProduct>
operator*(
const MatrixBase<OtherDerived>& matrix)
const {
312 return Product<Transpose, OtherDerived, AliasFreeProduct>(*
this, matrix.derived());
315 EIGEN_DEVICE_FUNC
const TranspositionType&
nestedExpression()
const {
return m_transpositions; }
318 const TranspositionType& m_transpositions;
Derived & derived()
Definition EigenBase.h:49
Map(PointerArgType dataPtr, const StrideType &stride=StrideType())
Definition Map.h:123
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:202
const internal::remove_all_t< MatrixTypeNested > & nestedExpression() const
Definition Transpose.h:72
Represents a sequence of transpositions (row/column interchange)
Definition Transpositions.h:141
Transpositions(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:153
const IndicesType & indices() const
Definition Transpositions.h:170
Transpositions & operator=(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:161
IndicesType & indices()
Definition Transpositions.h:172
Transpositions(Index size)
Definition Transpositions.h:167
Transpositions(const MatrixBase< Other > &indices)
Definition Transpositions.h:157
Namespace containing all symbols from the Eigen library.
Definition Core:137
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:83
const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition PermutationMatrix.h:471