10 #ifndef EIGEN_TRANSPOSITIONS_H
11 #define EIGEN_TRANSPOSITIONS_H
15 template<
typename Derived>
16 class 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()); }
116 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex>
117 struct 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;
154 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex>
155 class 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;
202 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex,
int _PacketAccess>
203 struct 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;
212 template<
int SizeAtCompileTime,
int MaxSizeAtCompileTime,
typename _StorageIndex,
int PacketAccess>
213 class 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;
263 template<
typename _IndicesType>
264 struct traits<TranspositionsWrapper<_IndicesType> >
265 : traits<PermutationWrapper<_IndicesType> >
267 typedef TranspositionsStorage StorageKind;
271 template<
typename _IndicesType>
272 class 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;
310 template<
typename MatrixDerived,
typename TranspositionsDerived>
312 const Product<MatrixDerived, TranspositionsDerived, AliasFreeProduct>
314 const TranspositionsBase<TranspositionsDerived>& transpositions)
317 (matrix.
derived(), transpositions.derived());
322 template<
typename TranspositionsDerived,
typename MatrixDerived>
324 const Product<TranspositionsDerived, MatrixDerived, AliasFreeProduct>
325 operator*(
const TranspositionsBase<TranspositionsDerived> &transpositions,
329 (transpositions.derived(), matrix.
derived());
336 template<
typename Derived>
337 struct traits<Transpose<TranspositionsBase<Derived> > >
343 template<
typename TranspositionsDerived>
344 class 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;
386 #endif // EIGEN_TRANSPOSITIONS_H