robot-rust 0.2.1

The robot-rust project, bindings for wpilib, ctre, and rev in rust.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef EIGEN_INDEXED_VIEW_HELPER_H
#define EIGEN_INDEXED_VIEW_HELPER_H

// IWYU pragma: private
#include "../InternalHeaderCheck.h"

namespace Eigen {

namespace internal {
struct symbolic_last_tag {};

struct all_t {};

}  // namespace internal

namespace placeholders {

typedef symbolic::SymbolExpr<internal::symbolic_last_tag> last_t;

/** \var last
 * \ingroup Core_Module
 *
 * Can be used as a parameter to Eigen::seq and Eigen::seqN functions to symbolically reference the last
 * element/row/columns of the underlying vector or matrix once passed to DenseBase::operator()(const RowIndices&, const
 * ColIndices&).
 *
 * This symbolic placeholder supports standard arithmetic operations.
 *
 * A typical usage example would be:
 * \code
 * using namespace Eigen;
 * using Eigen::placeholders::last;
 * VectorXd v(n);
 * v(seq(2,last-2)).setOnes();
 * \endcode
 *
 * \sa end
 */
static constexpr const last_t last;

typedef symbolic::AddExpr<symbolic::SymbolExpr<internal::symbolic_last_tag>,
                          symbolic::ValueExpr<Eigen::internal::FixedInt<1>>>
    lastp1_t;
typedef Eigen::internal::all_t all_t;

/** \var lastp1
 * \ingroup Core_Module
 *
 * Can be used as a parameter to Eigen::seq and Eigen::seqN functions to symbolically
 * reference the last+1 element/row/columns of the underlying vector or matrix once
 * passed to DenseBase::operator()(const RowIndices&, const ColIndices&).
 *
 * This symbolic placeholder supports standard arithmetic operations.
 * It is essentially an alias to last+fix<1>.
 *
 * \sa last
 */
#ifdef EIGEN_PARSED_BY_DOXYGEN
static constexpr auto lastp1 = last + fix<1>;
#else
// Using a FixedExpr<1> expression is important here to make sure the compiler
// can fully optimize the computation starting indices with zero overhead.
static constexpr lastp1_t lastp1 = lastp1_t{};
#endif

/** \var end
 * \ingroup Core_Module
 * \sa lastp1
 */
static constexpr lastp1_t end = lastp1;

/** \var all
 * \ingroup Core_Module
 * Can be used as a parameter to DenseBase::operator()(const RowIndices&, const ColIndices&) to index all rows or
 * columns
 */
static constexpr Eigen::internal::all_t all;

}  // namespace placeholders

namespace internal {

// Evaluate a symbolic expression or constant given the "size" of an object, allowing
// any symbols like `last` to be evaluated.  The default here assumes a dynamic constant.
template <typename Expr, int SizeAtCompileTime, typename EnableIf = void>
struct SymbolicExpressionEvaluator {
  static constexpr Index ValueAtCompileTime = Undefined;
  static Index eval(const Expr& expr, Index /*size*/) { return static_cast<Index>(expr); }
};

// Symbolic expression with size known at compile-time.
template <typename Expr, int SizeAtCompileTime>
struct SymbolicExpressionEvaluator<Expr, SizeAtCompileTime, std::enable_if_t<symbolic::is_symbolic<Expr>::value>> {
  static constexpr Index ValueAtCompileTime =
      Expr::Derived::eval_at_compile_time(Eigen::placeholders::last = fix<SizeAtCompileTime - 1>);
  static Index eval(const Expr& expr, Index /*size*/) {
    return expr.eval(Eigen::placeholders::last = fix<SizeAtCompileTime - 1>);
  }
};

// Symbolic expression with dynamic size.
template <typename Expr>
struct SymbolicExpressionEvaluator<Expr, Dynamic, std::enable_if_t<symbolic::is_symbolic<Expr>::value>> {
  static constexpr Index ValueAtCompileTime = Undefined;
  static Index eval(const Expr& expr, Index size) { return expr.eval(Eigen::placeholders::last = size - 1); }
};

// Fixed int.
template <int N, int SizeAtCompileTime>
struct SymbolicExpressionEvaluator<FixedInt<N>, SizeAtCompileTime, void> {
  static constexpr Index ValueAtCompileTime = static_cast<Index>(N);
  static Index eval(const FixedInt<N>& /*expr*/, Index /*size*/) { return ValueAtCompileTime; }
};

//--------------------------------------------------------------------------------
// Handling of generic indices (e.g. array)
//--------------------------------------------------------------------------------

// Potentially wrap indices in a type that is better-suited for IndexedView evaluation.
template <typename Indices, int NestedSizeAtCompileTime, typename EnableIf = void>
struct IndexedViewHelperIndicesWrapper {
  using type = Indices;
  static const type& CreateIndexSequence(const Indices& indices, Index /*nested_size*/) { return indices; }
};

// Extract compile-time and runtime first, size, increments.
template <typename Indices, typename EnableIf = void>
struct IndexedViewHelper {
  static constexpr Index FirstAtCompileTime = Undefined;
  static constexpr Index SizeAtCompileTime = array_size<Indices>::value;
  static constexpr Index IncrAtCompileTime = Undefined;

