64template<
typename MatrixType,
int _DiagIndex>
class Diagonal
65 :
public internal::dense_xpr_base< Diagonal<MatrixType,_DiagIndex> >::type
69 enum { DiagIndex = _DiagIndex };
70 typedef typename internal::dense_xpr_base<Diagonal>::type Base;
71 EIGEN_DENSE_PUBLIC_INTERFACE(Diagonal)
73 inline Diagonal(
MatrixType& matrix, Index a_index = DiagIndex) : m_matrix(matrix), m_index(a_index) {}
75 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Diagonal)
77 inline Index rows()
const
78 {
return m_index.value()<0 ? (std::min<Index>)(m_matrix.cols(),m_matrix.rows()+m_index.value()) : (std::min<Index>)(m_matrix.rows(),m_matrix.cols()-m_index.value()); }
80 inline Index cols()
const {
return 1; }
82 inline Index innerStride()
const
84 return m_matrix.outerStride() + 1;
87 inline Index outerStride()
const
92 typedef typename internal::conditional<
93 internal::is_lvalue<MatrixType>::value,
96 >::type ScalarWithConstIfNotLvalue;
98 inline ScalarWithConstIfNotLvalue* data() {
return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
99 inline const Scalar* data()
const {
return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
101 inline Scalar& coeffRef(Index row, Index)
104 return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
107 inline const Scalar& coeffRef(Index row, Index)
const
109 return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
112 inline CoeffReturnType coeff(Index row, Index)
const
114 return m_matrix.coeff(row+rowOffset(), row+colOffset());
117 inline Scalar& coeffRef(Index idx)
120 return m_matrix.const_cast_derived().coeffRef(idx+rowOffset(), idx+colOffset());
123 inline const Scalar& coeffRef(Index idx)
const
125 return m_matrix.const_cast_derived().coeffRef(idx+rowOffset(), idx+colOffset());
128 inline CoeffReturnType coeff(Index idx)
const
130 return m_matrix.coeff(idx+rowOffset(), idx+colOffset());
133 const typename internal::remove_all<typename MatrixType::Nested>::type&
134 nestedExpression()
const
141 return m_index.value();
145 typename MatrixType::Nested m_matrix;
146 const internal::variable_if_dynamicindex<Index, DiagIndex> m_index;
150 EIGEN_STRONG_INLINE Index absDiagIndex()
const {
return m_index.value()>0 ? m_index.value() : -m_index.value(); }
151 EIGEN_STRONG_INLINE Index rowOffset()
const {
return m_index.value()>0 ? 0 : -m_index.value(); }
152 EIGEN_STRONG_INLINE Index colOffset()
const {
return m_index.value()>0 ? m_index.value() : 0; }
154 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(Index)
const;
155 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(Index,Index)
const;