68class Diagonal :
public internal::dense_xpr_base<Diagonal<MatrixType, DiagIndex_> >::type {
70 enum { DiagIndex = DiagIndex_ };
71 typedef typename internal::dense_xpr_base<Diagonal>::type Base;
72 EIGEN_DENSE_PUBLIC_INTERFACE(Diagonal)
74 EIGEN_DEVICE_FUNC
explicit inline Diagonal(
MatrixType& matrix,
Index a_index = DiagIndex)
75 : m_matrix(matrix), m_index(a_index) {
76 eigen_assert(a_index <= m_matrix.cols() && -a_index <= m_matrix.rows());
79 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Diagonal)
81 EIGEN_DEVICE_FUNC
inline Index rows()
const {
82 return m_index.value() < 0 ? numext::mini<Index>(m_matrix.cols(), m_matrix.rows() + m_index.value())
83 : numext::mini<Index>(m_matrix.rows(), m_matrix.cols() - m_index.value());
86 EIGEN_DEVICE_FUNC
constexpr Index cols()
const noexcept {
return 1; }
88 EIGEN_DEVICE_FUNC
constexpr Index innerStride()
const noexcept {
return m_matrix.outerStride() + 1; }
90 EIGEN_DEVICE_FUNC
constexpr Index outerStride()
const noexcept {
return 0; }
92 typedef std::conditional_t<internal::is_lvalue<MatrixType>::value,
Scalar,
const Scalar> ScalarWithConstIfNotLvalue;
94 EIGEN_DEVICE_FUNC
inline ScalarWithConstIfNotLvalue* data() {
return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
95 EIGEN_DEVICE_FUNC
inline const Scalar* data()
const {
return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
99 return m_matrix.coeffRef(row + rowOffset(), row + colOffset());
103 return m_matrix.coeffRef(row + rowOffset(), row + colOffset());
106 EIGEN_DEVICE_FUNC
inline CoeffReturnType coeff(
Index row,
Index)
const {
107 return m_matrix.coeff(row + rowOffset(), row + colOffset());
110 EIGEN_DEVICE_FUNC
inline Scalar& coeffRef(
Index idx) {
112 return m_matrix.coeffRef(idx + rowOffset(), idx + colOffset());
115 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(
Index idx)
const {
116 return m_matrix.coeffRef(idx + rowOffset(), idx + colOffset());
119 EIGEN_DEVICE_FUNC
inline CoeffReturnType coeff(
Index idx)
const {
120 return m_matrix.coeff(idx + rowOffset(), idx + colOffset());
123 EIGEN_DEVICE_FUNC
inline const internal::remove_all_t<typename MatrixType::Nested>& nestedExpression()
const {
127 EIGEN_DEVICE_FUNC
inline Index index()
const {
return m_index.value(); }
130 typename internal::ref_selector<MatrixType>::non_const_type m_matrix;
131 const internal::variable_if_dynamicindex<Index, DiagIndex> m_index;
135 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr Index absDiagIndex()
const noexcept {
136 return m_index.value() > 0 ? m_index.value() : -m_index.value();
138 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr Index rowOffset()
const noexcept {
139 return m_index.value() > 0 ? 0 : -m_index.value();
141 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr Index colOffset()
const noexcept {
142 return m_index.value() > 0 ? m_index.value() : 0;
145 template <
int LoadMode>
146 typename MatrixType::PacketReturnType packet(
Index)
const;
147 template <
int LoadMode>
148 typename MatrixType::PacketReturnType packet(
Index,
Index)
const;