26 #ifndef EIGEN_DIAGONAL_H
27 #define EIGEN_DIAGONAL_H
51 template<
typename MatrixType,
int DiagIndex>
52 struct traits<Diagonal<MatrixType,DiagIndex> >
55 typedef typename nested<MatrixType>::type MatrixTypeNested;
56 typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
57 typedef typename MatrixType::StorageKind StorageKind;
59 AbsDiagIndex = DiagIndex<0 ? -DiagIndex : DiagIndex,
63 MatrixType::ColsAtCompileTime) - AbsDiagIndex),
64 ColsAtCompileTime = 1,
65 MaxRowsAtCompileTime =
int(MatrixType::MaxSizeAtCompileTime) ==
Dynamic ?
Dynamic
67 MatrixType::MaxColsAtCompileTime)
68 : (EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) - AbsDiagIndex),
69 MaxColsAtCompileTime = 1,
70 MaskLvalueBit = is_lvalue<MatrixType>::value ?
LvalueBit : 0,
72 CoeffReadCost = _MatrixTypeNested::CoeffReadCost,
73 MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret,
74 InnerStrideAtCompileTime = MatrixTypeOuterStride ==
Dynamic ?
Dynamic : MatrixTypeOuterStride+1,
75 OuterStrideAtCompileTime = 0
80 template<
typename MatrixType,
int DiagIndex>
class Diagonal
81 :
public internal::dense_xpr_base< Diagonal<MatrixType,DiagIndex> >::type
85 typedef typename internal::dense_xpr_base<Diagonal>::type
Base;
88 inline
Diagonal(MatrixType& matrix, Index index = DiagIndex) : m_matrix(matrix), m_index(index) {}
92 inline Index rows()
const
93 {
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()); }
95 inline Index
cols()
const {
return 1; }
97 inline Index innerStride()
const
99 return m_matrix.outerStride() + 1;
102 inline Index outerStride()
const
107 typedef typename internal::conditional<
108 internal::is_lvalue<MatrixType>::value,
114 inline const Scalar*
data()
const {
return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
116 inline Scalar& coeffRef(Index
row, Index)
119 return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
122 inline const Scalar& coeffRef(Index
row, Index)
const
124 return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
127 inline CoeffReturnType coeff(Index
row, Index)
const
129 return m_matrix.coeff(row+rowOffset(), row+colOffset());
132 inline Scalar& coeffRef(Index index)
135 return m_matrix.const_cast_derived().coeffRef(index+rowOffset(), index+colOffset());
138 inline const Scalar& coeffRef(Index index)
const
140 return m_matrix.const_cast_derived().coeffRef(index+rowOffset(), index+colOffset());
143 inline CoeffReturnType coeff(Index index)
const
145 return m_matrix.coeff(index+rowOffset(), index+colOffset());
148 const typename internal::remove_all<typename MatrixType::Nested>::type&
149 nestedExpression()
const
156 return m_index.value();
161 const internal::variable_if_dynamic<Index, DiagIndex>
m_index;
165 EIGEN_STRONG_INLINE Index absDiagIndex()
const {
return m_index.value()>0 ? m_index.value() : -m_index.value(); }
166 EIGEN_STRONG_INLINE Index rowOffset()
const {
return m_index.value()>0 ? 0 : -m_index.value(); }
167 EIGEN_STRONG_INLINE Index colOffset()
const {
return m_index.value()>0 ? m_index.value() : 0; }
169 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(Index)
const;
170 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(Index,Index)
const;
181 template<
typename Derived>
182 inline typename MatrixBase<Derived>::DiagonalReturnType
189 template<
typename Derived>
207 template<
typename Derived>
215 template<
typename Derived>
233 template<
typename Derived>
242 template<
typename Derived>
245 MatrixBase<Derived>::diagonal()
const
252 #endif // EIGEN_DIAGONAL_H