78class Diagonal :
public internal::dense_xpr_base<Diagonal<MatrixType, DiagIndex_> >::type {
80 enum { DiagIndex = DiagIndex_ };
81 using Base =
typename internal::dense_xpr_base<Diagonal>::type;
82 EIGEN_DENSE_PUBLIC_INTERFACE(Diagonal)
84 EIGEN_DEVICE_FUNC
constexpr explicit inline Diagonal(MatrixType& matrix, Index a_index = DiagIndex)
85 : m_matrix(matrix), m_index(a_index) {
86 eigen_assert(a_index <= m_matrix.cols() && -a_index <= m_matrix.rows());
89 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Diagonal)
91 EIGEN_DEVICE_FUNC
constexpr inline Index rows()
const {
92 return m_index.value() < 0 ? numext::mini<Index>(m_matrix.cols(), m_matrix.rows() + m_index.value())
93 : numext::mini<Index>(m_matrix.rows(), m_matrix.cols() - m_index.value());
96 EIGEN_DEVICE_FUNC
constexpr Index cols()
const noexcept {
return 1; }
98 EIGEN_DEVICE_FUNC
constexpr Index innerStride()
const noexcept {
99 return m_matrix.outerStride() + m_matrix.innerStride();
102 EIGEN_DEVICE_FUNC
constexpr Index outerStride()
const noexcept {
return 0; }
104 using ScalarWithConstIfNotLvalue = std::conditional_t<internal::is_lvalue<MatrixType>::value, Scalar,
const Scalar>;
106 EIGEN_DEVICE_FUNC
inline ScalarWithConstIfNotLvalue* data() {
107 return rows() > 0 ? &(m_matrix.coeffRef(rowOffset(), colOffset())) :
nullptr;
109 EIGEN_DEVICE_FUNC
inline const Scalar* data()
const {
110 return rows() > 0 ? &(m_matrix.coeffRef(rowOffset(), colOffset())) :
nullptr;
113 EIGEN_DEVICE_FUNC
inline Scalar& coeffRef(Index row, Index) {
114 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
115 return m_matrix.coeffRef(row + rowOffset(), row + colOffset());
118 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(Index row, Index)
const {
119 return m_matrix.coeffRef(row + rowOffset(), row + colOffset());
122 EIGEN_DEVICE_FUNC
inline CoeffReturnType coeff(Index row, Index)
const {
123 return m_matrix.coeff(row + rowOffset(), row + colOffset());
126 EIGEN_DEVICE_FUNC
inline Scalar& coeffRef(Index idx) {
127 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
128 return m_matrix.coeffRef(idx + rowOffset(), idx + colOffset());
131 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(Index idx)
const {
132 return m_matrix.coeffRef(idx + rowOffset(), idx + colOffset());
135 EIGEN_DEVICE_FUNC
inline CoeffReturnType coeff(Index idx)
const {
136 return m_matrix.coeff(idx + rowOffset(), idx + colOffset());
139 EIGEN_DEVICE_FUNC
constexpr inline const internal::remove_all_t<typename MatrixType::Nested>& nestedExpression()
144 EIGEN_DEVICE_FUNC
constexpr inline Index index()
const {
return m_index.value(); }
147 typename internal::ref_selector<MatrixType>::non_const_type m_matrix;
148 const internal::variable_if_dynamicindex<Index, DiagIndex> m_index;
152 EIGEN_DEVICE_FUNC
constexpr Index rowOffset()
const noexcept {
return m_index.value() > 0 ? 0 : -m_index.value(); }
153 EIGEN_DEVICE_FUNC
constexpr Index colOffset()
const noexcept {
return m_index.value() > 0 ? m_index.value() : 0; }
155 template <
int LoadMode>
156 typename MatrixType::PacketReturnType packet(Index)
const;
157 template <
int LoadMode>
158 typename MatrixType::PacketReturnType packet(Index, Index)
const;