IndexedViewMethods.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 #if !defined(EIGEN_PARSED_BY_DOXYGEN)
11 
12 // This file is automatically included twice to generate const and non-const versions
13 
14 #ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
15 #define EIGEN_INDEXED_VIEW_METHOD_CONST const
16 #define EIGEN_INDEXED_VIEW_METHOD_TYPE ConstIndexedViewType
17 #else
18 #define EIGEN_INDEXED_VIEW_METHOD_CONST
19 #define EIGEN_INDEXED_VIEW_METHOD_TYPE IndexedViewType
20 #endif
21 
22 #ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
23 protected:
24 
25 // define some aliases to ease readability
26 
27 template<typename Indices>
28 struct IvcRowType : public internal::IndexedViewCompatibleType<Indices,RowsAtCompileTime> {};
29 
30 template<typename Indices>
31 struct IvcColType : public internal::IndexedViewCompatibleType<Indices,ColsAtCompileTime> {};
32 
33 template<typename Indices>
34 struct IvcType : public internal::IndexedViewCompatibleType<Indices,SizeAtCompileTime> {};
35 
37 
38 template<typename Indices>
40 ivcRow(const Indices& indices) const {
41  return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,RowsAtCompileTime>(derived().rows()),Specialized);
42 }
43 
44 template<typename Indices>
46 ivcCol(const Indices& indices) const {
47  return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,ColsAtCompileTime>(derived().cols()),Specialized);
48 }
49 
50 template<typename Indices>
52 ivcSize(const Indices& indices) const {
53  return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,SizeAtCompileTime>(derived().size()),Specialized);
54 }
55 
56 public:
57 
58 #endif
59 
60 template<typename RowIndices, typename ColIndices>
62  typedef IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,
65 };
66 
67 // This is the generic version
68 
69 template<typename RowIndices, typename ColIndices>
73 operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
74 {
76  (derived(), ivcRow(rowIndices), ivcCol(colIndices));
77 }
78 
79 // The following overload returns a Block<> object
80 
81 template<typename RowIndices, typename ColIndices>
85 operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
86 {
88  typename IvcRowType<RowIndices>::type actualRowIndices = ivcRow(rowIndices);
89  typename IvcColType<ColIndices>::type actualColIndices = ivcCol(colIndices);
90  return BlockType(derived(),
91  internal::first(actualRowIndices),
92  internal::first(actualColIndices),
93  internal::size(actualRowIndices),
94  internal::size(actualColIndices));
95 }
96 
97 // The following overload returns a Scalar
98 
99 template<typename RowIndices, typename ColIndices>
102  CoeffReturnType >::type
103 operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
104 {
106 }
107 
108 #if EIGEN_HAS_STATIC_ARRAY_TEMPLATE
109 
110 // The following three overloads are needed to handle raw Index[N] arrays.
111 
112 template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndices>
113 IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename IvcColType<ColIndices>::type>
114 operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
115 {
116  return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename IvcColType<ColIndices>::type>
117  (derived(), rowIndices, ivcCol(colIndices));
118 }
119 
120 template<typename RowIndices, typename ColIndicesT, std::size_t ColIndicesN>
122 operator()(const RowIndices& rowIndices, const ColIndicesT (&colIndices)[ColIndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
123 {
125  (derived(), ivcRow(rowIndices), colIndices);
126 }
127 
128 template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndicesT, std::size_t ColIndicesN>
129 IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN], const ColIndicesT (&)[ColIndicesN]>
130 operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndicesT (&colIndices)[ColIndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
131 {
132  return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],const ColIndicesT (&)[ColIndicesN]>
133  (derived(), rowIndices, colIndices);
134 }
135 
136 #endif // EIGEN_HAS_STATIC_ARRAY_TEMPLATE
137 
138 // Overloads for 1D vectors/arrays
139 
140 template<typename Indices>
141 typename internal::enable_if<
145 {
148  (derived(), IvcIndex(0), ivcCol(indices));
149 }
150 
151 template<typename Indices>
152 typename internal::enable_if<
153  (!IsRowMajor) && (!(internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1 || internal::is_valid_index_type<Indices>::value)),
156 {
159  (derived(), ivcRow(indices), IvcIndex(0));
160 }
161 
162 template<typename Indices>
163 typename internal::enable_if<
167 {
169  typename IvcType<Indices>::type actualIndices = ivcSize(indices);
171  (derived(), internal::first(actualIndices), internal::size(actualIndices));
172 }
173 
174 template<typename IndexType>
177 {
179 }
180 
181 #if EIGEN_HAS_STATIC_ARRAY_TEMPLATE
182 
183 template<typename IndicesT, std::size_t IndicesN>
184 typename internal::enable_if<IsRowMajor,
185  IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,const IndicesT (&)[IndicesN]> >::type
186 operator()(const IndicesT (&indices)[IndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
187 {
189  return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,const IndicesT (&)[IndicesN]>
190  (derived(), IvcIndex(0), indices);
191 }
192 
193 template<typename IndicesT, std::size_t IndicesN>
194 typename internal::enable_if<!IsRowMajor,
195  IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const IndicesT (&)[IndicesN],IvcIndex> >::type
196 operator()(const IndicesT (&indices)[IndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
197 {
199  return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const IndicesT (&)[IndicesN],IvcIndex>
200  (derived(), indices, IvcIndex(0));
201 }
202 
203 #endif // EIGEN_HAS_STATIC_ARRAY_TEMPLATE
204 
205 #undef EIGEN_INDEXED_VIEW_METHOD_CONST
206 #undef EIGEN_INDEXED_VIEW_METHOD_TYPE
207 
208 #ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
209 #define EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
210 #include "IndexedViewMethods.h"
211 #undef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
212 #endif
213 
214 #else // EIGEN_PARSED_BY_DOXYGEN
215 
250 template<typename RowIndices, typename ColIndices>
251 IndexedView_or_Block
252 operator()(const RowIndices& rowIndices, const ColIndices& colIndices);
253 
258 template<typename Indices>
259 IndexedView_or_VectorBlock
260 operator()(const Indices& indices);
261 
262 #endif // EIGEN_PARSED_BY_DOXYGEN
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
Eigen::internal::eval_expr_given_size
Index eval_expr_given_size(Index x, Index)
Definition: IndexedViewHelper.h:63
ivcCol
IvcColType< Indices >::type ivcCol(const Indices &indices) const
Definition: IndexedViewMethods.h:46
type
Definition: pytypes.h:1525
EIGEN_STATIC_ASSERT_VECTOR_ONLY
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:142
Eigen::internal::makeIndexedViewCompatible
ArithmeticSequence< Index, typename make_size_type< SizeType >::type, IncrType > makeIndexedViewCompatible(const ArithmeticSequence< FirstType, SizeType, IncrType > &ids, Index size, SpecializedType)
Definition: ArithmeticSequence.h:366
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
EIGEN_INDEXED_VIEW_METHOD_CONST
#define EIGEN_INDEXED_VIEW_METHOD_CONST
Definition: IndexedViewMethods.h:15
test_eigen_tensor.indices
indices
Definition: test_eigen_tensor.py:33
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
operator()
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
Definition: IndexedViewMethods.h:73
ivcRow
IvcRowType< Indices >::type ivcRow(const Indices &indices) const
Definition: IndexedViewMethods.h:40
IndexedViewMethods.h
Eigen::Specialized
@ Specialized
Definition: Constants.h:310
EIGEN_INDEXED_VIEW_METHOD_TYPE::type
IndexedView< EIGEN_INDEXED_VIEW_METHOD_CONST Derived, typename IvcRowType< RowIndices >::type, typename IvcColType< ColIndices >::type > type
Definition: IndexedViewMethods.h:64
IvcIndex
internal::IndexedViewCompatibleType< Index, 1 >::type IvcIndex
Definition: IndexedViewMethods.h:36
IvcType
Definition: IndexedViewMethods.h:34
IvcColType
Definition: IndexedViewMethods.h:31
EIGEN_INDEXED_VIEW_METHOD_TYPE
Definition: IndexedViewMethods.h:61
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
Indices
std::vector< size_t > Indices
Definition: testPartialPriorFactor.cpp:37
IvcRowType
Definition: IndexedViewMethods.h:28
test_callbacks.value
value
Definition: test_callbacks.py:160
ivcSize
IvcColType< Indices >::type ivcSize(const Indices &indices) const
Definition: IndexedViewMethods.h:52


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:28