11 #ifndef EIGEN_DIAGONAL_H 12 #define EIGEN_DIAGONAL_H 15 #include "./InternalHeaderCheck.h" 39 template <
typename MatrixType,
int DiagIndex>
40 struct traits<Diagonal<MatrixType, DiagIndex> > : traits<MatrixType> {
41 typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
42 typedef std::remove_reference_t<MatrixTypeNested> MatrixTypeNested_;
43 typedef typename MatrixType::StorageKind StorageKind;
45 RowsAtCompileTime = (int(DiagIndex) ==
DynamicIndex || int(MatrixType::SizeAtCompileTime) ==
Dynamic)
47 : (plain_enum_min(MatrixType::RowsAtCompileTime - plain_enum_max(-DiagIndex, 0),
48 MatrixType::ColsAtCompileTime - plain_enum_max(DiagIndex, 0))),
49 ColsAtCompileTime = 1,
50 MaxRowsAtCompileTime =
53 ? min_size_prefer_fixed(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime)
54 : (plain_enum_min(MatrixType::MaxRowsAtCompileTime - plain_enum_max(-DiagIndex, 0),
55 MatrixType::MaxColsAtCompileTime - plain_enum_max(DiagIndex, 0))),
56 MaxColsAtCompileTime = 1,
57 MaskLvalueBit = is_lvalue<MatrixType>::value ?
LvalueBit : 0,
60 MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret,
61 InnerStrideAtCompileTime = MatrixTypeOuterStride ==
Dynamic ?
Dynamic : MatrixTypeOuterStride + 1,
62 OuterStrideAtCompileTime = 0
67 template <
typename MatrixType,
int DiagIndex_>
68 class 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())); }
97 EIGEN_DEVICE_FUNC
inline Scalar& coeffRef(
Index row,
Index) {
98 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
99 return m_matrix.coeffRef(row + rowOffset(), row + colOffset());
102 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(
Index row,
Index)
const {
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) {
111 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
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;
159 template <
typename Derived>
165 template <
typename Derived>
182 template <
typename Derived>
188 template <
typename Derived>
204 template <
typename Derived>
205 template <
int Index_>
211 template <
typename Derived>
212 template <
int Index_>
214 return Diagonal<const Derived, Index_>(derived());
219 #endif // EIGEN_DIAGONAL_H const unsigned int DirectAccessBit
Definition: Constants.h:159
const unsigned int LvalueBit
Definition: Constants.h:148
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
const int DynamicIndex
Definition: Constants.h:30
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
const unsigned int RowMajorBit
Definition: Constants.h:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:68
const int Dynamic
Definition: Constants.h:25
DiagonalReturnType diagonal()
Definition: Diagonal.h:160