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 EIGEN_CONSTEXPR
inline Index cols()
const EIGEN_NOEXCEPT {
return 1; }
88 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index innerStride()
const EIGEN_NOEXCEPT {
89 return m_matrix.outerStride() + 1;
92 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index outerStride()
const EIGEN_NOEXCEPT {
return 0; }
94 typedef std::conditional_t<internal::is_lvalue<MatrixType>::value, Scalar,
const Scalar> ScalarWithConstIfNotLvalue;
96 EIGEN_DEVICE_FUNC
inline ScalarWithConstIfNotLvalue* data() {
return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
97 EIGEN_DEVICE_FUNC
inline const Scalar* data()
const {
return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
99 EIGEN_DEVICE_FUNC
inline Scalar& coeffRef(
Index row,
Index) {
100 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
101 return m_matrix.coeffRef(row + rowOffset(), row + colOffset());
104 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(
Index row,
Index)
const {
105 return m_matrix.coeffRef(row + rowOffset(), row + colOffset());
108 EIGEN_DEVICE_FUNC
inline CoeffReturnType coeff(
Index row,
Index)
const {
109 return m_matrix.coeff(row + rowOffset(), row + colOffset());
112 EIGEN_DEVICE_FUNC
inline Scalar& coeffRef(
Index idx) {
113 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
114 return m_matrix.coeffRef(idx + rowOffset(), idx + colOffset());
117 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(
Index idx)
const {
118 return m_matrix.coeffRef(idx + rowOffset(), idx + colOffset());
121 EIGEN_DEVICE_FUNC
inline CoeffReturnType coeff(
Index idx)
const {
122 return m_matrix.coeff(idx + rowOffset(), idx + colOffset());
125 EIGEN_DEVICE_FUNC
inline const internal::remove_all_t<typename MatrixType::Nested>& nestedExpression()
const {
129 EIGEN_DEVICE_FUNC
inline Index index()
const {
return m_index.value(); }
132 typename internal::ref_selector<MatrixType>::non_const_type m_matrix;
133 const internal::variable_if_dynamicindex<Index, DiagIndex> m_index;
137 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
Index absDiagIndex()
const EIGEN_NOEXCEPT {
138 return m_index.value() > 0 ? m_index.value() : -m_index.value();
140 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
Index rowOffset()
const EIGEN_NOEXCEPT {
141 return m_index.value() > 0 ? 0 : -m_index.value();
143 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
Index colOffset()
const EIGEN_NOEXCEPT {
144 return m_index.value() > 0 ? m_index.value() : 0;
147 template <
int LoadMode>
148 typename MatrixType::PacketReturnType packet(
Index)
const;
149 template <
int LoadMode>
150 typename MatrixType::PacketReturnType packet(
Index,
Index)
const;