IndexedView.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) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_INDEXED_VIEW_H
11 #define EIGEN_INDEXED_VIEW_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
17 template<typename XprType, typename RowIndices, typename ColIndices>
18 struct traits<IndexedView<XprType, RowIndices, ColIndices> >
19  : traits<XprType>
20 {
21  enum {
22  RowsAtCompileTime = int(array_size<RowIndices>::value),
23  ColsAtCompileTime = int(array_size<ColIndices>::value),
24  MaxRowsAtCompileTime = RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime) : Dynamic,
25  MaxColsAtCompileTime = ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime) : Dynamic,
26 
27  XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0,
28  IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
29  : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
30  : XprTypeIsRowMajor,
31 
32  RowIncr = int(get_compile_time_incr<RowIndices>::value),
33  ColIncr = int(get_compile_time_incr<ColIndices>::value),
34  InnerIncr = IsRowMajor ? ColIncr : RowIncr,
35  OuterIncr = IsRowMajor ? RowIncr : ColIncr,
36 
37  HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
38  XprInnerStride = HasSameStorageOrderAsXprType ? int(inner_stride_at_compile_time<XprType>::ret) : int(outer_stride_at_compile_time<XprType>::ret),
39  XprOuterstride = HasSameStorageOrderAsXprType ? int(outer_stride_at_compile_time<XprType>::ret) : int(inner_stride_at_compile_time<XprType>::ret),
40 
41  InnerSize = XprTypeIsRowMajor ? ColsAtCompileTime : RowsAtCompileTime,
42  IsBlockAlike = InnerIncr==1 && OuterIncr==1,
43  IsInnerPannel = HasSameStorageOrderAsXprType && is_same<AllRange<InnerSize>,typename conditional<XprTypeIsRowMajor,ColIndices,RowIndices>::type>::value,
44 
45  InnerStrideAtCompileTime = InnerIncr<0 || InnerIncr==DynamicIndex || XprInnerStride==Dynamic ? Dynamic : XprInnerStride * InnerIncr,
46  OuterStrideAtCompileTime = OuterIncr<0 || OuterIncr==DynamicIndex || XprOuterstride==Dynamic ? Dynamic : XprOuterstride * OuterIncr,
47 
48  ReturnAsScalar = is_same<RowIndices,SingleRange>::value && is_same<ColIndices,SingleRange>::value,
49  ReturnAsBlock = (!ReturnAsScalar) && IsBlockAlike,
50  ReturnAsIndexedView = (!ReturnAsScalar) && (!ReturnAsBlock),
51 
52  // FIXME we deal with compile-time strides if and only if we have DirectAccessBit flag,
53  // but this is too strict regarding negative strides...
54  DirectAccessMask = (int(InnerIncr)!=UndefinedIncr && int(OuterIncr)!=UndefinedIncr && InnerIncr>=0 && OuterIncr>=0) ? DirectAccessBit : 0,
55  FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0,
56  FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
57  FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
58  Flags = (traits<XprType>::Flags & (HereditaryBits | DirectAccessMask )) | FlagsLvalueBit | FlagsRowMajorBit | FlagsLinearAccessBit
59  };
60 
62 };
63 
64 }
65 
66 template<typename XprType, typename RowIndices, typename ColIndices, typename StorageKind>
68 
69 
108 template<typename XprType, typename RowIndices, typename ColIndices>
109 class IndexedView : public IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>
110 {
111 public:
115 
116  typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested;
117  typedef typename internal::remove_all<XprType>::type NestedExpression;
118 
119  template<typename T0, typename T1>
120  IndexedView(XprType& xpr, const T0& rowIndices, const T1& colIndices)
121  : m_xpr(xpr), m_rowIndices(rowIndices), m_colIndices(colIndices)
122  {}
123 
125  Index rows() const { return internal::size(m_rowIndices); }
126 
128  Index cols() const { return internal::size(m_colIndices); }
129 
132  nestedExpression() const { return m_xpr; }
133 
136  nestedExpression() { return m_xpr; }
137 
139  const RowIndices& rowIndices() const { return m_rowIndices; }
140 
142  const ColIndices& colIndices() const { return m_colIndices; }
143 
144 protected:
146  RowIndices m_rowIndices;
147  ColIndices m_colIndices;
148 };
149 
150 
151 // Generic API dispatcher
152 template<typename XprType, typename RowIndices, typename ColIndices, typename StorageKind>
153 class IndexedViewImpl
154  : public internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type
155 {
156 public:
158 };
159 
160 namespace internal {
161 
162 
163 template<typename ArgType, typename RowIndices, typename ColIndices>
164 struct unary_evaluator<IndexedView<ArgType, RowIndices, ColIndices>, IndexBased>
165  : evaluator_base<IndexedView<ArgType, RowIndices, ColIndices> >
166 {
168 
169  enum {
170  CoeffReadCost = evaluator<ArgType>::CoeffReadCost /* TODO + cost of row/col index */,
171 
173 
175 
176  Flags = (evaluator<ArgType>::Flags & (HereditaryBits & ~RowMajorBit /*| LinearAccessBit | DirectAccessBit*/)) | FlagsLinearAccessBit | FlagsRowMajorBit,
177 
178  Alignment = 0
179  };
180 
181  EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr)
182  {
183  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
184  }
185 
186  typedef typename XprType::Scalar Scalar;
187  typedef typename XprType::CoeffReturnType CoeffReturnType;
188 
191  {
192  return m_argImpl.coeff(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
193  }
194 
197  {
198  return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
199  }
200 
203  {
205  Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
206  Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
207  return m_argImpl.coeffRef( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
208  }
209 
211  const Scalar& coeffRef(Index index) const
212  {
213  Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
214  Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
215  return m_argImpl.coeffRef( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
216  }
217 
219  const CoeffReturnType coeff(Index index) const
220  {
221  Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
222  Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
223  return m_argImpl.coeff( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
224  }
225 
226 protected:
227 
229  const XprType& m_xpr;
230 
231 };
232 
233 } // end namespace internal
234 
235 } // end namespace Eigen
236 
237 #endif // EIGEN_INDEXED_VIEW_H
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
col
m col(1)
Eigen::Block
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
Eigen::internal::traits< IndexedView< XprType, RowIndices, ColIndices > >::BlockType
Block< XprType, RowsAtCompileTime, ColsAtCompileTime, IsInnerPannel > BlockType
Definition: IndexedView.h:61
Eigen::UndefinedIncr
const int UndefinedIncr
Definition: Constants.h:31
Eigen::internal::unary_evaluator< IndexedView< ArgType, RowIndices, ColIndices >, IndexBased >::coeff
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const
Definition: IndexedView.h:190
Eigen::CwiseBinaryOp
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
Eigen::IndexedViewImpl::Base
internal::generic_xpr_base< IndexedView< XprType, RowIndices, ColIndices > >::type Base
Definition: IndexedView.h:157
Eigen::IndexedViewImpl
Definition: IndexedView.h:67
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
type
Definition: pytypes.h:1525
Eigen::IndexedView::m_xpr
MatrixTypeNested m_xpr
Definition: IndexedView.h:145
Eigen::IndexedView
Expression of a non-sequential sub-matrix defined by arbitrary sequences of row and column indices.
Definition: IndexedView.h:109
Eigen::internal::unary_evaluator< IndexedView< ArgType, RowIndices, ColIndices >, IndexBased >::Scalar
XprType::Scalar Scalar
Definition: IndexedView.h:186
Eigen::internal::evaluator_base
Definition: CoreEvaluators.h:110
Eigen::IndexedView::nestedExpression
const internal::remove_all< XprType >::type & nestedExpression() const
Definition: IndexedView.h:132
Eigen::DirectAccessBit
const unsigned int DirectAccessBit
Definition: Constants.h:155
Eigen::internal::SingleRange
Definition: IndexedViewHelper.h:97
Eigen::internal::unary_evaluator< IndexedView< ArgType, RowIndices, ColIndices >, IndexBased >::coeffRef
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Scalar & coeffRef(Index index) const
Definition: IndexedView.h:211
Eigen::internal::AllRange
Definition: IndexedViewHelper.h:141
Eigen::internal::true_type
Definition: Meta.h:96
EIGEN_GENERIC_PUBLIC_INTERFACE
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1264
Eigen::IndexedView::m_colIndices
ColIndices m_colIndices
Definition: IndexedView.h:147
Eigen::LvalueBit
const unsigned int LvalueBit
Definition: Constants.h:144
Eigen::internal::unary_evaluator< IndexedView< ArgType, RowIndices, ColIndices >, IndexBased >::coeffRef
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index row, Index col)
Definition: IndexedView.h:196
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
Eigen::IndexedView::rowIndices
const RowIndices & rowIndices() const
Definition: IndexedView.h:139
Eigen::internal::generic_xpr_base
Definition: XprHelper.h:501
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::IndexedView::m_rowIndices
RowIndices m_rowIndices
Definition: IndexedView.h:146
Eigen::internal::outer_stride_at_compile_time
Definition: DenseCoeffsBase.h:670
Eigen::IndexedView::nestedExpression
internal::remove_reference< XprType >::type & nestedExpression()
Definition: IndexedView.h:136
Eigen::Triplet< double >
Eigen::internal::unary_evaluator< IndexedView< ArgType, RowIndices, ColIndices >, IndexBased >::m_xpr
const XprType & m_xpr
Definition: IndexedView.h:229
Eigen::internal::evaluator
Definition: CoreEvaluators.h:90
Eigen::internal::unary_evaluator< IndexedView< ArgType, RowIndices, ColIndices >, IndexBased >::m_argImpl
evaluator< ArgType > m_argImpl
Definition: IndexedView.h:228
Eigen::internal::array_size
Definition: Meta.h:445
Eigen::internal::inner_stride_at_compile_time
Definition: DenseCoeffsBase.h:658
Eigen::LinearAccessBit
const unsigned int LinearAccessBit
Definition: Constants.h:130
Eigen::IndexedView::Base
IndexedViewImpl< XprType, RowIndices, ColIndices, typename internal::traits< XprType >::StorageKind >::Base Base
Definition: IndexedView.h:112
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::IndexedView::cols
Index cols() const
Definition: IndexedView.h:128
Eigen::internal::unary_evaluator< IndexedView< ArgType, RowIndices, ColIndices >, IndexBased >::unary_evaluator
EIGEN_DEVICE_FUNC unary_evaluator(const XprType &xpr)
Definition: IndexedView.h:181
row
m row(1)
Eigen::internal::conditional
Definition: Meta.h:109
Eigen::internal::unary_evaluator< IndexedView< ArgType, RowIndices, ColIndices >, IndexBased >::CoeffReturnType
XprType::CoeffReturnType CoeffReturnType
Definition: IndexedView.h:187
Eigen::internal::unary_evaluator
Definition: CoreEvaluators.h:65
Eigen::internal::unary_evaluator< IndexedView< ArgType, RowIndices, ColIndices >, IndexBased >::coeff
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition: IndexedView.h:219
Eigen::internal::is_same
Definition: Meta.h:148
internal
Definition: BandTriangularSolver.h:13
Eigen::DynamicIndex
const int DynamicIndex
Definition: Constants.h:27
EIGEN_STATIC_ASSERT_LVALUE
#define EIGEN_STATIC_ASSERT_LVALUE(Derived)
Definition: StaticAssert.h:202
Eigen::internal::size
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
T1
static const Similarity3 T1(R, Point3(3.5, -8.2, 4.2), 1)
EIGEN_INTERNAL_CHECK_COST_VALUE
#define EIGEN_INTERNAL_CHECK_COST_VALUE(C)
Definition: StaticAssert.h:218
Eigen::HereditaryBits
const unsigned int HereditaryBits
Definition: Constants.h:195
Eigen::internal::unary_evaluator< IndexedView< ArgType, RowIndices, ColIndices >, IndexBased >::XprType
IndexedView< ArgType, RowIndices, ColIndices > XprType
Definition: IndexedView.h:167
Eigen::internal::unary_evaluator< IndexedView< ArgType, RowIndices, ColIndices >, IndexBased >::coeffRef
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index index)
Definition: IndexedView.h:202
Eigen::internal::IndexBased
Definition: Constants.h:542
Eigen::IndexedView::rows
Index rows() const
Definition: IndexedView.h:125
EIGEN_INHERIT_ASSIGNMENT_OPERATORS
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Definition: Macros.h:1231
Eigen::IndexedView::colIndices
const ColIndices & colIndices() const
Definition: IndexedView.h:142
test_callbacks.value
value
Definition: test_callbacks.py:160
Eigen::internal::get_compile_time_incr
Definition: IndexedViewHelper.h:75
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


gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:01:17