ArithmeticSequence.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_ARITHMETIC_SEQUENCE_H
11 #define EIGEN_ARITHMETIC_SEQUENCE_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
17 #if (!EIGEN_HAS_CXX11) || !((!EIGEN_COMP_GNUC) || EIGEN_COMP_GNUC>=48)
18 template<typename T> struct aseq_negate {};
19 
20 template<> struct aseq_negate<Index> {
21  typedef Index type;
22 };
23 
24 template<int N> struct aseq_negate<FixedInt<N> > {
25  typedef FixedInt<-N> type;
26 };
27 
28 // Compilation error in the following case:
29 template<> struct aseq_negate<FixedInt<DynamicIndex> > {};
30 
31 template<typename FirstType,typename SizeType,typename IncrType,
32  bool FirstIsSymbolic=symbolic::is_symbolic<FirstType>::value,
33  bool SizeIsSymbolic =symbolic::is_symbolic<SizeType>::value>
35  typedef Index type;
36 };
37 
38 template<typename FirstType,typename SizeType,typename IncrType>
39 struct aseq_reverse_first_type<FirstType,SizeType,IncrType,true,true> {
40  typedef symbolic::AddExpr<FirstType,
43  > type;
44 };
45 
46 template<typename SizeType,typename IncrType,typename EnableIf = void>
48  typedef Index type;
49 };
50 
51 template<typename SizeType,typename IncrType>
52 struct aseq_reverse_first_type_aux<SizeType,IncrType,typename internal::enable_if<bool((SizeType::value+IncrType::value)|0x1)>::type> {
54 };
55 
56 template<typename FirstType,typename SizeType,typename IncrType>
57 struct aseq_reverse_first_type<FirstType,SizeType,IncrType,true,false> {
60 };
61 
62 template<typename FirstType,typename SizeType,typename IncrType>
63 struct aseq_reverse_first_type<FirstType,SizeType,IncrType,false,true> {
67 };
68 #endif
69 
70 // Helper to cleanup the type of the increment:
71 template<typename T> struct cleanup_seq_incr {
73 };
74 
75 }
76 
77 //--------------------------------------------------------------------------------
78 // seq(first,last,incr) and seqN(first,size,incr)
79 //--------------------------------------------------------------------------------
80 
81 template<typename FirstType=Index,typename SizeType=Index,typename IncrType=internal::FixedInt<1> >
83 
84 template<typename FirstType,typename SizeType,typename IncrType>
88 seqN(FirstType first, SizeType size, IncrType incr);
89 
109 template<typename FirstType,typename SizeType,typename IncrType>
110 class ArithmeticSequence
111 {
112 public:
113  ArithmeticSequence(FirstType first, SizeType size) : m_first(first), m_size(size) {}
114  ArithmeticSequence(FirstType first, SizeType size, IncrType incr) : m_first(first), m_size(size), m_incr(incr) {}
115 
116  enum {
119  };
120 
122  Index size() const { return m_size; }
123 
125  Index first() const { return m_first; }
126 
128  Index operator[](Index i) const { return m_first + i * m_incr; }
129 
130  const FirstType& firstObject() const { return m_first; }
131  const SizeType& sizeObject() const { return m_size; }
132  const IncrType& incrObject() const { return m_incr; }
133 
134 protected:
135  FirstType m_first;
136  SizeType m_size;
137  IncrType m_incr;
138 
139 public:
140 
141 #if EIGEN_HAS_CXX11 && ((!EIGEN_COMP_GNUC) || EIGEN_COMP_GNUC>=48)
142  auto reverse() const -> decltype(Eigen::seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr)) {
143  return seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr);
144  }
145 #else
146 protected:
149 public:
151  reverse() const {
152  return seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr);
153  }
154 #endif
155 };
156 
160 template<typename FirstType,typename SizeType,typename IncrType>
162 seqN(FirstType first, SizeType size, IncrType incr) {
164 }
165 
169 template<typename FirstType,typename SizeType>
171 seqN(FirstType first, SizeType size) {
173 }
174 
175 #ifdef EIGEN_PARSED_BY_DOXYGEN
176 
186 template<typename FirstType,typename LastType, typename IncrType>
187 auto seq(FirstType f, LastType l, IncrType incr);
188 
198 template<typename FirstType,typename LastType>
199 auto seq(FirstType f, LastType l);
200 
201 #else // EIGEN_PARSED_BY_DOXYGEN
202 
203 #if EIGEN_HAS_CXX11
204 template<typename FirstType,typename LastType>
205 auto seq(FirstType f, LastType l) -> decltype(seqN(typename internal::cleanup_index_type<FirstType>::type(f),
207  - typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>())))
208 {
211  -typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>()));
212 }
213 
214 template<typename FirstType,typename LastType, typename IncrType>
215 auto seq(FirstType f, LastType l, IncrType incr)
221 {
222  typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
225  -typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr)) / CleanedIncrType(incr),
226  CleanedIncrType(incr));
227 }
228 
229 #else // EIGEN_HAS_CXX11
230 
231 template<typename FirstType,typename LastType>
233  ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,Index> >::type
234 seq(FirstType f, LastType l)
235 {
238 }
239 
240 template<typename FirstTypeDerived,typename LastType>
242  ArithmeticSequence<FirstTypeDerived, symbolic::AddExpr<symbolic::AddExpr<symbolic::NegateExpr<FirstTypeDerived>,symbolic::ValueExpr<> >,
243  symbolic::ValueExpr<internal::FixedInt<1> > > > >::type
245 {
246  return seqN(f.derived(),(typename internal::cleanup_index_type<LastType>::type(l)-f.derived()+fix<1>()));
247 }
248 
249 template<typename FirstType,typename LastTypeDerived>
252  symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,symbolic::ValueExpr<> >,
253  symbolic::ValueExpr<internal::FixedInt<1> > > > >::type
255 {
257 }
258 
259 template<typename FirstTypeDerived,typename LastTypeDerived>
260 ArithmeticSequence<FirstTypeDerived,
261  symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,symbolic::NegateExpr<FirstTypeDerived> >,symbolic::ValueExpr<internal::FixedInt<1> > > >
263 {
264  return seqN(f.derived(),(l.derived()-f.derived()+fix<1>()));
265 }
266 
267 
268 template<typename FirstType,typename LastType, typename IncrType>
271 seq(FirstType f, LastType l, IncrType incr)
272 {
273  typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
275  Index((typename internal::cleanup_index_type<LastType>::type(l)-typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr))/CleanedIncrType(incr)), incr);
276 }
277 
278 template<typename FirstTypeDerived,typename LastType, typename IncrType>
280  ArithmeticSequence<FirstTypeDerived,
281  symbolic::QuotientExpr<symbolic::AddExpr<symbolic::AddExpr<symbolic::NegateExpr<FirstTypeDerived>,
282  symbolic::ValueExpr<> >,
286 seq(const symbolic::BaseExpr<FirstTypeDerived> &f, LastType l, IncrType incr)
287 {
288  typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
289  return seqN(f.derived(),(typename internal::cleanup_index_type<LastType>::type(l)-f.derived()+CleanedIncrType(incr))/CleanedIncrType(incr), incr);
290 }
291 
292 template<typename FirstType,typename LastTypeDerived, typename IncrType>
295  symbolic::QuotientExpr<symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,symbolic::ValueExpr<> >,
299 seq(FirstType f, const symbolic::BaseExpr<LastTypeDerived> &l, IncrType incr)
300 {
301  typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
303  (l.derived()-typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr))/CleanedIncrType(incr), incr);
304 }
305 
306 template<typename FirstTypeDerived,typename LastTypeDerived, typename IncrType>
307 ArithmeticSequence<FirstTypeDerived,
308  symbolic::QuotientExpr<symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,
309  symbolic::NegateExpr<FirstTypeDerived> >,
314 {
315  typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
316  return seqN(f.derived(),(l.derived()-f.derived()+CleanedIncrType(incr))/CleanedIncrType(incr), incr);
317 }
318 #endif // EIGEN_HAS_CXX11
319 
320 #endif // EIGEN_PARSED_BY_DOXYGEN
321 
322 
323 #if EIGEN_HAS_CXX11 || defined(EIGEN_PARSED_BY_DOXYGEN)
324 
330 template<typename SizeType,typename IncrType>
331 auto lastN(SizeType size, IncrType incr)
332 -> decltype(seqN(Eigen::last-(size-fix<1>())*incr, size, incr))
333 {
334  return seqN(Eigen::last-(size-fix<1>())*incr, size, incr);
335 }
336 
343 template<typename SizeType>
344 auto lastN(SizeType size)
345 -> decltype(seqN(Eigen::last+fix<1>()-size, size))
346 {
347  return seqN(Eigen::last+fix<1>()-size, size);
348 }
349 #endif
350 
351 namespace internal {
352 
353 // Convert a symbolic span into a usable one (i.e., remove last/end "keywords")
354 template<typename T>
357 };
358 
359 template<typename FirstType,typename SizeType,typename IncrType,int XprSize>
360 struct IndexedViewCompatibleType<ArithmeticSequence<FirstType,SizeType,IncrType>, XprSize> {
362 };
363 
364 template<typename FirstType,typename SizeType,typename IncrType>
369 }
370 
371 template<typename FirstType,typename SizeType,typename IncrType>
372 struct get_compile_time_incr<ArithmeticSequence<FirstType,SizeType,IncrType> > {
374 };
375 
376 } // end namespace internal
377 
399 namespace indexing {
400  using Eigen::all;
401  using Eigen::seq;
402  using Eigen::seqN;
403  #if EIGEN_HAS_CXX11
404  using Eigen::lastN;
405  #endif
406  using Eigen::last;
407  using Eigen::lastp1;
408  using Eigen::fix;
409 }
410 
411 } // end namespace Eigen
412 
413 #endif // EIGEN_ARITHMETIC_SEQUENCE_H
Eigen::ArithmeticSequence::ArithmeticSequence
ArithmeticSequence(FirstType first, SizeType size, IncrType incr)
Definition: ArithmeticSequence.h:114
Eigen::internal::aseq_reverse_first_type::type
Index type
Definition: ArithmeticSequence.h:35
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::IndexedViewCompatibleType
Definition: IndexedViewHelper.h:86
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
Eigen::SpecializedType
SpecializedType
Definition: Constants.h:309
Eigen::internal::cleanup_index_type::type
T type
Definition: IntegralConstant.h:164
Eigen::seqN
ArithmeticSequence< typename internal::cleanup_index_type< FirstType >::type, typename internal::cleanup_index_type< SizeType >::type, typename internal::cleanup_seq_incr< IncrType >::type > seqN(FirstType first, SizeType size, IncrType incr)
Definition: ArithmeticSequence.h:162
Eigen::internal::eval_expr_given_size
Index eval_expr_given_size(Index x, Index)
Definition: IndexedViewHelper.h:63
Eigen::internal::aseq_reverse_first_type
Definition: ArithmeticSequence.h:34
Eigen::fix
internal::FixedInt< N > fix()
Definition: IntegralConstant.h:192
Eigen::internal::aseq_negate
Definition: ArithmeticSequence.h:18
Eigen::symbolic::is_symbolic
Definition: SymbolicIndex.h:189
Eigen::ArithmeticSequence::ArithmeticSequence
ArithmeticSequence(FirstType first, SizeType size)
Definition: ArithmeticSequence.h:113
Eigen::internal::FixedInt
Definition: IntegralConstant.h:18
Eigen::symbolic::is_symbolic::value
@ value
Definition: SymbolicIndex.h:191
type
Definition: pytypes.h:1525
Eigen::ArithmeticSequence::operator[]
Index operator[](Index i) const
Definition: ArithmeticSequence.h:128
Eigen::internal::get_compile_time_incr::value
@ value
Definition: IndexedViewHelper.h:76
Eigen::internal::aseq_reverse_first_type_aux
Definition: ArithmeticSequence.h:47
Eigen::last
static const symbolic::SymbolExpr< internal::symbolic_last_tag > last
Definition: IndexedViewHelper.h:38
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
Eigen::internal::cleanup_seq_incr::type
cleanup_index_type< T, DynamicIndex >::type type
Definition: ArithmeticSequence.h:72
Eigen::symbolic::ValueExpr
Definition: SymbolicIndex.h:52
Eigen::ArithmeticSequence::ReverseFirstType
internal::aseq_reverse_first_type< FirstType, SizeType, IncrType >::type ReverseFirstType
Definition: ArithmeticSequence.h:148
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::symbolic::BaseExpr
Definition: SymbolicIndex.h:77
Eigen::ArithmeticSequence::ReverseIncrType
internal::aseq_negate< IncrType >::type ReverseIncrType
Definition: ArithmeticSequence.h:147
Eigen::ArithmeticSequence::sizeObject
const SizeType & sizeObject() const
Definition: ArithmeticSequence.h:131
Eigen::all
static const Eigen::internal::all_t all
Definition: IndexedViewHelper.h:171
l
static const Line3 l(Rot3(), 1, 1)
Eigen::ArithmeticSequence::firstObject
const FirstType & firstObject() const
Definition: ArithmeticSequence.h:130
Eigen::internal::aseq_reverse_first_type< FirstType, SizeType, IncrType, false, true >::type
symbolic::AddExpr< symbolic::ProductExpr< symbolic::AddExpr< SizeType, symbolic::ValueExpr< FixedInt<-1 > > >, symbolic::ValueExpr< IncrType > >, symbolic::ValueExpr<> > type
Definition: ArithmeticSequence.h:66
Eigen::internal::first
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
Definition: IndexedViewHelper.h:81
Eigen::ArithmeticSequence::incrObject
const IncrType & incrObject() const
Definition: ArithmeticSequence.h:132
Eigen::internal::aseq_reverse_first_type< FirstType, SizeType, IncrType, true, false >::type
symbolic::AddExpr< FirstType, symbolic::ValueExpr< Aux > > type
Definition: ArithmeticSequence.h:59
Eigen::Triplet< double >
Eigen::ArithmeticSequence
Definition: ArithmeticSequence.h:82
Eigen::symbolic::ProductExpr
Definition: SymbolicIndex.h:46
Eigen::symbolic::AddExpr
Definition: SymbolicIndex.h:45
Eigen::internal::make_size_type::type
internal::conditional< symbolic::is_symbolic< T >::value, Index, T >::type type
Definition: ArithmeticSequence.h:356
Eigen::ArithmeticSequence::size
Index size() const
Definition: ArithmeticSequence.h:122
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
Eigen::internal::aseq_reverse_first_type< FirstType, SizeType, IncrType, true, true >::type
symbolic::AddExpr< FirstType, symbolic::ProductExpr< symbolic::AddExpr< SizeType, symbolic::ValueExpr< FixedInt<-1 > > >, symbolic::ValueExpr< IncrType > > > type
Definition: ArithmeticSequence.h:43
Eigen::internal::aseq_reverse_first_type< FirstType, SizeType, IncrType, true, false >::Aux
aseq_reverse_first_type_aux< SizeType, IncrType >::type Aux
Definition: ArithmeticSequence.h:58
Eigen::ArithmeticSequence::m_first
FirstType m_first
Definition: ArithmeticSequence.h:135
Eigen::internal::conditional
Definition: Meta.h:109
Eigen::internal::aseq_negate< FixedInt< N > >::type
FixedInt<-N > type
Definition: ArithmeticSequence.h:25
Eigen::lastp1
static const symbolic::AddExpr< symbolic::SymbolExpr< internal::symbolic_last_tag >, symbolic::ValueExpr< Eigen::internal::FixedInt< 1 > > > lastp1(last+fix< 1 >())
Eigen::internal::cleanup_seq_incr
Definition: ArithmeticSequence.h:71
Eigen::internal::make_size_type
Definition: ArithmeticSequence.h:355
Eigen::ArithmeticSequence::first
Index first() const
Definition: ArithmeticSequence.h:125
N
#define N
Definition: igam.h:9
internal
Definition: BandTriangularSolver.h:13
Eigen::DynamicIndex
const int DynamicIndex
Definition: Constants.h:27
Eigen::internal::get_fixed_value
Definition: IntegralConstant.h:133
Eigen::internal::enable_if
Definition: Meta.h:273
Eigen::internal::size
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
Eigen::ArithmeticSequence::m_incr
IncrType m_incr
Definition: ArithmeticSequence.h:137
Eigen::internal::aseq_reverse_first_type_aux::type
Index type
Definition: ArithmeticSequence.h:48
Eigen::ArithmeticSequence::reverse
ArithmeticSequence< ReverseFirstType, SizeType, ReverseIncrType > reverse() const
Definition: ArithmeticSequence.h:151
Eigen::ArithmeticSequence::m_size
SizeType m_size
Definition: ArithmeticSequence.h:136
Eigen::internal::IndexedViewCompatibleType< ArithmeticSequence< FirstType, SizeType, IncrType >, XprSize >::type
ArithmeticSequence< Index, typename make_size_type< SizeType >::type, IncrType > type
Definition: ArithmeticSequence.h:361
Eigen::seq
internal::enable_if<!(symbolic::is_symbolic< FirstType >::value||symbolic::is_symbolic< LastType >::value), ArithmeticSequence< typename internal::cleanup_index_type< FirstType >::type, Index > >::type seq(FirstType f, LastType l)
Definition: ArithmeticSequence.h:234
test_callbacks.value
value
Definition: test_callbacks.py:160
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::internal::get_compile_time_incr
Definition: IndexedViewHelper.h:75
Eigen::ArithmeticSequence::IncrAtCompileTime
@ IncrAtCompileTime
Definition: ArithmeticSequence.h:118
Eigen::internal::aseq_negate< Index >::type
Index type
Definition: ArithmeticSequence.h:21
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::ArithmeticSequence::SizeAtCompileTime
@ SizeAtCompileTime
Definition: ArithmeticSequence.h:117


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:01:48