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;
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 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 enum { DiagIndex = _DiagIndex };
70 typedef typename internal::dense_xpr_base<Diagonal>::type Base;
71 EIGEN_DENSE_PUBLIC_INTERFACE(
Diagonal)
73 inline Diagonal(MatrixType& matrix, Index a_index = DiagIndex) : m_matrix(matrix), m_index(a_index) {}
75 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Diagonal)
77 inline Index rows()
const
78 {
return m_index.value()<0 ? (std::min<Index>)(m_matrix.cols(),m_matrix.rows()+m_index.value()) : (std::min<Index>)(m_matrix.rows(),m_matrix.cols()-m_index.value()); }
80 inline Index cols()
const {
return 1; }
82 inline Index innerStride()
const
84 return m_matrix.outerStride() + 1;
87 inline Index outerStride()
const
92 typedef typename internal::conditional<
93 internal::is_lvalue<MatrixType>::value,
96 >::type ScalarWithConstIfNotLvalue;
98 inline ScalarWithConstIfNotLvalue* data() {
return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
99 inline const Scalar* data()
const {
return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
101 inline Scalar& coeffRef(Index row, Index)
103 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
104 return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
107 inline const Scalar& coeffRef(Index row, Index)
const
109 return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
112 inline CoeffReturnType coeff(Index row, Index)
const
114 return m_matrix.coeff(row+rowOffset(), row+colOffset());
117 inline Scalar& coeffRef(Index idx)
119 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
120 return m_matrix.const_cast_derived().coeffRef(idx+rowOffset(), idx+colOffset());
123 inline const Scalar& coeffRef(Index idx)
const
125 return m_matrix.const_cast_derived().coeffRef(idx+rowOffset(), idx+colOffset());
128 inline CoeffReturnType coeff(Index idx)
const
130 return m_matrix.coeff(idx+rowOffset(), idx+colOffset());
133 const typename internal::remove_all<typename MatrixType::Nested>::type&
134 nestedExpression()
const
141 return m_index.value();
145 typename MatrixType::Nested m_matrix;
146 const internal::variable_if_dynamicindex<Index, DiagIndex> m_index;
150 EIGEN_STRONG_INLINE Index absDiagIndex()
const {
return m_index.value()>0 ? m_index.value() : -m_index.value(); }
151 EIGEN_STRONG_INLINE Index rowOffset()
const {
return m_index.value()>0 ? 0 : -m_index.value(); }
152 EIGEN_STRONG_INLINE Index colOffset()
const {
return m_index.value()>0 ? m_index.value() : 0; }
154 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(Index)
const;
155 template<
int LoadMode>
typename MatrixType::PacketReturnType packet(Index,Index)
const;
166 template<
typename Derived>
174 template<
typename Derived>
192 template<
typename Derived>
200 template<
typename Derived>
218 template<
typename Derived>
227 template<
typename Derived>
229 inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Index>::Type
237 #endif // EIGEN_DIAGONAL_H
const int DynamicIndex
Definition: Constants.h:26
Expression of the transpose of a matrix.
Definition: Transpose.h:57
const int Dynamic
Definition: Constants.h:21
const unsigned int LinearAccessBit
Definition: Constants.h:117
const unsigned int LvalueBit
Definition: Constants.h:131
DiagonalReturnType diagonal()
Definition: Diagonal.h:168
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:60
const unsigned int RowMajorBit
Definition: Constants.h:53
const unsigned int DirectAccessBit
Definition: Constants.h:142
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:64
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48