11 #ifndef EIGEN_TRANSPOSE_H
12 #define EIGEN_TRANSPOSE_H
31 template<
typename MatrixType>
32 struct traits<Transpose<MatrixType> > : traits<MatrixType>
34 typedef typename MatrixType::Scalar Scalar;
35 typedef typename nested<MatrixType>::type MatrixTypeNested;
36 typedef typename remove_reference<MatrixTypeNested>::type MatrixTypeNestedPlain;
37 typedef typename traits<MatrixType>::StorageKind StorageKind;
38 typedef typename traits<MatrixType>::XprKind XprKind;
40 RowsAtCompileTime = MatrixType::ColsAtCompileTime,
41 ColsAtCompileTime = MatrixType::RowsAtCompileTime,
42 MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime,
43 MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
44 FlagsLvalueBit = is_lvalue<MatrixType>::value ?
LvalueBit : 0,
45 Flags0 = MatrixTypeNestedPlain::Flags & ~(
LvalueBit | NestByRefBit),
46 Flags1 = Flags0 | FlagsLvalueBit,
48 CoeffReadCost = MatrixTypeNestedPlain::CoeffReadCost,
49 InnerStrideAtCompileTime = inner_stride_at_compile_time<MatrixType>::ret,
50 OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret
55 template<
typename MatrixType,
typename StorageKind>
class TransposeImpl;
58 :
public TransposeImpl<MatrixType,typename internal::traits<MatrixType>::StorageKind>
62 typedef typename TransposeImpl<MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
65 inline Transpose(MatrixType& a_matrix) : m_matrix(a_matrix) {}
67 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Transpose)
69 inline Index rows()
const {
return m_matrix.cols(); }
70 inline Index cols()
const {
return m_matrix.rows(); }
73 const typename internal::remove_all<typename MatrixType::Nested>::type&
77 typename internal::remove_all<typename MatrixType::Nested>::type&
81 typename MatrixType::Nested m_matrix;
86 template<typename MatrixType, bool HasDirectAccess = has_direct_access<MatrixType>::ret>
87 struct TransposeImpl_base
89 typedef typename dense_xpr_base<Transpose<MatrixType> >::type type;
92 template<
typename MatrixType>
93 struct TransposeImpl_base<MatrixType, false>
95 typedef typename dense_xpr_base<Transpose<MatrixType> >::type type;
100 template<
typename MatrixType>
class TransposeImpl<MatrixType,Dense>
101 :
public internal::TransposeImpl_base<MatrixType>::type
105 typedef typename internal::TransposeImpl_base<MatrixType>::type Base;
106 EIGEN_DENSE_PUBLIC_INTERFACE(Transpose<MatrixType>)
107 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TransposeImpl)
109 inline Index innerStride()
const {
return derived().nestedExpression().innerStride(); }
110 inline Index outerStride()
const {
return derived().nestedExpression().outerStride(); }
112 typedef typename internal::conditional<
113 internal::is_lvalue<MatrixType>::value,
116 >::type ScalarWithConstIfNotLvalue;
118 inline ScalarWithConstIfNotLvalue* data() {
return derived().nestedExpression().data(); }
119 inline const Scalar* data()
const {
return derived().nestedExpression().data(); }
121 inline ScalarWithConstIfNotLvalue& coeffRef(Index rowId, Index colId)
123 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
124 return derived().nestedExpression().const_cast_derived().coeffRef(colId, rowId);
127 inline ScalarWithConstIfNotLvalue& coeffRef(Index index)
129 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
130 return derived().nestedExpression().const_cast_derived().coeffRef(index);
133 inline const Scalar& coeffRef(Index rowId, Index colId)
const
135 return derived().nestedExpression().coeffRef(colId, rowId);
138 inline const Scalar& coeffRef(Index index)
const
140 return derived().nestedExpression().coeffRef(index);
143 inline CoeffReturnType coeff(Index rowId, Index colId)
const
145 return derived().nestedExpression().coeff(colId, rowId);
148 inline CoeffReturnType coeff(Index index)
const
150 return derived().nestedExpression().coeff(index);
153 template<
int LoadMode>
154 inline const PacketScalar packet(Index rowId, Index colId)
const
156 return derived().nestedExpression().template packet<LoadMode>(colId, rowId);
159 template<
int LoadMode>
160 inline void writePacket(Index rowId, Index colId,
const PacketScalar& x)
162 derived().nestedExpression().const_cast_derived().template writePacket<LoadMode>(colId, rowId, x);
165 template<
int LoadMode>
166 inline const PacketScalar packet(Index index)
const
168 return derived().nestedExpression().template packet<LoadMode>(index);
171 template<
int LoadMode>
172 inline void writePacket(Index index,
const PacketScalar& x)
174 derived().nestedExpression().const_cast_derived().template writePacket<LoadMode>(index, x);
197 template<
typename Derived>
198 inline Transpose<Derived>
209 template<
typename Derived>
235 template<
typename Derived>
239 return this->transpose();
249 template<
typename MatrixType,
250 bool IsSquare = (MatrixType::RowsAtCompileTime == MatrixType::ColsAtCompileTime) && MatrixType::RowsAtCompileTime!=
Dynamic>
251 struct inplace_transpose_selector;
253 template<
typename MatrixType>
254 struct inplace_transpose_selector<MatrixType,true> {
255 static void run(MatrixType& m) {
256 m.matrix().template triangularView<StrictlyUpper>().swap(m.matrix().transpose());
260 template<
typename MatrixType>
261 struct inplace_transpose_selector<MatrixType,false> {
262 static void run(MatrixType& m) {
263 if (m.rows()==m.cols())
264 m.matrix().template triangularView<StrictlyUpper>().swap(m.matrix().transpose());
266 m = m.transpose().eval();
290 template<
typename Derived>
293 eigen_assert((rows() == cols() || (RowsAtCompileTime ==
Dynamic && ColsAtCompileTime ==
Dynamic))
294 &&
"transposeInPlace() called on a non-square non-resizable matrix");
295 internal::inplace_transpose_selector<Derived>::run(derived());
320 template<
typename Derived>
323 derived() = adjoint().
eval();
326 #ifndef EIGEN_NO_DEBUG
332 template<
typename BinOp,
typename NestedXpr,
typename Rhs>
333 struct blas_traits<SelfCwiseBinaryOp<BinOp,NestedXpr,Rhs> >
334 : blas_traits<NestedXpr>
336 typedef SelfCwiseBinaryOp<BinOp,NestedXpr,Rhs> XprType;
337 static inline const XprType extract(
const XprType& x) {
return x; }
340 template<
bool DestIsTransposed,
typename OtherDerived>
341 struct check_transpose_aliasing_compile_time_selector
343 enum { ret = bool(blas_traits<OtherDerived>::IsTransposed) != DestIsTransposed };
346 template<
bool DestIsTransposed,
typename BinOp,
typename DerivedA,
typename DerivedB>
347 struct check_transpose_aliasing_compile_time_selector<DestIsTransposed,CwiseBinaryOp<BinOp,DerivedA,DerivedB> >
349 enum { ret = bool(blas_traits<DerivedA>::IsTransposed) != DestIsTransposed
350 || bool(blas_traits<DerivedB>::IsTransposed) != DestIsTransposed
354 template<
typename Scalar,
bool DestIsTransposed,
typename OtherDerived>
355 struct check_transpose_aliasing_run_time_selector
357 static bool run(
const Scalar* dest,
const OtherDerived& src)
359 return (
bool(blas_traits<OtherDerived>::IsTransposed) != DestIsTransposed) && (dest!=0 && dest==(
const Scalar*)extract_data(src));
363 template<
typename Scalar,
bool DestIsTransposed,
typename BinOp,
typename DerivedA,
typename DerivedB>
364 struct check_transpose_aliasing_run_time_selector<Scalar,DestIsTransposed,CwiseBinaryOp<BinOp,DerivedA,DerivedB> >
366 static bool run(
const Scalar* dest,
const CwiseBinaryOp<BinOp,DerivedA,DerivedB>& src)
368 return ((blas_traits<DerivedA>::IsTransposed != DestIsTransposed) && (dest!=0 && dest==(
const Scalar*)extract_data(src.lhs())))
369 || ((blas_traits<DerivedB>::IsTransposed != DestIsTransposed) && (dest!=0 && dest==(
const Scalar*)extract_data(src.rhs())));
379 template<
typename Derived,
typename OtherDerived,
380 bool MightHaveTransposeAliasing
381 = check_transpose_aliasing_compile_time_selector
382 <blas_traits<Derived>::IsTransposed,OtherDerived>::ret
384 struct checkTransposeAliasing_impl
386 static void run(
const Derived& dst,
const OtherDerived& other)
388 eigen_assert((!check_transpose_aliasing_run_time_selector
389 <
typename Derived::Scalar,blas_traits<Derived>::IsTransposed,OtherDerived>
390 ::run(extract_data(dst), other))
391 &&
"aliasing detected during transposition, use transposeInPlace() "
392 "or evaluate the rhs into a temporary using .eval()");
397 template<
typename Derived,
typename OtherDerived>
398 struct checkTransposeAliasing_impl<Derived, OtherDerived, false>
400 static void run(
const Derived&,
const OtherDerived&)
407 template<
typename Derived>
408 template<
typename OtherDerived>
409 void DenseBase<Derived>::checkTransposeAliasing(
const OtherDerived& other)
const
411 internal::checkTransposeAliasing_impl<Derived, OtherDerived>::run(derived(), other);
417 #endif // EIGEN_TRANSPOSE_H