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 nested<MatrixType>::type MatrixTypeNested;
41 typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
42 typedef typename MatrixType::StorageKind StorageKind;
44 RowsAtCompileTime = (int(DiagIndex) ==
Dynamic || 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 ==
Dynamic ? 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 CoeffReadCost = _MatrixTypeNested::CoeffReadCost,
57 MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret,
58 InnerStrideAtCompileTime = MatrixTypeOuterStride ==
Dynamic ?
Dynamic : MatrixTypeOuterStride+1,
59 OuterStrideAtCompileTime = 0
64 template<
typename MatrixType,
int DiagIndex>
class Diagonal
65 :
public internal::dense_xpr_base< Diagonal<MatrixType,DiagIndex> >::type
69 typedef typename internal::dense_xpr_base<Diagonal>::type Base;
70 EIGEN_DENSE_PUBLIC_INTERFACE(
Diagonal)
72 inline Diagonal(MatrixType& matrix, Index index = DiagIndex) : m_matrix(matrix), m_index(index) {}
74 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Diagonal)
76 inline Index rows()
const
77 {
return m_index.value()<0 ? (std::min)(m_matrix.cols(),m_matrix.rows()+m_index.value()) : (std::min)(m_matrix.rows(),m_matrix.cols()-m_index.value()); }
79 inline Index cols()
const {
return 1; }
81 inline Index innerStride()
const
83 return m_matrix.outerStride() + 1;
86 inline Index outerStride()
const
91 typedef typename internal::conditional<
92 internal::is_lvalue<MatrixType>::value,
95 >::type ScalarWithConstIfNotLvalue;
97 inline ScalarWithConstIfNotLvalue* data() {
return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
98 inline const Scalar* data()
const {
return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
100 inline Scalar& coeffRef(Index row, Index)
102 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
103 return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
106 inline const Scalar& coeffRef(Index row, Index)
const
108 return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
111 inline CoeffReturnType coeff(Index row, Index)
const
113 return m_matrix.coeff(row+rowOffset(), row+colOffset());
116 inline Scalar& coeffRef(Index index)
118 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
119 return m_matrix.const_cast_derived().coeffRef(index+rowOffset(), index+colOffset());
122 inline const Scalar& coeffRef(Index index)
const
124 return m_matrix.const_cast_derived().coeffRef(index+rowOffset(), index+colOffset());
127 inline CoeffReturnType coeff(Index index)
const
129 return m_matrix.coeff(index+rowOffset(), index+colOffset());
132 const typename internal::remove_all<typename MatrixType::Nested>::type&
133 nestedExpression()
const
140 return m_index.value();
144 typename MatrixType::Nested m_matrix;
145 const internal::variable_if_dynamic<Index, DiagIndex> m_index;
149 EIGEN_STRONG_INLINE Index absDiagIndex()
const {
return m_index.value()>0 ? m_index.value() : -m_index.value(); }
150 EIGEN_STRONG_INLINE Index rowOffset()
const {
return m_index.value()>0 ? 0 : -m_index.value(); }
151 EIGEN_STRONG_INLINE Index colOffset()
const {
return m_index.value()>0 ? m_index.value() : 0; }
153 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(Index)
const;
154 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(Index,Index)
const;
165 template<
typename Derived>
173 template<
typename Derived>
191 template<
typename Derived>
199 template<
typename Derived>
217 template<
typename Derived>
226 template<
typename Derived>
228 inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Index>::Type
236 #endif // EIGEN_DIAGONAL_H