WPILibC++ 2023.4.3-108-ge5452e3
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
23protected:
24
25// define some aliases to ease readability
26
27template<typename Indices>
28struct IvcRowType : public internal::IndexedViewCompatibleType<Indices,RowsAtCompileTime> {};
29
30template<typename Indices>
31struct IvcColType : public internal::IndexedViewCompatibleType<Indices,ColsAtCompileTime> {};
32
33template<typename Indices>
34struct IvcType : public internal::IndexedViewCompatibleType<Indices,SizeAtCompileTime> {};
35
37
38template<typename Indices>
40ivcRow(const Indices& indices) const {
41 return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,RowsAtCompileTime>(derived().rows()),Specialized);
42}
43
44template<typename Indices>
46ivcCol(const Indices& indices) const {
47 return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,ColsAtCompileTime>(derived().cols()),Specialized);
48}
49
50template<typename Indices>
52ivcSize(const Indices& indices) const {
53 return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,SizeAtCompileTime>(derived().size()),Specialized);
54}
55
56public:
57
58#endif
59
60template<typename RowIndices, typename ColIndices>
62 typedef IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,
65};
66
67// This is the generic version
68
69template<typename RowIndices, typename ColIndices>
70typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value
73operator()(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
81template<typename RowIndices, typename ColIndices>
82typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value
85operator()(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
99template<typename RowIndices, typename ColIndices>
100typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value
102 CoeffReturnType >::type
103operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
104{
105 return Base::operator()(internal::eval_expr_given_size(rowIndices,rows()),internal::eval_expr_given_size(colIndices,cols()));
106}
107
108#if EIGEN_HAS_STATIC_ARRAY_TEMPLATE
109
110// The following three overloads are needed to handle raw Index[N] arrays.
111
112template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndices>
113IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename IvcColType<ColIndices>::type>
114operator()(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
120template<typename RowIndices, typename ColIndicesT, std::size_t ColIndicesN>
122operator()(const RowIndices& rowIndices, const ColIndicesT (&colIndices)[ColIndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
123{
125 (derived(), ivcRow(rowIndices), colIndices);
126}
127
128template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndicesT, std::size_t ColIndicesN>
129IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN], const ColIndicesT (&)[ColIndicesN]>
130operator()(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
140template<typename Indices>
141typename internal::enable_if<
142 IsRowMajor && (!(internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1 || internal::is_valid_index_type<Indices>::value)),
145{
148 (derived(), IvcIndex(0), ivcCol(indices));
149}
150
151template<typename Indices>
152typename internal::enable_if<
153 (!IsRowMajor) && (!(internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1 || internal::is_valid_index_type<Indices>::value)),
155operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST
156{
159 (derived(), ivcRow(indices), IvcIndex(0));
160}
161
162template<typename Indices>
163typename internal::enable_if<
164 (internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1) && (!internal::is_valid_index_type<Indices>::value) && (!symbolic::is_symbolic<Indices>::value),
165 VectorBlock<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,internal::array_size<Indices>::value> >::type
166operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST
167{
169 typename IvcType<Indices>::type actualIndices = ivcSize(indices);
170 return VectorBlock<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,internal::array_size<Indices>::value>
171 (derived(), internal::first(actualIndices), internal::size(actualIndices));
172}
173
174template<typename IndexType>
175typename internal::enable_if<symbolic::is_symbolic<IndexType>::value, CoeffReturnType >::type
177{
179}
180
181#if EIGEN_HAS_STATIC_ARRAY_TEMPLATE
182
183template<typename IndicesT, std::size_t IndicesN>
184typename internal::enable_if<IsRowMajor,
185 IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,const IndicesT (&)[IndicesN]> >::type
186operator()(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
193template<typename IndicesT, std::size_t IndicesN>
194typename internal::enable_if<!IsRowMajor,
195 IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const IndicesT (&)[IndicesN],IvcIndex> >::type
196operator()(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
216/**
217 * \returns a generic submatrix view defined by the rows and columns indexed \a rowIndices and \a colIndices respectively.
218 *
219 * Each parameter must either be:
220 * - An integer indexing a single row or column
221 * - Eigen::all indexing the full set of respective rows or columns in increasing order
222 * - An ArithmeticSequence as returned by the Eigen::seq and Eigen::seqN functions
223 * - Any %Eigen's vector/array of integers or expressions
224 * - Plain C arrays: \c int[N]
225 * - And more generally any type exposing the following two member functions:
226 * \code
227 * <integral type> operator[](<integral type>) const;
228 * <integral type> size() const;
229 * \endcode
230 * where \c <integral \c type> stands for any integer type compatible with Eigen::Index (i.e. \c std::ptrdiff_t).
231 *
232 * The last statement implies compatibility with \c std::vector, \c std::valarray, \c std::array, many of the Range-v3's ranges, etc.
233 *
234 * If the submatrix can be represented using a starting position \c (i,j) and positive sizes \c (rows,columns), then this
235 * method will returns a Block object after extraction of the relevant information from the passed arguments. This is the case
236 * when all arguments are either:
237 * - An integer
238 * - Eigen::all
239 * - An ArithmeticSequence with compile-time increment strictly equal to 1, as returned by Eigen::seq(a,b), and Eigen::seqN(a,N).
240 *
241 * Otherwise a more general IndexedView<Derived,RowIndices',ColIndices'> object will be returned, after conversion of the inputs
242 * to more suitable types \c RowIndices' and \c ColIndices'.
243 *
244 * For 1D vectors and arrays, you better use the operator()(const Indices&) overload, which behave the same way but taking a single parameter.
245 *
246 * See also this <a href="https://stackoverflow.com/questions/46110917/eigen-replicate-items-along-one-dimension-without-useless-allocations">question</a> and its answer for an example of how to duplicate coefficients.
247 *
248 * \sa operator()(const Indices&), class Block, class IndexedView, DenseBase::block(Index,Index,Index,Index)
249 */
250template<typename RowIndices, typename ColIndices>
251IndexedView_or_Block
252operator()(const RowIndices& rowIndices, const ColIndices& colIndices);
253
254/** This is an overload of operator()(const RowIndices&, const ColIndices&) for 1D vectors or arrays
255 *
256 * \only_for_vectors
257 */
258template<typename Indices>
259IndexedView_or_VectorBlock
260operator()(const Indices& indices);
261
262#endif // EIGEN_PARSED_BY_DOXYGEN
IvcColType< Indices >::type ivcSize(const Indices &indices) const
Definition: IndexedViewMethods.h:52
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typenameEIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typenameEIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
Definition: IndexedViewMethods.h:73
#define EIGEN_INDEXED_VIEW_METHOD_CONST
Definition: IndexedViewMethods.h:15
IvcRowType< Indices >::type ivcRow(const Indices &indices) const
Definition: IndexedViewMethods.h:40
IvcColType< Indices >::type ivcCol(const Indices &indices) const
Definition: IndexedViewMethods.h:46
internal::IndexedViewCompatibleType< Index, 1 >::type IvcIndex
Definition: IndexedViewMethods.h:36
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:142
Definition: core.h:1240
type
Definition: core.h:575
ArithmeticSequence< Index, typename make_size_type< SizeType >::type, IncrType > makeIndexedViewCompatible(const ArithmeticSequence< FirstType, SizeType, IncrType > &ids, Index size, SpecializedType)
Definition: ArithmeticSequence.h:366
Index eval_expr_given_size(Index x, Index)
Definition: IndexedViewHelper.h:63
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
Definition: IndexedViewHelper.h:81
@ Specialized
Definition: Constants.h:310
Definition: IndexedViewMethods.h:61
IndexedView< EIGEN_INDEXED_VIEW_METHOD_CONST Derived, typename IvcRowType< RowIndices >::type, typename IvcColType< ColIndices >::type > type
Definition: IndexedViewMethods.h:64
Definition: IndexedViewMethods.h:31
Definition: IndexedViewMethods.h:28
Definition: IndexedViewMethods.h:34