11#ifndef EIGEN_TRANSPOSITIONS_H
12#define EIGEN_TRANSPOSITIONS_H
15#include "./InternalHeaderCheck.h"
19template <
typename Derived>
20class TranspositionsBase {
21 using Traits = internal::traits<Derived>;
24 using IndicesType =
typename Traits::IndicesType;
25 using StorageIndex =
typename IndicesType::Scalar;
26 using Index = Eigen::Index;
28 EIGEN_DEVICE_FUNC Derived& derived() {
return *
static_cast<Derived*
>(
this); }
29 EIGEN_DEVICE_FUNC
const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
32 template <
typename OtherDerived>
33 Derived& operator=(
const TranspositionsBase<OtherDerived>& other) {
34 indices() = other.indices();
39 EIGEN_DEVICE_FUNC Index size()
const {
return indices().size(); }
41 EIGEN_DEVICE_FUNC Index rows()
const {
return indices().size(); }
43 EIGEN_DEVICE_FUNC Index cols()
const {
return indices().size(); }
46 EIGEN_DEVICE_FUNC
inline const StorageIndex& coeff(Index i)
const {
return indices().coeff(i); }
48 inline StorageIndex& coeffRef(Index i) {
return indices().coeffRef(i); }
50 inline const StorageIndex& operator()(Index i)
const {
return indices()(i); }
52 inline StorageIndex& operator()(Index i) {
return indices()(i); }
54 inline const StorageIndex& operator[](Index i)
const {
return indices()(i); }
56 inline StorageIndex& operator[](Index i) {
return indices()(i); }
59 EIGEN_DEVICE_FUNC
const IndicesType& indices()
const {
return derived().indices(); }
61 EIGEN_DEVICE_FUNC IndicesType& indices() {
return derived().indices(); }
64 inline void resize(Index newSize) { indices().resize(newSize); }
68 for (StorageIndex i = 0; i < indices().size(); ++i) coeffRef(i) = i;
93 inline Transpose<TranspositionsBase> inverse()
const {
return Transpose<TranspositionsBase>(derived()); }
96 inline Transpose<TranspositionsBase> transpose()
const {
return Transpose<TranspositionsBase>(derived()); }
100 Transpose<TranspositionsBase> adjoint()
const {
return Transpose<TranspositionsBase>(derived()); }
104template <
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_>
105struct traits<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> >
106 : traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> > {
107 using IndicesType = Matrix<StorageIndex_, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>;
108 using StorageKind = TranspositionsStorage;
142template <
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_>
144 :
public TranspositionsBase<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> > {
145 using Traits = internal::traits<Transpositions>;
148 using Base = TranspositionsBase<Transpositions>;
149 using IndicesType =
typename Traits::IndicesType;
150 using StorageIndex =
typename IndicesType::Scalar;
152 inline Transpositions() {}
155 template <
typename OtherDerived>
159 template <
typename Other>
163 template <
typename OtherDerived>
164 Transpositions&
operator=(
const TranspositionsBase<OtherDerived>& other) {
165 return Base::operator=(other);
173 EIGEN_DEVICE_FUNC
const IndicesType&
indices()
const {
return m_indices; }
175 EIGEN_DEVICE_FUNC IndicesType&
indices() {
return m_indices; }
178 IndicesType m_indices;
182template <
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_,
int PacketAccess_>
183struct traits<Map<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>, PacketAccess_> >
184 : traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> > {
185 using IndicesType = Map<const Matrix<StorageIndex_, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>, PacketAccess_>;
186 using StorageIndex = StorageIndex_;
187 using StorageKind = TranspositionsStorage;
191template <
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_,
int PacketAccess>
192class Map<
Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>, PacketAccess>
193 :
public TranspositionsBase<
194 Map<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>, PacketAccess> > {
195 using Traits = internal::traits<Map>;
198 using Base = TranspositionsBase<Map>;
199 using IndicesType =
typename Traits::IndicesType;
200 using StorageIndex =
typename IndicesType::Scalar;
202 explicit inline Map(
const StorageIndex* indicesPtr) : m_indices(indicesPtr) {}
204 inline Map(
const StorageIndex* indicesPtr, Index size) : m_indices(indicesPtr, size) {}
207 template <
typename OtherDerived>
208 Map& operator=(
const TranspositionsBase<OtherDerived>& other) {
209 return Base::operator=(other);
212#ifndef EIGEN_PARSED_BY_DOXYGEN
216 Map& operator=(
const Map& other) {
217 m_indices = other.m_indices;
223 EIGEN_DEVICE_FUNC
const IndicesType& indices()
const {
return m_indices; }
226 EIGEN_DEVICE_FUNC IndicesType& indices() {
return m_indices; }
229 IndicesType m_indices;
233template <
typename IndicesType_>
234struct traits<TranspositionsWrapper<IndicesType_> > : traits<PermutationWrapper<IndicesType_> > {
235 using StorageKind = TranspositionsStorage;
239template <
typename IndicesType_>
240class TranspositionsWrapper :
public TranspositionsBase<TranspositionsWrapper<IndicesType_> > {
241 using Traits = internal::traits<TranspositionsWrapper>;
244 using Base = TranspositionsBase<TranspositionsWrapper>;
245 using IndicesType =
typename Traits::IndicesType;
246 using StorageIndex =
typename IndicesType::Scalar;
248 explicit inline TranspositionsWrapper(IndicesType& indices) : m_indices(indices) {}
251 template <
typename OtherDerived>
252 TranspositionsWrapper& operator=(
const TranspositionsBase<OtherDerived>& other) {
253 return Base::operator=(other);
257 EIGEN_DEVICE_FUNC
const IndicesType& indices()
const {
return m_indices; }
260 EIGEN_DEVICE_FUNC IndicesType& indices() {
return m_indices; }
263 typename IndicesType::Nested m_indices;
268template <
typename MatrixDerived,
typename TranspositionsDerived>
276template <
typename TranspositionsDerived,
typename MatrixDerived>
286template <
typename Derived>
287struct traits<Transpose<TranspositionsBase<Derived> > > : traits<Derived> {};
291template <
typename TranspositionsDerived>
292class Transpose<TranspositionsBase<TranspositionsDerived> > {
293 using TranspositionType = TranspositionsDerived;
294 using IndicesType =
typename TranspositionType::IndicesType;
297 explicit Transpose(
const TranspositionType& t) : m_transpositions(t) {}
299 EIGEN_DEVICE_FUNC
constexpr Index size() const noexcept {
return m_transpositions.size(); }
300 EIGEN_DEVICE_FUNC
constexpr Index rows() const noexcept {
return m_transpositions.size(); }
301 EIGEN_DEVICE_FUNC
constexpr Index cols() const noexcept {
return m_transpositions.size(); }
305 template <
typename OtherDerived>
306 friend const Product<OtherDerived, Transpose, AliasFreeProduct> operator*(
const MatrixBase<OtherDerived>& matrix,
307 const Transpose& trt) {
308 return Product<OtherDerived, Transpose, AliasFreeProduct>(matrix.derived(), trt);
313 template <
typename OtherDerived>
314 const Product<Transpose, OtherDerived, AliasFreeProduct> operator*(
const MatrixBase<OtherDerived>& matrix)
const {
315 return Product<Transpose, OtherDerived, AliasFreeProduct>(*
this, matrix.derived());
318 EIGEN_DEVICE_FUNC
const TranspositionType&
nestedExpression()
const {
return m_transpositions; }
321 const TranspositionType& m_transpositions;
A matrix or vector expression mapping an existing array of data.
Definition Map.h:97
constexpr Map(PointerArgType dataPtr, const StrideType &stride=StrideType())
Definition Map.h:124
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
Expression of the product of two arbitrary matrices or vectors.
Definition Product.h:203
Expression of the transpose of a matrix.
Definition Transpose.h:57
constexpr const internal::remove_all_t< MatrixTypeNested > & nestedExpression() const
Definition Transpose.h:73
Represents a sequence of transpositions (row/column interchange)
Definition Transpositions.h:144
Transpositions(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:156
const IndicesType & indices() const
Definition Transpositions.h:173
Transpositions & operator=(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:164
IndicesType & indices()
Definition Transpositions.h:175
Transpositions(Index size)
Definition Transpositions.h:170
Transpositions(const MatrixBase< Other > &indices)
Definition Transpositions.h:160