  static constexpr Index first(const Indices& indices) { return static_cast<Index>(indices[0]); }
  static constexpr Index size(const Indices& indices) { return index_list_size(indices); }
  static constexpr Index incr(const Indices& /*indices*/) { return Undefined; }
};

//--------------------------------------------------------------------------------
// Handling of ArithmeticSequence
//--------------------------------------------------------------------------------

template <Index FirstAtCompileTime_, Index SizeAtCompileTime_, Index IncrAtCompileTime_>
class ArithmeticSequenceRange {
 public:
  static constexpr Index FirstAtCompileTime = FirstAtCompileTime_;
  static constexpr Index SizeAtCompileTime = SizeAtCompileTime_;
  static constexpr Index IncrAtCompileTime = IncrAtCompileTime_;

  constexpr ArithmeticSequenceRange(Index first, Index size, Index incr) : first_{first}, size_{size}, incr_{incr} {}
  constexpr Index operator[](Index i) const { return first() + i * incr(); }
  constexpr Index first() const noexcept { return first_.value(); }
  constexpr Index size() const noexcept { return size_.value(); }
  constexpr Index incr() const noexcept { return incr_.value(); }

 private:
  variable_if_dynamicindex<Index, int(FirstAtCompileTime)> first_;
  variable_if_dynamic<Index, int(SizeAtCompileTime)> size_;
  variable_if_dynamicindex<Index, int(IncrAtCompileTime)> incr_;
};

template <typename FirstType, typename SizeType, typename IncrType, int NestedSizeAtCompileTime>
struct IndexedViewHelperIndicesWrapper<ArithmeticSequence<FirstType, SizeType, IncrType>, NestedSizeAtCompileTime,
                                       void> {
  static constexpr Index EvalFirstAtCompileTime =
      SymbolicExpressionEvaluator<FirstType, NestedSizeAtCompileTime>::ValueAtCompileTime;
  static constexpr Index EvalSizeAtCompileTime =
      SymbolicExpressionEvaluator<SizeType, NestedSizeAtCompileTime>::ValueAtCompileTime;
  static constexpr Index EvalIncrAtCompileTime =
      SymbolicExpressionEvaluator<IncrType, NestedSizeAtCompileTime>::ValueAtCompileTime;

  static constexpr Index FirstAtCompileTime =
      (int(EvalFirstAtCompileTime) == Undefined) ? Index(DynamicIndex) : EvalFirstAtCompileTime;
  static constexpr Index SizeAtCompileTime =
      (int(EvalSizeAtCompileTime) == Undefined) ? Index(Dynamic) : EvalSizeAtCompileTime;
  static constexpr Index IncrAtCompileTime =
      (int(EvalIncrAtCompileTime) == Undefined) ? Index(DynamicIndex) : EvalIncrAtCompileTime;

  using Indices = ArithmeticSequence<FirstType, SizeType, IncrType>;
  using type = ArithmeticSequenceRange<FirstAtCompileTime, SizeAtCompileTime, IncrAtCompileTime>;

  static type CreateIndexSequence(const Indices& indices, Index nested_size) {
    Index first =
        SymbolicExpressionEvaluator<FirstType, NestedSizeAtCompileTime>::eval(indices.firstObject(), nested_size);
    Index size =
        SymbolicExpressionEvaluator<SizeType, NestedSizeAtCompileTime>::eval(indices.sizeObject(), nested_size);
    Index incr =
        SymbolicExpressionEvaluator<IncrType, NestedSizeAtCompileTime>::eval(indices.incrObject(), nested_size);
    return type(first, size, incr);
  }
};

template <Index FirstAtCompileTime_, Index SizeAtCompileTime_, Index IncrAtCompileTime_>
struct IndexedViewHelper<ArithmeticSequenceRange<FirstAtCompileTime_, SizeAtCompileTime_, IncrAtCompileTime_>, void> {
 public:
  using Indices = ArithmeticSequenceRange<FirstAtCompileTime_, SizeAtCompileTime_, IncrAtCompileTime_>;
  static constexpr Index FirstAtCompileTime = Indices::FirstAtCompileTime;
  static constexpr Index SizeAtCompileTime = Indices::SizeAtCompileTime;
  static constexpr Index IncrAtCompileTime = Indices::IncrAtCompileTime;
  static Index first(const Indices& indices) { return indices.first(); }
  static Index size(const Indices& indices) { return indices.size(); }
  static Index incr(const Indices& indices) { return indices.incr(); }
};

//--------------------------------------------------------------------------------
// Handling of a single index.
//--------------------------------------------------------------------------------

template <Index ValueAtCompileTime>
class SingleRange {
 public:
  static constexpr Index FirstAtCompileTime = ValueAtCompileTime;
  static constexpr Index SizeAtCompileTime = Index(1);
  static constexpr Index IncrAtCompileTime = Index(1);  // Needs to be 1 to be treated as block-like.

