11 #ifndef EIGEN_DIAGONAL_H
12 #define EIGEN_DIAGONAL_H
36 template<
typename MatrixType,
int DiagIndex>
37 struct traits<Diagonal<MatrixType,DiagIndex> >
40 typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
41 typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
42 typedef typename MatrixType::StorageKind StorageKind;
44 RowsAtCompileTime = (int(DiagIndex) == DynamicIndex || int(MatrixType::SizeAtCompileTime) == Dynamic) ? Dynamic
45 : (EIGEN_PLAIN_ENUM_MIN(MatrixType::RowsAtCompileTime - EIGEN_PLAIN_ENUM_MAX(-DiagIndex, 0),
46 MatrixType::ColsAtCompileTime - EIGEN_PLAIN_ENUM_MAX( DiagIndex, 0))),
47 ColsAtCompileTime = 1,
48 MaxRowsAtCompileTime =
int(MatrixType::MaxSizeAtCompileTime) == Dynamic ? Dynamic
49 : DiagIndex == DynamicIndex ? EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime,
50 MatrixType::MaxColsAtCompileTime)
51 : (EIGEN_PLAIN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime - EIGEN_PLAIN_ENUM_MAX(-DiagIndex, 0),
52 MatrixType::MaxColsAtCompileTime - EIGEN_PLAIN_ENUM_MAX( DiagIndex, 0))),
53 MaxColsAtCompileTime = 1,
54 MaskLvalueBit = is_lvalue<MatrixType>::value ?
LvalueBit : 0,
56 MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret,
57 InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1,
58 OuterStrideAtCompileTime = 0
63 template<
typename MatrixType,
int _DiagIndex>
class Diagonal
64 :
public internal::dense_xpr_base< Diagonal<MatrixType,_DiagIndex> >::type
68 enum { DiagIndex = _DiagIndex };
69 typedef typename internal::dense_xpr_base<Diagonal>::type Base;
70 EIGEN_DENSE_PUBLIC_INTERFACE(
Diagonal)
73 explicit inline Diagonal(MatrixType& matrix, Index a_index = DiagIndex) : m_matrix(matrix), m_index(a_index) {}
75 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Diagonal)
78 inline Index rows()
const
80 return m_index.value()<0 ? numext::mini<Index>(m_matrix.cols(),m_matrix.rows()+m_index.value())
81 : numext::mini<Index>(m_matrix.rows(),m_matrix.cols()-m_index.value());
85 inline Index cols()
const {
return 1; }
88 inline Index innerStride()
const
90 return m_matrix.outerStride() + 1;
94 inline Index outerStride()
const
99 typedef typename internal::conditional<
100 internal::is_lvalue<MatrixType>::value,
103 >::type ScalarWithConstIfNotLvalue;
106 inline ScalarWithConstIfNotLvalue* data() {
return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
108 inline const Scalar* data()
const {
return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
111 inline Scalar& coeffRef(Index row, Index)
113 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
114 return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
118 inline const Scalar& coeffRef(Index row, Index)
const
120 return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
124 inline CoeffReturnType coeff(Index row, Index)
const
126 return m_matrix.coeff(row+rowOffset(), row+colOffset());
130 inline Scalar& coeffRef(Index idx)
132 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
133 return m_matrix.const_cast_derived().coeffRef(idx+rowOffset(), idx+colOffset());
137 inline const Scalar& coeffRef(Index idx)
const
139 return m_matrix.const_cast_derived().coeffRef(idx+rowOffset(), idx+colOffset());
143 inline CoeffReturnType coeff(Index idx)
const
145 return m_matrix.coeff(idx+rowOffset(), idx+colOffset());
149 inline const typename internal::remove_all<typename MatrixType::Nested>::type&
150 nestedExpression()
const
156 inline Index index()
const
158 return m_index.value();
162 typename MatrixType::Nested m_matrix;
163 const internal::variable_if_dynamicindex<Index, DiagIndex> m_index;
168 EIGEN_STRONG_INLINE Index absDiagIndex()
const {
return m_index.value()>0 ? m_index.value() : -m_index.value(); }
170 EIGEN_STRONG_INLINE Index rowOffset()
const {
return m_index.value()>0 ? 0 : -m_index.value(); }
172 EIGEN_STRONG_INLINE Index colOffset()
const {
return m_index.value()>0 ? m_index.value() : 0; }
174 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(Index)
const;
175 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(Index,Index)
const;
186 template<
typename Derived>
194 template<
typename Derived>
212 template<
typename Derived>
220 template<
typename Derived>
238 template<
typename Derived>
243 return typename DiagonalIndexReturnType<Index_>::Type(derived());
247 template<
typename Derived>
249 inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Index_>::Type
252 return typename ConstDiagonalIndexReturnType<Index_>::Type(derived());
257 #endif // EIGEN_DIAGONAL_H
Expression of the transpose of a matrix.
Definition: Transpose.h:53
const unsigned int DirectAccessBit
Definition: Constants.h:149
const unsigned int LvalueBit
Definition: Constants.h:138
const unsigned int RowMajorBit
Definition: Constants.h:61
Definition: Eigen_Colamd.h:54
DiagonalReturnType diagonal()
Definition: Diagonal.h:188
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:63
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48