11 #ifndef EIGEN_TRANSPOSE_H 12 #define EIGEN_TRANSPOSE_H 17 template<
typename MatrixType>
18 struct traits<Transpose<MatrixType> > :
public traits<MatrixType>
20 typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
21 typedef typename remove_reference<MatrixTypeNested>::type MatrixTypeNestedPlain;
23 RowsAtCompileTime = MatrixType::ColsAtCompileTime,
24 ColsAtCompileTime = MatrixType::RowsAtCompileTime,
25 MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime,
26 MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
27 FlagsLvalueBit = is_lvalue<MatrixType>::value ?
LvalueBit : 0,
28 Flags0 = traits<MatrixTypeNestedPlain>::Flags & ~(
LvalueBit | NestByRefBit),
29 Flags1 = Flags0 | FlagsLvalueBit,
31 InnerStrideAtCompileTime = inner_stride_at_compile_time<MatrixType>::ret,
32 OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret
37 template<
typename MatrixType,
typename StorageKind>
class TransposeImpl;
53 :
public TransposeImpl<MatrixType,typename internal::traits<MatrixType>::StorageKind>
57 typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested;
59 typedef typename TransposeImpl<MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
61 typedef typename internal::remove_all<MatrixType>::type NestedExpression;
64 explicit inline Transpose(MatrixType& matrix) : m_matrix(matrix) {}
66 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Transpose)
68 EIGEN_DEVICE_FUNC
inline Index rows()
const {
return m_matrix.cols(); }
69 EIGEN_DEVICE_FUNC
inline Index cols()
const {
return m_matrix.rows(); }
73 const typename internal::remove_all<MatrixTypeNested>::type&
78 typename internal::remove_reference<MatrixTypeNested>::type&
83 m_matrix.resize(ncols,nrows);
87 typename internal::ref_selector<MatrixType>::non_const_type m_matrix;
92 template<typename MatrixType, bool HasDirectAccess = has_direct_access<MatrixType>::ret>
93 struct TransposeImpl_base
95 typedef typename dense_xpr_base<Transpose<MatrixType> >::type type;
98 template<
typename MatrixType>
99 struct TransposeImpl_base<MatrixType, false>
101 typedef typename dense_xpr_base<Transpose<MatrixType> >::type type;
107 template<
typename XprType,
typename StorageKind>
109 :
public internal::generic_xpr_base<Transpose<XprType> >::type
112 typedef typename internal::generic_xpr_base<Transpose<XprType> >::type Base;
115 template<
typename MatrixType>
class TransposeImpl<MatrixType,Dense>
116 :
public internal::TransposeImpl_base<MatrixType>::type
120 typedef typename internal::TransposeImpl_base<MatrixType>::type Base;
121 using Base::coeffRef;
123 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TransposeImpl)
125 EIGEN_DEVICE_FUNC
inline Index innerStride()
const {
return derived().nestedExpression().innerStride(); }
126 EIGEN_DEVICE_FUNC
inline Index outerStride()
const {
return derived().nestedExpression().outerStride(); }
128 typedef typename internal::conditional<
129 internal::is_lvalue<MatrixType>::value,
132 >::type ScalarWithConstIfNotLvalue;
134 EIGEN_DEVICE_FUNC
inline ScalarWithConstIfNotLvalue* data() {
return derived().nestedExpression().data(); }
135 EIGEN_DEVICE_FUNC
inline const Scalar* data()
const {
return derived().nestedExpression().data(); }
139 inline const Scalar& coeffRef(
Index rowId,
Index colId)
const 141 return derived().nestedExpression().coeffRef(colId, rowId);
145 inline const Scalar& coeffRef(
Index index)
const 147 return derived().nestedExpression().coeffRef(index);
170 template<
typename Derived>
182 template<
typename Derived>
208 template<
typename Derived>
212 return AdjointReturnType(this->transpose());
221 template<
typename MatrixType,
222 bool IsSquare = (MatrixType::RowsAtCompileTime == MatrixType::ColsAtCompileTime) && MatrixType::RowsAtCompileTime!=
Dynamic,
223 bool MatchPacketSize =
224 (
int(MatrixType::RowsAtCompileTime) == int(internal::packet_traits<typename MatrixType::Scalar>::size))
226 struct inplace_transpose_selector;
228 template<
typename MatrixType>
229 struct inplace_transpose_selector<MatrixType,true,false> {
230 static void run(MatrixType& m) {
231 m.matrix().template triangularView<StrictlyUpper>().swap(m.matrix().transpose());
236 template<
typename MatrixType>
237 struct inplace_transpose_selector<MatrixType,true,true> {
238 static void run(MatrixType& m) {
239 typedef typename MatrixType::Scalar
Scalar;
240 typedef typename internal::packet_traits<typename MatrixType::Scalar>::type Packet;
241 const Index PacketSize = internal::packet_traits<Scalar>::size;
242 const Index Alignment = internal::evaluator<MatrixType>::Alignment;
243 PacketBlock<Packet> A;
244 for (
Index i=0; i<PacketSize; ++i)
245 A.packet[i] = m.template packetByOuterInner<Alignment>(i,0);
246 internal::ptranspose(A);
247 for (
Index i=0; i<PacketSize; ++i)
248 m.template writePacket<Alignment>(m.rowIndexByOuterInner(i,0), m.colIndexByOuterInner(i,0), A.packet[i]);
252 template<
typename MatrixType,
bool MatchPacketSize>
253 struct inplace_transpose_selector<MatrixType,false,MatchPacketSize> {
254 static void run(MatrixType& m) {
255 if (m.rows()==m.cols())
256 m.matrix().template triangularView<StrictlyUpper>().swap(m.matrix().transpose());
258 m = m.transpose().eval();
283 template<
typename Derived>
286 eigen_assert((rows() == cols() || (RowsAtCompileTime ==
Dynamic && ColsAtCompileTime ==
Dynamic))
287 &&
"transposeInPlace() called on a non-square non-resizable matrix");
288 internal::inplace_transpose_selector<Derived>::run(derived());
314 template<
typename Derived>
317 derived() = adjoint().eval();
320 #ifndef EIGEN_NO_DEBUG 326 template<
bool DestIsTransposed,
typename OtherDerived>
327 struct check_transpose_aliasing_compile_time_selector
329 enum { ret = bool(blas_traits<OtherDerived>::IsTransposed) != DestIsTransposed };
332 template<
bool DestIsTransposed,
typename BinOp,
typename DerivedA,
typename DerivedB>
333 struct check_transpose_aliasing_compile_time_selector<DestIsTransposed,CwiseBinaryOp<BinOp,DerivedA,DerivedB> >
335 enum { ret = bool(blas_traits<DerivedA>::IsTransposed) != DestIsTransposed
336 || bool(blas_traits<DerivedB>::IsTransposed) != DestIsTransposed
340 template<
typename Scalar,
bool DestIsTransposed,
typename OtherDerived>
341 struct check_transpose_aliasing_run_time_selector
343 static bool run(
const Scalar* dest,
const OtherDerived& src)
345 return (
bool(blas_traits<OtherDerived>::IsTransposed) != DestIsTransposed) && (dest!=0 && dest==(
const Scalar*)extract_data(src));
349 template<
typename Scalar,
bool DestIsTransposed,
typename BinOp,
typename DerivedA,
typename DerivedB>
350 struct check_transpose_aliasing_run_time_selector<Scalar,DestIsTransposed,CwiseBinaryOp<BinOp,DerivedA,DerivedB> >
354 return ((blas_traits<DerivedA>::IsTransposed != DestIsTransposed) && (dest!=0 && dest==(
const Scalar*)extract_data(src.
lhs())))
355 || ((blas_traits<DerivedB>::IsTransposed != DestIsTransposed) && (dest!=0 && dest==(
const Scalar*)extract_data(src.
rhs())));
365 template<
typename Derived,
typename OtherDerived,
366 bool MightHaveTransposeAliasing
367 = check_transpose_aliasing_compile_time_selector
368 <blas_traits<Derived>::IsTransposed,OtherDerived>::ret
370 struct checkTransposeAliasing_impl
372 static void run(
const Derived& dst,
const OtherDerived& other)
374 eigen_assert((!check_transpose_aliasing_run_time_selector
375 <
typename Derived::Scalar,blas_traits<Derived>::IsTransposed,OtherDerived>
376 ::run(extract_data(dst), other))
377 &&
"aliasing detected during transposition, use transposeInPlace() " 378 "or evaluate the rhs into a temporary using .eval()");
383 template<
typename Derived,
typename OtherDerived>
384 struct checkTransposeAliasing_impl<Derived, OtherDerived, false>
386 static void run(
const Derived&,
const OtherDerived&)
391 template<
typename Dst,
typename Src>
392 void check_for_aliasing(
const Dst &dst,
const Src &src)
394 internal::checkTransposeAliasing_impl<Dst, Src>::run(dst, src);
399 #endif // EIGEN_NO_DEBUG 403 #endif // EIGEN_TRANSPOSE_H internal::remove_reference< MatrixTypeNested >::type & nestedExpression()
Definition: Transpose.h:79
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:66
const _LhsNested & lhs() const
Definition: CwiseBinaryOp.h:132
const AdjointReturnType adjoint() const
Definition: Transpose.h:210
Expression of the transpose of a matrix.
Definition: Transpose.h:52
const unsigned int LvalueBit
Definition: Constants.h:139
Namespace containing all symbols from the Eigen library.
Definition: Core:287
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:38
const unsigned int RowMajorBit
Definition: Constants.h:61
TransposeReturnType transpose()
Definition: Transpose.h:172
const unsigned int PacketAccessBit
Definition: Constants.h:89
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition: Transpose.h:74
void adjointInPlace()
Definition: Transpose.h:315
Definition: Eigen_Colamd.h:50
const int Dynamic
Definition: Constants.h:21
const _RhsNested & rhs() const
Definition: CwiseBinaryOp.h:135
void transposeInPlace()
Definition: Transpose.h:284
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48