  constexpr SingleRange(Index v) noexcept : value_(v) {}
  constexpr Index operator[](Index) const noexcept { return first(); }
  constexpr Index first() const noexcept { return value_.value(); }
  constexpr Index size() const noexcept { return SizeAtCompileTime; }
  constexpr Index incr() const noexcept { return IncrAtCompileTime; }

 private:
  variable_if_dynamicindex<Index, int(ValueAtCompileTime)> value_;
};

template <typename T>
struct is_single_range : public std::false_type {};

template <Index ValueAtCompileTime>
struct is_single_range<SingleRange<ValueAtCompileTime>> : public std::true_type {};

template <typename SingleIndex, int NestedSizeAtCompileTime>
struct IndexedViewHelperIndicesWrapper<
    SingleIndex, NestedSizeAtCompileTime,
    std::enable_if_t<std::is_integral<SingleIndex>::value || symbolic::is_symbolic<SingleIndex>::value>> {
  static constexpr Index EvalValueAtCompileTime =
      SymbolicExpressionEvaluator<SingleIndex, NestedSizeAtCompileTime>::ValueAtCompileTime;
  static constexpr Index ValueAtCompileTime =
      (int(EvalValueAtCompileTime) == Undefined) ? Index(DynamicIndex) : EvalValueAtCompileTime;
  using type = SingleRange<ValueAtCompileTime>;
  static type CreateIndexSequence(const SingleIndex& index, Index nested_size) {
    return type(SymbolicExpressionEvaluator<SingleIndex, NestedSizeAtCompileTime>::eval(index, nested_size));
  }
};

template <int N, int NestedSizeAtCompileTime>
struct IndexedViewHelperIndicesWrapper<FixedInt<N>, NestedSizeAtCompileTime, void> {
  using type = SingleRange<Index(N)>;
  static type CreateIndexSequence(const FixedInt<N>& /*index*/) { return type(Index(N)); }
};

template <Index ValueAtCompileTime>
struct IndexedViewHelper<SingleRange<ValueAtCompileTime>, void> {
  using Indices = SingleRange<ValueAtCompileTime>;
  static constexpr Index FirstAtCompileTime = Indices::FirstAtCompileTime;
  static constexpr Index SizeAtCompileTime = Indices::SizeAtCompileTime;
  static constexpr Index IncrAtCompileTime = Indices::IncrAtCompileTime;

  static constexpr Index first(const Indices& indices) { return indices.first(); }
  static constexpr Index size(const Indices& /*indices*/) { return SizeAtCompileTime; }
  static constexpr Index incr(const Indices& /*indices*/) { return IncrAtCompileTime; }
};

//--------------------------------------------------------------------------------
// Handling of all
//--------------------------------------------------------------------------------

// Convert a symbolic 'all' into a usable range type
template <Index SizeAtCompileTime_>
class AllRange {
 public:
  static constexpr Index FirstAtCompileTime = Index(0);
  static constexpr Index SizeAtCompileTime = SizeAtCompileTime_;
  static constexpr Index IncrAtCompileTime = Index(1);
  constexpr AllRange(Index size) : size_(size) {}
  constexpr Index operator[](Index i) const noexcept { return i; }
  constexpr Index first() const noexcept { return FirstAtCompileTime; }
  constexpr Index size() const noexcept { return size_.value(); }
  constexpr Index incr() const noexcept { return IncrAtCompileTime; }

