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 (Index i = 0; i < indices().size(); ++i) coeffRef(i) = internal::convert_index<StorageIndex>(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;
158template <
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_>
160 :
public TranspositionsBase<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> > {
161 using Traits = internal::traits<Transpositions>;
164 using Base = TranspositionsBase<Transpositions>;
165 using IndicesType =
typename Traits::IndicesType;
166 using StorageIndex =
typename IndicesType::Scalar;
168 inline Transpositions() {}
171 template <
typename OtherDerived>
175 template <
typename Other>
179 template <
typename OtherDerived>
180 Transpositions&
operator=(
const TranspositionsBase<OtherDerived>& other) {
181 return Base::operator=(other);
189 EIGEN_DEVICE_FUNC
const IndicesType&
indices()
const {
return m_indices; }
191 EIGEN_DEVICE_FUNC IndicesType&
indices() {
return m_indices; }
194 IndicesType m_indices;
198template <
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_,
int PacketAccess_>
199struct traits<Map<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>, PacketAccess_> >
200 : traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_> > {
201 using IndicesType = Map<const Matrix<StorageIndex_, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>, PacketAccess_>;
202 using StorageIndex = StorageIndex_;
203 using StorageKind = TranspositionsStorage;
207template <
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename StorageIndex_,
int PacketAccess>
208class Map<
Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>, PacketAccess>
209 :
public TranspositionsBase<
210 Map<Transpositions<SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>, PacketAccess> > {
211 using Traits = internal::traits<Map>;
214 using Base = TranspositionsBase<Map>;
215 using IndicesType =
typename Traits::IndicesType;
216 using StorageIndex =
typename IndicesType::Scalar;
218 explicit inline Map(
const StorageIndex* indicesPtr) : m_indices(indicesPtr) {}
220 inline Map(
const StorageIndex* indicesPtr, Index size) : m_indices(indicesPtr, size) {}
223 template <
typename OtherDerived>
224 Map& operator=(
const TranspositionsBase<OtherDerived>& other) {
225 return Base::operator=(other);
228#ifndef EIGEN_PARSED_BY_DOXYGEN
232 Map& operator=(
const Map& other) {
233 m_indices = other.m_indices;
239 EIGEN_DEVICE_FUNC
const IndicesType& indices()
const {
return m_indices; }
242 EIGEN_DEVICE_FUNC IndicesType& indices() {
return m_indices; }
245 IndicesType m_indices;
249template <
typename IndicesType_>
250struct traits<TranspositionsWrapper<IndicesType_> > : traits<PermutationWrapper<IndicesType_> > {
251 using StorageKind = TranspositionsStorage;
255template <
typename IndicesType_>
256class TranspositionsWrapper :
public TranspositionsBase<TranspositionsWrapper<IndicesType_> > {
257 using Traits = internal::traits<TranspositionsWrapper>;
260 using Base = TranspositionsBase<TranspositionsWrapper>;
261 using IndicesType =
typename Traits::IndicesType;
262 using StorageIndex =
typename IndicesType::Scalar;
264 explicit inline TranspositionsWrapper(IndicesType& indices) : m_indices(indices) {}
267 template <
typename OtherDerived>
268 TranspositionsWrapper& operator=(
const TranspositionsBase<OtherDerived>& other) {
269 return Base::operator=(other);
273 EIGEN_DEVICE_FUNC
const IndicesType& indices()
const {
return m_indices; }
276 EIGEN_DEVICE_FUNC IndicesType& indices() {
return m_indices; }
279 typename IndicesType::Nested m_indices;
284template <
typename MatrixDerived,
typename TranspositionsDerived>
292template <
typename TranspositionsDerived,
typename MatrixDerived>
302template <
typename Derived>
303struct traits<Transpose<TranspositionsBase<Derived> > > : traits<Derived> {};
307template <
typename TranspositionsDerived>
308class Transpose<TranspositionsBase<TranspositionsDerived> > {
309 using TranspositionType = TranspositionsDerived;
310 using IndicesType =
typename TranspositionType::IndicesType;
313 explicit Transpose(
const TranspositionType& t) : m_transpositions(t) {}
315 EIGEN_DEVICE_FUNC
constexpr Index size() const noexcept {
return m_transpositions.size(); }
316 EIGEN_DEVICE_FUNC
constexpr Index rows() const noexcept {
return m_transpositions.size(); }
317 EIGEN_DEVICE_FUNC
constexpr Index cols() const noexcept {
return m_transpositions.size(); }
321 template <
typename OtherDerived>
322 friend const Product<OtherDerived, Transpose, AliasFreeProduct> operator*(
const MatrixBase<OtherDerived>& matrix,
323 const Transpose& trt) {
324 return Product<OtherDerived, Transpose, AliasFreeProduct>(matrix.derived(), trt);
329 template <
typename OtherDerived>
330 const Product<Transpose, OtherDerived, AliasFreeProduct> operator*(
const MatrixBase<OtherDerived>& matrix)
const {
331 return Product<Transpose, OtherDerived, AliasFreeProduct>(*
this, matrix.derived());
334 EIGEN_DEVICE_FUNC
const TranspositionType&
nestedExpression()
const {
return m_transpositions; }
337 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:225
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:160
Transpositions(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:172
const IndicesType & indices() const
Definition Transpositions.h:189
Transpositions & operator=(const TranspositionsBase< OtherDerived > &other)
Definition Transpositions.h:180
IndicesType & indices()
Definition Transpositions.h:191
Transpositions(Index size)
Definition Transpositions.h:186
Transpositions(const MatrixBase< Other > &indices)
Definition Transpositions.h:176