Go to the documentation of this file.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_DIAGONAL_H
00026 #define EIGEN_DIAGONAL_H
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 namespace internal {
00048 template<typename MatrixType, int DiagIndex>
00049 struct traits<Diagonal<MatrixType,DiagIndex> >
00050 : traits<MatrixType>
00051 {
00052 typedef typename nested<MatrixType>::type MatrixTypeNested;
00053 typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
00054 typedef typename MatrixType::StorageKind StorageKind;
00055 enum {
00056 AbsDiagIndex = DiagIndex<0 ? -DiagIndex : DiagIndex,
00057
00058 RowsAtCompileTime = (int(DiagIndex) == Dynamic || int(MatrixType::SizeAtCompileTime) == Dynamic) ? Dynamic
00059 : (EIGEN_SIZE_MIN_PREFER_DYNAMIC(MatrixType::RowsAtCompileTime,
00060 MatrixType::ColsAtCompileTime) - AbsDiagIndex),
00061 ColsAtCompileTime = 1,
00062 MaxRowsAtCompileTime = int(MatrixType::MaxSizeAtCompileTime) == Dynamic ? Dynamic
00063 : DiagIndex == Dynamic ? EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime,
00064 MatrixType::MaxColsAtCompileTime)
00065 : (EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) - AbsDiagIndex),
00066 MaxColsAtCompileTime = 1,
00067 MaskLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
00068 Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | MaskLvalueBit | DirectAccessBit) & ~RowMajorBit,
00069 CoeffReadCost = _MatrixTypeNested::CoeffReadCost,
00070 MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret,
00071 InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1,
00072 OuterStrideAtCompileTime = 0
00073 };
00074 };
00075 }
00076
00077 template<typename MatrixType, int DiagIndex> class Diagonal
00078 : public internal::dense_xpr_base< Diagonal<MatrixType,DiagIndex> >::type
00079 {
00080 public:
00081
00082 typedef typename internal::dense_xpr_base<Diagonal>::type Base;
00083 EIGEN_DENSE_PUBLIC_INTERFACE(Diagonal)
00084
00085 inline Diagonal(const MatrixType& matrix, Index index = DiagIndex) : m_matrix(matrix), m_index(index) {}
00086
00087 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Diagonal)
00088
00089 inline Index rows() const
00090 { return m_index.value()<0 ? std::min(m_matrix.cols(),m_matrix.rows()+m_index.value()) : std::min(m_matrix.rows(),m_matrix.cols()-m_index.value()); }
00091
00092 inline Index cols() const { return 1; }
00093
00094 inline Index innerStride() const
00095 {
00096 return m_matrix.outerStride() + 1;
00097 }
00098
00099 inline Index outerStride() const
00100 {
00101 return 0;
00102 }
00103
00104 inline Scalar& coeffRef(Index row, Index)
00105 {
00106 return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
00107 }
00108
00109 inline const Scalar& coeffRef(Index row, Index) const
00110 {
00111 return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
00112 }
00113
00114 inline CoeffReturnType coeff(Index row, Index) const
00115 {
00116 return m_matrix.coeff(row+rowOffset(), row+colOffset());
00117 }
00118
00119 inline Scalar& coeffRef(Index index)
00120 {
00121 return m_matrix.const_cast_derived().coeffRef(index+rowOffset(), index+colOffset());
00122 }
00123
00124 inline const Scalar& coeffRef(Index index) const
00125 {
00126 return m_matrix.const_cast_derived().coeffRef(index+rowOffset(), index+colOffset());
00127 }
00128
00129 inline CoeffReturnType coeff(Index index) const
00130 {
00131 return m_matrix.coeff(index+rowOffset(), index+colOffset());
00132 }
00133
00134 protected:
00135 const typename MatrixType::Nested m_matrix;
00136 const internal::variable_if_dynamic<Index, DiagIndex> m_index;
00137
00138 private:
00139
00140 EIGEN_STRONG_INLINE Index absDiagIndex() const { return m_index.value()>0 ? m_index.value() : -m_index.value(); }
00141 EIGEN_STRONG_INLINE Index rowOffset() const { return m_index.value()>0 ? 0 : -m_index.value(); }
00142 EIGEN_STRONG_INLINE Index colOffset() const { return m_index.value()>0 ? m_index.value() : 0; }
00143
00144 template<int LoadMode> typename MatrixType::PacketReturnType packet(Index) const;
00145 template<int LoadMode> typename MatrixType::PacketReturnType packet(Index,Index) const;
00146 };
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 template<typename Derived>
00157 inline typename MatrixBase<Derived>::DiagonalReturnType
00158 MatrixBase<Derived>::diagonal()
00159 {
00160 return derived();
00161 }
00162
00163
00164 template<typename Derived>
00165 inline const typename MatrixBase<Derived>::ConstDiagonalReturnType
00166 MatrixBase<Derived>::diagonal() const
00167 {
00168 return derived();
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 template<typename Derived>
00183 inline typename MatrixBase<Derived>::template DiagonalIndexReturnType<Dynamic>::Type
00184 MatrixBase<Derived>::diagonal(Index index)
00185 {
00186 return typename DiagonalIndexReturnType<Dynamic>::Type(derived(), index);
00187 }
00188
00189
00190 template<typename Derived>
00191 inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Dynamic>::Type
00192 MatrixBase<Derived>::diagonal(Index index) const
00193 {
00194 return typename ConstDiagonalIndexReturnType<Dynamic>::Type(derived(), index);
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 template<typename Derived>
00209 template<int Index>
00210 inline typename MatrixBase<Derived>::template DiagonalIndexReturnType<Index>::Type
00211 MatrixBase<Derived>::diagonal()
00212 {
00213 return derived();
00214 }
00215
00216
00217 template<typename Derived>
00218 template<int Index>
00219 inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Index>::Type
00220 MatrixBase<Derived>::diagonal() const
00221 {
00222 return derived();
00223 }
00224
00225 #endif // EIGEN_DIAGONAL_H