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 
73  explicit inline Diagonal(MatrixType& matrix, Index a_index = DiagIndex) : m_matrix(matrix), m_index(a_index)
74  {
75  eigen_assert( a_index <= m_matrix.cols() && -a_index <= m_matrix.rows() );
76  }
77 
79 
81  inline Index rows() const
82  {
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());
85  }
86 
88  inline Index cols() const EIGEN_NOEXCEPT { return 1; }
89 
91  inline Index innerStride() const EIGEN_NOEXCEPT {
92  return m_matrix.outerStride() + 1;
93  }
94 
96  inline Index outerStride() const EIGEN_NOEXCEPT { return 0; }
97 
98  typedef typename internal::conditional<
100  Scalar,
101  const Scalar
103 
105  inline ScalarWithConstIfNotLvalue* data() { return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
107  inline const Scalar* data() const { return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
108 
111  {
113  return m_matrix.coeffRef(row+rowOffset(), row+colOffset());
114  }
115 
117  inline const Scalar& coeffRef(Index row, Index) const
118  {
119  return m_matrix.coeffRef(row+rowOffset(), row+colOffset());
120  }
121 
123  inline CoeffReturnType coeff(Index row, Index) const
124  {
125  return m_matrix.coeff(row+rowOffset(), row+colOffset());
126  }
127 
129  inline Scalar& coeffRef(Index idx)
130  {
132  return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset());
133  }
134 
136  inline const Scalar& coeffRef(Index idx) const
137  {
138  return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset());
139  }
140 
142  inline CoeffReturnType coeff(Index idx) const
143  {
144  return m_matrix.coeff(idx+rowOffset(), idx+colOffset());
145  }
146 
150  {
151  return m_matrix;
152  }
153 
155  inline Index index() const
156  {
157  return m_index.value();
158  }
159 
160  protected:
163 
164  private:
165  // some compilers may fail to optimize std::max etc in case of compile-time constants...
167  Index absDiagIndex() const EIGEN_NOEXCEPT { return m_index.value()>0 ? m_index.value() : -m_index.value(); }
169  Index rowOffset() const EIGEN_NOEXCEPT { return m_index.value()>0 ? 0 : -m_index.value(); }
171  Index colOffset() const EIGEN_NOEXCEPT { return m_index.value()>0 ? m_index.value() : 0; }
172  // trigger a compile-time error if someone try to call packet
173  template<int LoadMode> typename MatrixType::PacketReturnType packet(Index) const;
174  template<int LoadMode> typename MatrixType::PacketReturnType packet(Index,Index) const;
175 };
176 
185 template<typename Derived>
188 {
189  return DiagonalReturnType(derived());
190 }
191 
193 template<typename Derived>
196 {
197  return ConstDiagonalReturnType(derived());
198 }
199 
211 template<typename Derived>
214 {
215  return DiagonalDynamicIndexReturnType(derived(), index);
216 }
217 
219 template<typename Derived>
222 {
223  return ConstDiagonalDynamicIndexReturnType(derived(), index);
224 }
225 
237 template<typename Derived>
238 template<int Index_>
242 {
243  return typename DiagonalIndexReturnType<Index_>::Type(derived());
244 }
245 
247 template<typename Derived>
248 template<int Index_>
250 inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Index_>::Type
252 {
253  return typename ConstDiagonalIndexReturnType<Index_>::Type(derived());
254 }
255 
256 } // end namespace Eigen
257 
258 #endif // EIGEN_DIAGONAL_H
Eigen::internal::traits< Diagonal< MatrixType, DiagIndex > >::MatrixTypeNested
ref_selector< MatrixType >::type MatrixTypeNested
Definition: Diagonal.h:40
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen::MatrixBase::ConstDiagonalReturnType
internal::add_const< Diagonal< const Derived > >::type ConstDiagonalReturnType
Definition: MatrixBase.h:209
Eigen::Diagonal::m_matrix
internal::ref_selector< MatrixType >::non_const_type m_matrix
Definition: Diagonal.h:161
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::Diagonal::nestedExpression
const EIGEN_DEVICE_FUNC internal::remove_all< typename MatrixType::Nested >::type & nestedExpression() const
Definition: Diagonal.h:149
Eigen::Diagonal::data
EIGEN_DEVICE_FUNC ScalarWithConstIfNotLvalue * data()
Definition: Diagonal.h:105
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Eigen::internal::dense_xpr_base
Definition: XprHelper.h:483
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
Eigen::Diagonal::rows
EIGEN_DEVICE_FUNC Index rows() const
Definition: Diagonal.h:81
Eigen::internal::is_lvalue
Definition: XprHelper.h:659
Eigen::RowMajorBit
const unsigned int RowMajorBit
Definition: Constants.h:66
ret
DenseIndex ret
Definition: level1_cplx_impl.h:44
Eigen::Diagonal::colOffset
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index colOffset() const EIGEN_NOEXCEPT
Definition: Diagonal.h:171
EIGEN_CONSTEXPR
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
type
Definition: pytypes.h:1491
EIGEN_DENSE_PUBLIC_INTERFACE
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1283
Eigen::Diagonal::coeffRef
EIGEN_DEVICE_FUNC Scalar & coeffRef(Index row, Index)
Definition: Diagonal.h:110
Eigen::DirectAccessBit
const unsigned int DirectAccessBit
Definition: Constants.h:155
Eigen::MatrixBase::ConstDiagonalDynamicIndexReturnType
internal::add_const< Diagonal< const Derived, DynamicIndex > >::type ConstDiagonalDynamicIndexReturnType
Definition: MatrixBase.h:225
Eigen::internal::variable_if_dynamicindex::value
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR T value()
Definition: XprHelper.h:160
EIGEN_PLAIN_ENUM_MIN
#define EIGEN_PLAIN_ENUM_MIN(a, b)
Definition: Macros.h:1288
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::Diagonal::innerStride
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerStride() const EIGEN_NOEXCEPT
Definition: Diagonal.h:91
Eigen::internal::traits< Diagonal< MatrixType, DiagIndex > >::StorageKind
MatrixType::StorageKind StorageKind
Definition: Diagonal.h:42
Eigen::LvalueBit
const unsigned int LvalueBit
Definition: Constants.h:144
Eigen::Diagonal::ScalarWithConstIfNotLvalue
internal::conditional< internal::is_lvalue< MatrixType >::value, Scalar, const Scalar >::type ScalarWithConstIfNotLvalue
Definition: Diagonal.h:102
Eigen::Diagonal::Base
internal::dense_xpr_base< Diagonal >::type Base
Definition: Diagonal.h:69
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
Eigen::Architecture::Type
Type
Definition: Constants.h:471
Eigen::Diagonal::coeffRef
const EIGEN_DEVICE_FUNC Scalar & coeffRef(Index idx) const
Definition: Diagonal.h:136
Eigen::Diagonal
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:63
Eigen::MatrixBase::DiagonalDynamicIndexReturnType
Diagonal< Derived, DynamicIndex > DiagonalDynamicIndexReturnType
Definition: MatrixBase.h:224
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::internal::outer_stride_at_compile_time
Definition: DenseCoeffsBase.h:670
Eigen::Diagonal::index
EIGEN_DEVICE_FUNC Index index() const
Definition: Diagonal.h:155
Eigen::Triplet< double >
Eigen::internal::variable_if_dynamicindex< Index, DiagIndex >
Eigen::internal::ref_selector
Definition: XprHelper.h:416
Eigen::Diagonal::m_index
const internal::variable_if_dynamicindex< Index, DiagIndex > m_index
Definition: Diagonal.h:162
matrix
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: gtsam/3rdparty/Eigen/blas/common.h:110
Eigen::Diagonal::coeff
EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index idx) const
Definition: Diagonal.h:142
Eigen::internal::traits< Diagonal< MatrixType, DiagIndex > >::_MatrixTypeNested
remove_reference< MatrixTypeNested >::type _MatrixTypeNested
Definition: Diagonal.h:41
Eigen::Diagonal::Diagonal
EIGEN_DEVICE_FUNC Diagonal(MatrixType &matrix, Index a_index=DiagIndex)
Definition: Diagonal.h:73
Eigen::MatrixBase::DiagonalReturnType
Diagonal< Derived > DiagonalReturnType
Definition: MatrixBase.h:205
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::Diagonal::rowOffset
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rowOffset() const EIGEN_NOEXCEPT
Definition: Diagonal.h:169
row
m row(1)
Eigen::internal::conditional
Definition: Meta.h:109
EIGEN_PLAIN_ENUM_MAX
#define EIGEN_PLAIN_ENUM_MAX(a, b)
Definition: Macros.h:1289
Eigen::Diagonal::cols
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: Diagonal.h:88
EIGEN_NOEXCEPT
#define EIGEN_NOEXCEPT
Definition: Macros.h:1418
internal
Definition: BandTriangularSolver.h:13
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Eigen::DynamicIndex
const int DynamicIndex
Definition: Constants.h:27
EIGEN_STATIC_ASSERT_LVALUE
#define EIGEN_STATIC_ASSERT_LVALUE(Derived)
Definition: StaticAssert.h:202
Eigen::Diagonal::coeff
EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index) const
Definition: Diagonal.h:123
Eigen::MatrixBase::diagonal
EIGEN_DEVICE_FUNC DiagonalReturnType diagonal()
Definition: Diagonal.h:187
Eigen::Diagonal::coeffRef
EIGEN_DEVICE_FUNC Scalar & coeffRef(Index idx)
Definition: Diagonal.h:129
Eigen::Diagonal::absDiagIndex
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index absDiagIndex() const EIGEN_NOEXCEPT
Definition: Diagonal.h:167
Eigen::Diagonal::data
const EIGEN_DEVICE_FUNC Scalar * data() const
Definition: Diagonal.h:107
EIGEN_INHERIT_ASSIGNMENT_OPERATORS
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Definition: Macros.h:1231
test_callbacks.value
value
Definition: test_callbacks.py:158
EIGEN_SIZE_MIN_PREFER_FIXED
#define EIGEN_SIZE_MIN_PREFER_FIXED(a, b)
Definition: Macros.h:1302
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::Diagonal::coeffRef
const EIGEN_DEVICE_FUNC Scalar & coeffRef(Index row, Index) const
Definition: Diagonal.h:117
Eigen::Diagonal::outerStride
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT
Definition: Diagonal.h:96


gtsam
Author(s):
autogenerated on Thu Jun 13 2024 03:02:13