Diagonal.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_DIAGONAL_H
12 #define EIGEN_DIAGONAL_H
13 
14 namespace Eigen {
15 
35 namespace internal {
36 template<typename MatrixType, int DiagIndex>
37 struct traits<Diagonal<MatrixType,DiagIndex> >
38  : traits<MatrixType>
39 {
42  typedef typename MatrixType::StorageKind StorageKind;
43  enum {
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,
55  Flags = (unsigned int)_MatrixTypeNested::Flags & (RowMajorBit | MaskLvalueBit | DirectAccessBit) & ~RowMajorBit, // FIXME DirectAccessBit should not be handled by expressions
56  MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret,
57  InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1,
58  OuterStrideAtCompileTime = 0
59  };
60 };
61 }
62 
63 template<typename MatrixType, int _DiagIndex> class Diagonal
64  : public internal::dense_xpr_base< Diagonal<MatrixType,_DiagIndex> >::type
65 {
66  public:
67 
68  enum { DiagIndex = _DiagIndex };
71 
72  EIGEN_DEVICE_FUNC
73  explicit inline Diagonal(MatrixType& matrix, Index a_index = DiagIndex) : m_matrix(matrix), m_index(a_index) {}
74 
76 
77  EIGEN_DEVICE_FUNC
78  inline Index rows() const
79  {
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());
82  }
83 
84  EIGEN_DEVICE_FUNC
85  inline Index cols() const { return 1; }
86 
87  EIGEN_DEVICE_FUNC
88  inline Index innerStride() const
89  {
90  return m_matrix.outerStride() + 1;
91  }
92 
93  EIGEN_DEVICE_FUNC
94  inline Index outerStride() const
95  {
96  return 0;
97  }
98 
99  typedef typename internal::conditional<
101  Scalar,
102  const Scalar
104 
105  EIGEN_DEVICE_FUNC
106  inline ScalarWithConstIfNotLvalue* data() { return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
107  EIGEN_DEVICE_FUNC
108  inline const Scalar* data() const { return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
109 
110  EIGEN_DEVICE_FUNC
111  inline Scalar& coeffRef(Index row, Index)
112  {
113  EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
114  return m_matrix.coeffRef(row+rowOffset(), row+colOffset());
115  }
116 
117  EIGEN_DEVICE_FUNC
118  inline const Scalar& coeffRef(Index row, Index) const
119  {
120  return m_matrix.coeffRef(row+rowOffset(), row+colOffset());
121  }
122 
123  EIGEN_DEVICE_FUNC
124  inline CoeffReturnType coeff(Index row, Index) const
125  {
126  return m_matrix.coeff(row+rowOffset(), row+colOffset());
127  }
128 
129  EIGEN_DEVICE_FUNC
130  inline Scalar& coeffRef(Index idx)
131  {
132  EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
133  return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset());
134  }
135 
136  EIGEN_DEVICE_FUNC
137  inline const Scalar& coeffRef(Index idx) const
138  {
139  return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset());
140  }
141 
142  EIGEN_DEVICE_FUNC
143  inline CoeffReturnType coeff(Index idx) const
144  {
145  return m_matrix.coeff(idx+rowOffset(), idx+colOffset());
146  }
147 
148  EIGEN_DEVICE_FUNC
151  {
152  return m_matrix;
153  }
154 
155  EIGEN_DEVICE_FUNC
156  inline Index index() const
157  {
158  return m_index.value();
159  }
160 
161  protected:
164 
165  private:
166  // some compilers may fail to optimize std::max etc in case of compile-time constants...
167  EIGEN_DEVICE_FUNC
168  EIGEN_STRONG_INLINE Index absDiagIndex() const { return m_index.value()>0 ? m_index.value() : -m_index.value(); }
169  EIGEN_DEVICE_FUNC
170  EIGEN_STRONG_INLINE Index rowOffset() const { return m_index.value()>0 ? 0 : -m_index.value(); }
171  EIGEN_DEVICE_FUNC
172  EIGEN_STRONG_INLINE Index colOffset() const { return m_index.value()>0 ? m_index.value() : 0; }
173  // trigger a compile-time error if someone try to call packet
174  template<int LoadMode> typename MatrixType::PacketReturnType packet(Index) const;
175  template<int LoadMode> typename MatrixType::PacketReturnType packet(Index,Index) const;
176 };
177 
186 template<typename Derived>
189 {
190  return DiagonalReturnType(derived());
191 }
192 
194 template<typename Derived>
197 {
198  return ConstDiagonalReturnType(derived());
199 }
200 
212 template<typename Derived>
215 {
216  return DiagonalDynamicIndexReturnType(derived(), index);
217 }
218 
220 template<typename Derived>
223 {
224  return ConstDiagonalDynamicIndexReturnType(derived(), index);
225 }
226 
238 template<typename Derived>
239 template<int Index_>
242 {
243  return typename DiagonalIndexReturnType<Index_>::Type(derived());
244 }
245 
247 template<typename Derived>
248 template<int Index_>
251 {
252  return typename ConstDiagonalIndexReturnType<Index_>::Type(derived());
253 }
254 
255 } // end namespace Eigen
256 
257 #endif // EIGEN_DIAGONAL_H
EIGEN_DEVICE_FUNC Index innerStride() const
Definition: Diagonal.h:88
#define EIGEN_STRONG_INLINE
Definition: Macros.h:493
EIGEN_DEVICE_FUNC Index cols() const
Definition: Diagonal.h:85
EIGEN_DEVICE_FUNC const internal::remove_all< typename MatrixType::Nested >::type & nestedExpression() const
Definition: Diagonal.h:150
const unsigned int DirectAccessBit
Definition: Constants.h:150
const unsigned int LvalueBit
Definition: Constants.h:139
#define EIGEN_PLAIN_ENUM_MAX(a, b)
Definition: Macros.h:873
Definition: LDLT.h:16
const int DynamicIndex
Definition: Constants.h:26
EIGEN_DEVICE_FUNC ScalarWithConstIfNotLvalue * data()
Definition: Diagonal.h:106
internal::conditional< internal::is_lvalue< MatrixType >::value, Scalar, const Scalar >::type ScalarWithConstIfNotLvalue
Definition: Diagonal.h:103
EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: Diagonal.h:108
const unsigned int RowMajorBit
Definition: Constants.h:61
#define EIGEN_SIZE_MIN_PREFER_FIXED(a, b)
Definition: Macros.h:886
EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index) const
Definition: Diagonal.h:124
#define EIGEN_STATIC_ASSERT_LVALUE(Derived)
Definition: StaticAssert.h:197
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index absDiagIndex() const
Definition: Diagonal.h:168
EIGEN_DEVICE_FUNC Scalar & coeffRef(Index row, Index)
Definition: Diagonal.h:111
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T value()
Definition: XprHelper.h:132
EIGEN_DEVICE_FUNC Index index() const
Definition: Diagonal.h:156
EIGEN_DEVICE_FUNC Index outerStride() const
Definition: Diagonal.h:94
remove_reference< MatrixTypeNested >::type _MatrixTypeNested
Definition: Diagonal.h:41
ref_selector< MatrixType >::type MatrixTypeNested
Definition: Diagonal.h:40
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
internal::dense_xpr_base< Diagonal >::type Base
Definition: Diagonal.h:69
EIGEN_DEVICE_FUNC RowXpr row(Index i)
This is the const version of row(). */.
Definition: BlockMethods.h:859
EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index idx) const
Definition: Diagonal.h:143
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rowOffset() const
Definition: Diagonal.h:170
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Definition: Macros.h:839
EIGEN_DEVICE_FUNC Index rows() const
Definition: Diagonal.h:78
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index colOffset() const
Definition: Diagonal.h:172
#define EIGEN_PLAIN_ENUM_MIN(a, b)
Definition: Macros.h:872
const internal::variable_if_dynamicindex< Index, DiagIndex > m_index
Definition: Diagonal.h:163
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:867
EIGEN_DEVICE_FUNC const Scalar & coeffRef(Index row, Index) const
Definition: Diagonal.h:118
EIGEN_DEVICE_FUNC DiagonalReturnType diagonal()
Definition: Diagonal.h:188
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:63
const int Dynamic
Definition: Constants.h:21
EIGEN_DEVICE_FUNC Scalar & coeffRef(Index idx)
Definition: Diagonal.h:130
internal::ref_selector< MatrixType >::non_const_type m_matrix
Definition: Diagonal.h:162
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
EIGEN_DEVICE_FUNC const Scalar & coeffRef(Index idx) const
Definition: Diagonal.h:137


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:10