 private:
  variable_if_dynamic<Index, int(SizeAtCompileTime)> size_;
};

template <int NestedSizeAtCompileTime>
struct IndexedViewHelperIndicesWrapper<all_t, NestedSizeAtCompileTime, void> {
  using type = AllRange<Index(NestedSizeAtCompileTime)>;
  static type CreateIndexSequence(const all_t& /*indices*/, Index nested_size) { return type(nested_size); }
};

template <Index SizeAtCompileTime_>
struct IndexedViewHelper<AllRange<SizeAtCompileTime_>, void> {
  using Indices = AllRange<SizeAtCompileTime_>;
  static constexpr Index FirstAtCompileTime = Indices::FirstAtCompileTime;
  static constexpr Index SizeAtCompileTime = Indices::SizeAtCompileTime;
  static constexpr Index IncrAtCompileTime = Indices::IncrAtCompileTime;

  static Index first(const Indices& indices) { return indices.first(); }
  static Index size(const Indices& indices) { return indices.size(); }
  static Index incr(const Indices& indices) { return indices.incr(); }
};

// this helper class assumes internal::valid_indexed_view_overload<RowIndices, ColIndices>::value == true
template <typename Derived, typename RowIndices, typename ColIndices, typename EnableIf = void>
struct IndexedViewSelector;

template <typename Indices, int SizeAtCompileTime>
using IvcType = typename internal::IndexedViewHelperIndicesWrapper<Indices, SizeAtCompileTime>::type;

template <int SizeAtCompileTime, typename Indices>
inline IvcType<Indices, SizeAtCompileTime> CreateIndexSequence(size_t size, const Indices& indices) {
  return internal::IndexedViewHelperIndicesWrapper<Indices, SizeAtCompileTime>::CreateIndexSequence(indices, size);
}

// Generic
template <typename Derived, typename RowIndices, typename ColIndices>
struct IndexedViewSelector<Derived, RowIndices, ColIndices,
                           std::enable_if_t<internal::traits<
                               IndexedView<Derived, IvcType<RowIndices, Derived::RowsAtCompileTime>,
                                           IvcType<ColIndices, Derived::ColsAtCompileTime>>>::ReturnAsIndexedView>> {
  using ReturnType = IndexedView<Derived, IvcType<RowIndices, Derived::RowsAtCompileTime>,
                                 IvcType<ColIndices, Derived::ColsAtCompileTime>>;
  using ConstReturnType = IndexedView<const Derived, IvcType<RowIndices, Derived::RowsAtCompileTime>,
                                      IvcType<ColIndices, Derived::ColsAtCompileTime>>;

  static inline ReturnType run(Derived& derived, const RowIndices& rowIndices, const ColIndices& colIndices) {
    return ReturnType(derived, CreateIndexSequence<Derived::RowsAtCompileTime>(derived.rows(), rowIndices),
                      CreateIndexSequence<Derived::ColsAtCompileTime>(derived.cols(), colIndices));
  }
  static inline ConstReturnType run(const Derived& derived, const RowIndices& rowIndices,
                                    const ColIndices& colIndices) {
    return ConstReturnType(derived, CreateIndexSequence<Derived::RowsAtCompileTime>(derived.rows(), rowIndices),
                           CreateIndexSequence<Derived::ColsAtCompileTime>(derived.cols(), colIndices));
  }
};

// Block
template <typename Derived, typename RowIndices, typename ColIndices>
struct IndexedViewSelector<
    Derived, RowIndices, ColIndices,
    std::enable_if_t<internal::traits<IndexedView<Derived, IvcType<RowIndices, Derived::RowsAtCompileTime>,
                                                  IvcType<ColIndices, Derived::ColsAtCompileTime>>>::ReturnAsBlock>> {
  using ActualRowIndices = IvcType<RowIndices, Derived::RowsAtCompileTime>;
  using ActualColIndices = IvcType<ColIndices, Derived::ColsAtCompileTime>;
  using IndexedViewType = IndexedView<Derived, ActualRowIndices, ActualColIndices>;
  using ConstIndexedViewType = IndexedView<const Derived, ActualRowIndices, ActualColIndices>;
  using ReturnType = typename internal::traits<IndexedViewType>::BlockType;
  using ConstReturnType = typename internal::traits<ConstIndexedViewType>::BlockType;
  using RowHelper = internal::IndexedViewHelper<ActualRowIndices>;
  using ColHelper = internal::IndexedViewHelper<ActualColIndices>;

  static inline ReturnType run(Derived& derived, const RowIndices& rowIndices, const ColIndices& colIndices) {
    auto actualRowIndices = CreateIndexSequence<Derived::RowsAtCompileTime>(derived.rows(), rowIndices);
    auto actualColIndices = CreateIndexSequence<Derived::ColsAtCompileTime>(derived.cols(), colIndices);
    return ReturnType(derived, RowHelper::first(actualRowIndices), ColHelper::first(actualColIndices),
                      RowHelper::size(actualRowIndices), ColHelper::size(actualColIndices));
  }
  static inline ConstReturnType run(const Derived& derived, const RowIndices& rowIndices,
                                    const ColIndices& colIndices) {
    auto actualRowIndices = CreateIndexSequence<Derived::RowsAtCompileTime>(derived.rows(), rowIndices);
    auto actualColIndices = CreateIndexSequence<Derived::ColsAtCompileTime>(derived.cols(), colIndices);
    return ConstReturnType(derived, RowHelper::first(actualRowIndices), ColHelper::first(actualColIndices),
                           RowHelper::size(actualRowIndices), ColHelper::size(actualColIndices));
  }
};

// Scalar
template <typename Derived, typename RowIndices, typename ColIndices>
struct IndexedViewSelector<
    Derived, RowIndices, ColIndices,
    std::enable_if_t<internal::traits<IndexedView<Derived, IvcType<RowIndices, Derived::RowsAtCompileTime>,
                                                  IvcType<ColIndices, Derived::ColsAtCompileTime>>>::ReturnAsScalar>> {
  using ReturnType = typename DenseBase<Derived>::Scalar&;
  using ConstReturnType = typename DenseBase<Derived>::CoeffReturnType;
  using ActualRowIndices = IvcType<RowIndices, Derived::RowsAtCompileTime>;
  using ActualColIndices = IvcType<ColIndices, Derived::ColsAtCompileTime>;
  using RowHelper = internal::IndexedViewHelper<ActualRowIndices>;
  using ColHelper = internal::IndexedViewHelper<ActualColIndices>;
  static inline ReturnType run(Derived& derived, const RowIndices& rowIndices, const ColIndices& colIndices) {
    auto actualRowIndices = CreateIndexSequence<Derived::RowsAtCompileTime>(derived.rows(), rowIndices);
    auto actualColIndices = CreateIndexSequence<Derived::ColsAtCompileTime>(derived.cols(), colIndices);
    return derived(RowHelper::first(actualRowIndices), ColHelper::first(actualColIndices));
  }
  static inline ConstReturnType run(const Derived& derived, const RowIndices& rowIndices,
                                    const ColIndices& colIndices) {
    auto actualRowIndices = CreateIndexSequence<Derived::RowsAtCompileTime>(derived.rows(), rowIndices);
    auto actualColIndices = CreateIndexSequence<Derived::ColsAtCompileTime>(derived.cols(), colIndices);
    return derived(RowHelper::first(actualRowIndices), ColHelper::first(actualColIndices));
  }
};

// this helper class assumes internal::is_valid_index_type<Indices>::value == false
template <typename Derived, typename Indices, typename EnableIf = void>
struct VectorIndexedViewSelector;

// Generic
template <typename Derived, typename Indices>
struct VectorIndexedViewSelector<
    Derived, Indices,
    std::enable_if_t<!internal::is_single_range<IvcType<Indices, Derived::SizeAtCompileTime>>::value &&
                     internal::IndexedViewHelper<IvcType<Indices, Derived::SizeAtCompileTime>>::IncrAtCompileTime !=
                         1>> {
  static constexpr bool IsRowMajor = DenseBase<Derived>::IsRowMajor;
  using ZeroIndex = internal::SingleRange<Index(0)>;
  using RowMajorReturnType = IndexedView<Derived, ZeroIndex, IvcType<Indices, Derived::SizeAtCompileTime>>;
  using ConstRowMajorReturnType = IndexedView<const Derived, ZeroIndex, IvcType<Indices, Derived::SizeAtCompileTime>>;

  using ColMajorReturnType = IndexedView<Derived, IvcType<Indices, Derived::SizeAtCompileTime>, ZeroIndex>;
  using ConstColMajorReturnType = IndexedView<const Derived, IvcType<Indices, Derived::SizeAtCompileTime>, ZeroIndex>;

  using ReturnType = typename internal::conditional<IsRowMajor, RowMajorReturnType, ColMajorReturnType>::type;
  using ConstReturnType =
      typename internal::conditional<IsRowMajor, ConstRowMajorReturnType, ConstColMajorReturnType>::type;

  template <bool UseRowMajor = IsRowMajor, std::enable_if_t<UseRowMajor, bool> = true>
  static inline RowMajorReturnType run(Derived& derived, const Indices& indices) {
    return RowMajorReturnType(derived, ZeroIndex(0),
                              CreateIndexSequence<Derived::ColsAtCompileTime>(derived.cols(), indices));
  }
  template <bool UseRowMajor = IsRowMajor, std::enable_if_t<UseRowMajor, bool> = true>
  static inline ConstRowMajorReturnType run(const Derived& derived, const Indices& indices) {
    return ConstRowMajorReturnType(derived, ZeroIndex(0),
                                   CreateIndexSequence<Derived::ColsAtCompileTime>(derived.cols(), indices));
  }
  template <bool UseRowMajor = IsRowMajor, std::enable_if_t<!UseRowMajor, bool> = true>
  static inline ColMajorReturnType run(Derived& derived, const Indices& indices) {
    return ColMajorReturnType(derived, CreateIndexSequence<Derived::RowsAtCompileTime>(derived.rows(), indices),
                              ZeroIndex(0));
  }
  template <bool UseRowMajor = IsRowMajor, std::enable_if_t<!UseRowMajor, bool> = true>
  static inline ConstColMajorReturnType run(const Derived& derived, const Indices& indices) {
    return ConstColMajorReturnType(derived, CreateIndexSequence<Derived::RowsAtCompileTime>(derived.rows(), indices),
                                   ZeroIndex(0));
  }
};

// Block
template <typename Derived, typename Indices>
struct VectorIndexedViewSelector<
    Derived, Indices,
    std::enable_if_t<!internal::is_single_range<IvcType<Indices, Derived::SizeAtCompileTime>>::value &&
                     internal::IndexedViewHelper<IvcType<Indices, Derived::SizeAtCompileTime>>::IncrAtCompileTime ==
                         1>> {
  using Helper = internal::IndexedViewHelper<IvcType<Indices, Derived::SizeAtCompileTime>>;
  using ReturnType = VectorBlock<Derived, Helper::SizeAtCompileTime>;
  using ConstReturnType = VectorBlock<const Derived, Helper::SizeAtCompileTime>;
  static inline ReturnType run(Derived& derived, const Indices& indices) {
    auto actualIndices = CreateIndexSequence<Derived::SizeAtCompileTime>(derived.size(), indices);
    return ReturnType(derived, Helper::first(actualIndices), Helper::size(actualIndices));
  }
  static inline ConstReturnType run(const Derived& derived, const Indices& indices) {
    auto actualIndices = CreateIndexSequence<Derived::SizeAtCompileTime>(derived.size(), indices);
    return ConstReturnType(derived, Helper::first(actualIndices), Helper::size(actualIndices));
  }
};

// Symbolic
template <typename Derived, typename Indices>
struct VectorIndexedViewSelector<
    Derived, Indices,
    std::enable_if_t<internal::is_single_range<IvcType<Indices, Derived::SizeAtCompileTime>>::value>> {
  using ReturnType = typename DenseBase<Derived>::Scalar&;
  using ConstReturnType = typename DenseBase<Derived>::CoeffReturnType;
  using Helper = internal::IndexedViewHelper<IvcType<Indices, Derived::SizeAtCompileTime>>;
  static inline ReturnType run(Derived& derived, const Indices& indices) {
    auto actualIndices = CreateIndexSequence<Derived::SizeAtCompileTime>(derived.size(), indices);
    return derived(Helper::first(actualIndices));
  }
  static inline ConstReturnType run(const Derived& derived, const Indices& indices) {
    auto actualIndices = CreateIndexSequence<Derived::SizeAtCompileTime>(derived.size(), indices);
    return derived(Helper::first(actualIndices));
  }
};

}  // end namespace internal

}  // end namespace Eigen

#endif  // EIGEN_INDEXED_VIEW_HELPER_H