11 #ifndef EIGEN_DIAGONAL_H
12 #define EIGEN_DIAGONAL_H
36 template<
typename MatrixType,
int DiagIndex>
41 typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
42 typedef typename MatrixType::StorageKind StorageKind;
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,
57 InnerStrideAtCompileTime = MatrixTypeOuterStride ==
Dynamic ?
Dynamic : MatrixTypeOuterStride+1,
58 OuterStrideAtCompileTime = 0
63 template<
typename MatrixType,
int _DiagIndex>
class Diagonal
68 enum { DiagIndex = _DiagIndex };
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_assert( a_index <= m_matrix.cols() && -a_index <= m_matrix.rows() );
78 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Diagonal)
81 inline Index rows()
const
83 return m_index.value()<0 ? numext::mini<Index>(m_matrix.cols(),m_matrix.rows()+m_index.value())
84 : numext::mini<Index>(m_matrix.rows(),m_matrix.cols()-m_index.value());
88 inline Index cols()
const {
return 1; }
91 inline Index innerStride()
const
93 return m_matrix.outerStride() + 1;
97 inline Index outerStride()
const
111 inline const Scalar* data()
const {
return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
116 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
117 return m_matrix.coeffRef(row+rowOffset(), row+colOffset());
121 inline const Scalar& coeffRef(
Index row,
Index)
const
123 return m_matrix.coeffRef(row+rowOffset(), row+colOffset());
127 inline CoeffReturnType coeff(
Index row,
Index)
const
129 return m_matrix.coeff(row+rowOffset(), row+colOffset());
133 inline Scalar& coeffRef(
Index idx)
135 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
136 return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset());
140 inline const Scalar& coeffRef(
Index idx)
const
142 return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset());
146 inline CoeffReturnType coeff(
Index idx)
const
148 return m_matrix.coeff(idx+rowOffset(), idx+colOffset());
152 inline const typename internal::remove_all<typename MatrixType::Nested>::type&
153 nestedExpression()
const
159 inline Index index()
const
161 return m_index.value();
171 EIGEN_STRONG_INLINE
Index absDiagIndex()
const {
return m_index.value()>0 ? m_index.value() : -m_index.value(); }
173 EIGEN_STRONG_INLINE
Index rowOffset()
const {
return m_index.value()>0 ? 0 : -m_index.value(); }
175 EIGEN_STRONG_INLINE
Index colOffset()
const {
return m_index.value()>0 ? m_index.value() : 0; }
177 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(
Index)
const;
178 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(
Index,
Index)
const;
189 template<
typename Derived>
197 template<
typename Derived>
215 template<
typename Derived>
223 template<
typename Derived>
241 template<
typename Derived>
247 return typename DiagonalIndexReturnType<Index_>::Type(derived());
251 template<
typename Derived>
254 inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Index_>::Type
257 return typename ConstDiagonalIndexReturnType<Index_>::Type(derived());
262 #endif // EIGEN_DIAGONAL_H