00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_TRANSPOSE_H
00026 #define EIGEN_TRANSPOSE_H
00027
00040 template<typename MatrixType>
00041 struct ei_traits<Transpose<MatrixType> >
00042 {
00043 typedef typename MatrixType::Scalar Scalar;
00044 typedef typename ei_nested<MatrixType>::type MatrixTypeNested;
00045 typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested;
00046 enum {
00047 RowsAtCompileTime = MatrixType::ColsAtCompileTime,
00048 ColsAtCompileTime = MatrixType::RowsAtCompileTime,
00049 MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime,
00050 MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
00051 Flags = ((int(_MatrixTypeNested::Flags) ^ RowMajorBit)
00052 & ~(LowerTriangularBit | UpperTriangularBit))
00053 | (int(_MatrixTypeNested::Flags)&UpperTriangularBit ? LowerTriangularBit : 0)
00054 | (int(_MatrixTypeNested::Flags)&LowerTriangularBit ? UpperTriangularBit : 0),
00055 CoeffReadCost = _MatrixTypeNested::CoeffReadCost
00056 };
00057 };
00058
00059 template<typename MatrixType> class Transpose
00060 : public MatrixBase<Transpose<MatrixType> >
00061 {
00062 public:
00063
00064 EIGEN_GENERIC_PUBLIC_INTERFACE(Transpose)
00065
00066 inline Transpose(const MatrixType& matrix) : m_matrix(matrix) {}
00067
00068 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Transpose)
00069
00070 inline int rows() const { return m_matrix.cols(); }
00071 inline int cols() const { return m_matrix.rows(); }
00072 inline int stride(void) const { return m_matrix.stride(); }
00073
00074 inline Scalar& coeffRef(int row, int col)
00075 {
00076 return m_matrix.const_cast_derived().coeffRef(col, row);
00077 }
00078
00079 inline const Scalar coeff(int row, int col) const
00080 {
00081 return m_matrix.coeff(col, row);
00082 }
00083
00084 inline const Scalar coeff(int index) const
00085 {
00086 return m_matrix.coeff(index);
00087 }
00088
00089 inline Scalar& coeffRef(int index)
00090 {
00091 return m_matrix.const_cast_derived().coeffRef(index);
00092 }
00093
00094 template<int LoadMode>
00095 inline const PacketScalar packet(int row, int col) const
00096 {
00097 return m_matrix.template packet<LoadMode>(col, row);
00098 }
00099
00100 template<int LoadMode>
00101 inline void writePacket(int row, int col, const PacketScalar& x)
00102 {
00103 m_matrix.const_cast_derived().template writePacket<LoadMode>(col, row, x);
00104 }
00105
00106 template<int LoadMode>
00107 inline const PacketScalar packet(int index) const
00108 {
00109 return m_matrix.template packet<LoadMode>(index);
00110 }
00111
00112 template<int LoadMode>
00113 inline void writePacket(int index, const PacketScalar& x)
00114 {
00115 m_matrix.const_cast_derived().template writePacket<LoadMode>(index, x);
00116 }
00117
00118 protected:
00119 const typename MatrixType::Nested m_matrix;
00120 };
00121
00141 template<typename Derived>
00142 inline Transpose<Derived>
00143 MatrixBase<Derived>::transpose()
00144 {
00145 return derived();
00146 }
00147
00153 template<typename Derived>
00154 inline const Transpose<Derived>
00155 MatrixBase<Derived>::transpose() const
00156 {
00157 return derived();
00158 }
00159
00175 template<typename Derived>
00176 inline const typename MatrixBase<Derived>::AdjointReturnType
00177 MatrixBase<Derived>::adjoint() const
00178 {
00179 return conjugate().nestByValue();
00180 }
00181
00182
00183
00184
00185
00186 template<typename MatrixType,
00187 bool IsSquare = (MatrixType::RowsAtCompileTime == MatrixType::ColsAtCompileTime) && MatrixType::RowsAtCompileTime!=Dynamic>
00188 struct ei_inplace_transpose_selector;
00189
00190 template<typename MatrixType>
00191 struct ei_inplace_transpose_selector<MatrixType,true> {
00192 static void run(MatrixType& m) {
00193 m.template part<StrictlyUpperTriangular>().swap(m.transpose());
00194 }
00195 };
00196
00197 template<typename MatrixType>
00198 struct ei_inplace_transpose_selector<MatrixType,false> {
00199 static void run(MatrixType& m) {
00200 if (m.rows()==m.cols())
00201 m.template part<StrictlyUpperTriangular>().swap(m.transpose());
00202 else
00203 m = m.transpose().eval();
00204 }
00205 };
00206
00221 template<typename Derived>
00222 inline void MatrixBase<Derived>::transposeInPlace()
00223 {
00224 ei_inplace_transpose_selector<Derived>::run(derived());
00225 }
00226
00227 #endif // EIGEN_TRANSPOSE_H