11 #ifndef EIGEN_TRANSPOSE_H
12 #define EIGEN_TRANSPOSE_H
19 template<
typename MatrixType>
20 struct traits<Transpose<
MatrixType> > :
public traits<MatrixType>
22 typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
23 typedef std::remove_reference_t<MatrixTypeNested> MatrixTypeNestedPlain;
25 RowsAtCompileTime = MatrixType::ColsAtCompileTime,
26 ColsAtCompileTime = MatrixType::RowsAtCompileTime,
27 MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime,
28 MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
29 FlagsLvalueBit = is_lvalue<MatrixType>::value ?
LvalueBit : 0,
31 Flags1 = Flags0 | FlagsLvalueBit,
33 InnerStrideAtCompileTime = inner_stride_at_compile_time<MatrixType>::ret,
34 OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret
39 template<
typename MatrixType,
typename StorageKind>
class TransposeImpl;
55 :
public TransposeImpl<MatrixType,typename internal::traits<MatrixType>::StorageKind>
82 std::remove_reference_t<MatrixTypeNested>&
92 typename internal::ref_selector<MatrixType>::non_const_type
m_matrix;
97 template<typename MatrixType, bool HasDirectAccess = has_direct_access<MatrixType>::ret>
98 struct TransposeImpl_base
100 typedef typename dense_xpr_base<Transpose<MatrixType> >::type type;
103 template<
typename MatrixType>
106 typedef typename dense_xpr_base<Transpose<MatrixType> >::type type;
112 template<
typename XprType,
typename StorageKind>
114 :
public internal::generic_xpr_base<Transpose<XprType> >::type
117 typedef typename internal::generic_xpr_base<Transpose<XprType> >::type
Base;
121 :
public internal::TransposeImpl_base<MatrixType>::type
125 typedef typename internal::TransposeImpl_base<MatrixType>::type
Base;
126 using Base::coeffRef;
135 typedef std::conditional_t<
136 internal::is_lvalue<MatrixType>::value,
144 const Scalar*
data()
const {
return derived().nestedExpression().data(); }
150 return derived().nestedExpression().coeffRef(colId, rowId);
156 return derived().nestedExpression().coeffRef(index);
181 template<
typename Derived>
194 template<
typename Derived>
221 template<
typename Derived>
225 return AdjointReturnType(this->transpose());
235 bool IsSquare = (MatrixType::RowsAtCompileTime == MatrixType::ColsAtCompileTime) && MatrixType::RowsAtCompileTime!=
Dynamic,
236 bool MatchPacketSize =
239 struct inplace_transpose_selector;
241 template<
typename MatrixType>
242 struct inplace_transpose_selector<
MatrixType,true,false> {
244 m.matrix().template triangularView<StrictlyUpper>().swap(
m.matrix().transpose().template triangularView<StrictlyUpper>());
248 template<
typename MatrixType>
249 struct inplace_transpose_selector<
MatrixType,true,true> {
252 typedef typename internal::packet_traits<typename MatrixType::Scalar>::type Packet;
254 const Index Alignment = internal::evaluator<MatrixType>::Alignment;
255 PacketBlock<Packet>
A;
257 A.packet[
i] =
m.template packetByOuterInner<Alignment>(
i,0);
260 m.template writePacket<Alignment>(
m.rowIndexByOuterInner(
i,0),
m.colIndexByOuterInner(
i,0),
A.packet[
i]);
265 template <
typename MatrixType, Index Alignment>
267 typedef typename MatrixType::Scalar Scalar;
268 typedef typename internal::packet_traits<typename MatrixType::Scalar>::type Packet;
272 for (; row_start + PacketSize <=
m.rows(); row_start += PacketSize) {
273 for (
int col_start = row_start; col_start + PacketSize <=
m.cols(); col_start += PacketSize) {
274 PacketBlock<Packet>
A;
275 if (row_start == col_start) {
277 A.packet[
i] =
m.template packetByOuterInner<Alignment>(row_start +
i,col_start);
280 m.template writePacket<Alignment>(
m.rowIndexByOuterInner(row_start +
i, col_start),
m.colIndexByOuterInner(row_start +
i,col_start),
A.packet[
i]);
282 PacketBlock<Packet>
B;
283 for (
Index i=0;
i<PacketSize; ++
i) {
284 A.packet[
i] =
m.template packetByOuterInner<Alignment>(row_start +
i,col_start);
285 B.packet[
i] =
m.template packetByOuterInner<Alignment>(col_start +
i, row_start);
289 for (
Index i=0;
i<PacketSize; ++
i) {
290 m.template writePacket<Alignment>(
m.rowIndexByOuterInner(row_start +
i, col_start),
m.colIndexByOuterInner(row_start +
i,col_start),
B.packet[
i]);
291 m.template writePacket<Alignment>(
m.rowIndexByOuterInner(col_start +
i, row_start),
m.colIndexByOuterInner(col_start +
i,row_start),
A.packet[
i]);
297 m.matrix().row(
row).head(
row).swap(
298 m.matrix().col(
row).head(
row).transpose());
302 template<
typename MatrixType,
bool MatchPacketSize>
303 struct inplace_transpose_selector<
MatrixType,false,MatchPacketSize> {
306 if (
m.rows() ==
m.cols()) {
309 if ((
m.rows() % PacketSize) == 0)
310 BlockedInPlaceTranspose<MatrixType,internal::evaluator<MatrixType>::Alignment>(
m);
312 BlockedInPlaceTranspose<MatrixType,Unaligned>(
m);
315 m.matrix().template triangularView<StrictlyUpper>().swap(
m.matrix().transpose().template triangularView<StrictlyUpper>());
318 m =
m.transpose().eval();
345 template<
typename Derived>
349 &&
"transposeInPlace() called on a non-square non-resizable matrix");
350 internal::inplace_transpose_selector<Derived>::run(derived());
376 template<
typename Derived>
379 derived() = adjoint().eval();
382 #ifndef EIGEN_NO_DEBUG
388 template<
bool DestIsTransposed,
typename OtherDerived>
389 struct check_transpose_aliasing_compile_time_selector
391 enum { ret =
bool(blas_traits<OtherDerived>::IsTransposed) != DestIsTransposed };
394 template<
bool DestIsTransposed,
typename BinOp,
typename DerivedA,
typename DerivedB>
395 struct check_transpose_aliasing_compile_time_selector<DestIsTransposed,CwiseBinaryOp<BinOp,DerivedA,DerivedB> >
397 enum { ret =
bool(blas_traits<DerivedA>::IsTransposed) != DestIsTransposed
398 ||
bool(blas_traits<DerivedB>::IsTransposed) != DestIsTransposed
402 template<
typename Scalar,
bool DestIsTransposed,
typename OtherDerived>
403 struct check_transpose_aliasing_run_time_selector
407 return (
bool(blas_traits<OtherDerived>::IsTransposed) != DestIsTransposed) && (dest!=0 && dest==(
const Scalar*)
extract_data(src));
411 template<
typename Scalar,
bool DestIsTransposed,
typename BinOp,
typename DerivedA,
typename DerivedB>
412 struct check_transpose_aliasing_run_time_selector<Scalar,DestIsTransposed,CwiseBinaryOp<BinOp,DerivedA,DerivedB> >
414 EIGEN_DEVICE_FUNC static bool run(
const Scalar* dest,
const CwiseBinaryOp<BinOp,DerivedA,DerivedB>& src)
416 return ((blas_traits<DerivedA>::IsTransposed != DestIsTransposed) && (dest!=0 && dest==(
const Scalar*)
extract_data(src.lhs())))
417 || ((blas_traits<DerivedB>::IsTransposed != DestIsTransposed) && (dest!=0 && dest==(
const Scalar*)
extract_data(src.rhs())));
427 template<
typename Derived,
typename OtherDerived,
428 bool MightHaveTransposeAliasing
429 = check_transpose_aliasing_compile_time_selector
430 <blas_traits<Derived>::IsTransposed,OtherDerived>::ret
432 struct checkTransposeAliasing_impl
436 eigen_assert((!check_transpose_aliasing_run_time_selector
437 <
typename Derived::Scalar,blas_traits<Derived>::IsTransposed,OtherDerived>
439 &&
"aliasing detected during transposition, use transposeInPlace() "
440 "or evaluate the rhs into a temporary using .eval()");
445 template<
typename Derived,
typename OtherDerived>
446 struct checkTransposeAliasing_impl<Derived, OtherDerived, false>
453 template<
typename Dst,
typename Src>
456 if((!Dst::IsVectorAtCompileTime) && dst.rows()>1 && dst.cols()>1)
457 internal::checkTransposeAliasing_impl<Dst, Src>::run(dst, src);
RowXpr row(Index i)
This is the const version of row(). */.
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived)
#define EIGEN_DEVICE_FUNC
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Matrix< float, 1, Dynamic > MatrixType
TransposeReturnType transpose()
internal::traits< Derived >::Scalar Scalar
Transpose< Derived > TransposeReturnType
Base class for all dense matrices, vectors, and expressions.
const AdjointReturnType adjoint() const
The matrix class, also used for vectors and row-vectors.
const Scalar * data() const
Index innerStride() const
ScalarWithConstIfNotLvalue * data()
const Scalar & coeffRef(Index rowId, Index colId) const
Index outerStride() const
const Scalar & coeffRef(Index index) const
std::conditional_t< internal::is_lvalue< MatrixType >::value, Scalar, const Scalar > ScalarWithConstIfNotLvalue
internal::TransposeImpl_base< MatrixType >::type Base
internal::generic_xpr_base< Transpose< XprType > >::type Base
Expression of the transpose of a matrix.
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
const internal::remove_all_t< MatrixTypeNested > & nestedExpression() const
TransposeImpl< MatrixType, typename internal::traits< MatrixType >::StorageKind >::Base Base
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
std::remove_reference_t< MatrixTypeNested > & nestedExpression()
void resize(Index nrows, Index ncols)
internal::ref_selector< MatrixType >::non_const_type m_matrix
internal::remove_all_t< MatrixType > NestedExpression
internal::ref_selector< MatrixType >::non_const_type MatrixTypeNested
const unsigned int PacketAccessBit
const unsigned int LvalueBit
const unsigned int RowMajorBit
void check_for_aliasing(const Dst &dst, const Src &src)
void ptranspose(PacketBlock< Packet2cf, 2 > &kernel)
typename remove_all< T >::type remove_all_t
EIGEN_ALWAYS_INLINE const T::Scalar * extract_data(const T &m)
void BlockedInPlaceTranspose(MatrixType &m)
const unsigned int NestByRefBit
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.