11 #ifndef EIGEN_DIAGONAL_H
12 #define EIGEN_DIAGONAL_H
14 #include "./InternalHeaderCheck.h"
38 template<
typename MatrixType,
int DiagIndex>
39 struct traits<Diagonal<MatrixType,DiagIndex> >
42 typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
43 typedef std::remove_reference_t<MatrixTypeNested> MatrixTypeNested_;
44 typedef typename MatrixType::StorageKind StorageKind;
47 : (plain_enum_min(MatrixType::RowsAtCompileTime - plain_enum_max(-DiagIndex, 0),
48 MatrixType::ColsAtCompileTime - plain_enum_max( DiagIndex, 0))),
49 ColsAtCompileTime = 1,
50 MaxRowsAtCompileTime =
int(MatrixType::MaxSizeAtCompileTime) ==
Dynamic ?
Dynamic
51 : DiagIndex ==
DynamicIndex ? min_size_prefer_fixed(MatrixType::MaxRowsAtCompileTime,
52 MatrixType::MaxColsAtCompileTime)
53 : (plain_enum_min(MatrixType::MaxRowsAtCompileTime - plain_enum_max(-DiagIndex, 0),
54 MatrixType::MaxColsAtCompileTime - plain_enum_max( DiagIndex, 0))),
55 MaxColsAtCompileTime = 1,
56 MaskLvalueBit = is_lvalue<MatrixType>::value ?
LvalueBit : 0,
58 MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret,
59 InnerStrideAtCompileTime = MatrixTypeOuterStride ==
Dynamic ?
Dynamic : MatrixTypeOuterStride+1,
60 OuterStrideAtCompileTime = 0
65 template<
typename MatrixType,
int DiagIndex_>
class Diagonal
66 :
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)
75 explicit inline Diagonal(MatrixType& matrix,
Index a_index = DiagIndex) : m_matrix(matrix), m_index(a_index)
77 eigen_assert( a_index <= m_matrix.cols() && -a_index <= m_matrix.rows() );
80 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Diagonal)
83 inline Index rows()
const
85 return m_index.value()<0 ? numext::mini<Index>(m_matrix.cols(),m_matrix.rows()+m_index.value())
86 : numext::mini<Index>(m_matrix.rows(),m_matrix.cols()-m_index.value());
89 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
90 inline Index cols()
const EIGEN_NOEXCEPT {
return 1; }
92 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
93 inline Index innerStride()
const EIGEN_NOEXCEPT {
94 return m_matrix.outerStride() + 1;
97 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
98 inline Index outerStride()
const EIGEN_NOEXCEPT {
return 0; }
100 typedef std::conditional_t<
101 internal::is_lvalue<MatrixType>::value,
104 > ScalarWithConstIfNotLvalue;
107 inline ScalarWithConstIfNotLvalue* data() {
return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
109 inline const Scalar* data()
const {
return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
114 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
115 return m_matrix.coeffRef(row+rowOffset(), row+colOffset());
119 inline const Scalar& coeffRef(
Index row,
Index)
const
121 return m_matrix.coeffRef(row+rowOffset(), row+colOffset());
125 inline CoeffReturnType coeff(
Index row,
Index)
const
127 return m_matrix.coeff(row+rowOffset(), row+colOffset());
131 inline Scalar& coeffRef(
Index idx)
133 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
134 return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset());
138 inline const Scalar& coeffRef(
Index idx)
const
140 return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset());
144 inline CoeffReturnType coeff(
Index idx)
const
146 return m_matrix.coeff(idx+rowOffset(), idx+colOffset());
150 inline const internal::remove_all_t<typename MatrixType::Nested>&
151 nestedExpression()
const
157 inline Index index()
const
159 return m_index.value();
163 typename internal::ref_selector<MatrixType>::non_const_type m_matrix;
164 const internal::variable_if_dynamicindex<Index, DiagIndex> m_index;
168 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
169 Index absDiagIndex()
const EIGEN_NOEXCEPT {
return m_index.value()>0 ? m_index.value() : -m_index.value(); }
170 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
171 Index rowOffset()
const EIGEN_NOEXCEPT {
return m_index.value()>0 ? 0 : -m_index.value(); }
172 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
173 Index colOffset()
const EIGEN_NOEXCEPT {
return m_index.value()>0 ? m_index.value() : 0; }
175 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(
Index)
const;
176 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(
Index,
Index)
const;
187 template<
typename Derived>
195 template<
typename Derived>
196 EIGEN_DEVICE_FUNC
inline
214 template<
typename Derived>
222 template<
typename Derived>
240 template<
typename Derived>
250 template<
typename Derived>
253 inline const Diagonal<const Derived, Index_>
256 return Diagonal<const Derived, Index_>(derived());
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:67
DiagonalReturnType diagonal()
Definition: Diagonal.h:189
const unsigned int DirectAccessBit
Definition: Constants.h:157
const unsigned int LvalueBit
Definition: Constants.h:146
const unsigned int RowMajorBit
Definition: Constants.h:68
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int DynamicIndex
Definition: Constants.h:29
const int Dynamic
Definition: Constants.h:24
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41