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) {
163  return ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type,typename internal::cleanup_seq_incr<IncrType>::type>(first,size,incr);
164 }
165 
169 template<typename FirstType,typename SizeType>
170 ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type >
171 seqN(FirstType first, SizeType size) {
172  return ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type>(first,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)
216  -> decltype(seqN(typename internal::cleanup_index_type<FirstType>::type(f),
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>
234 seq(FirstType f, LastType l)
235 {
238 }
239 
240 template<typename FirstTypeDerived,typename LastType>
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>
251  ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,
255 {
257 }
258 
259 template<typename FirstTypeDerived,typename LastTypeDerived>
260 ArithmeticSequence<FirstTypeDerived,
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,
282  symbolic::ValueExpr<> >,
284  symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
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>
293 typename internal::enable_if<!symbolic::is_symbolic<FirstType>::value,
294  ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,
296  symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
297  symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
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,
310  symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
311  symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
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
internal::aseq_negate< IncrType >::type ReverseIncrType
const IncrType & incrObject() const
static const Eigen::internal::all_t all
cleanup_index_type< T, DynamicIndex >::type type
internal::conditional< symbolic::is_symbolic< T >::value, Index, T >::type type
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
const int DynamicIndex
Definition: Constants.h:27
ArithmeticSequence< Index, typename make_size_type< SizeType >::type, IncrType > type
#define N
Definition: gksort.c:12
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
ArithmeticSequence(FirstType first, SizeType size, IncrType incr)
static const symbolic::SymbolExpr< internal::symbolic_last_tag > last
ArithmeticSequence(FirstType first, SizeType size)
static const Line3 l(Rot3(), 1, 1)
ArithmeticSequence< ReverseFirstType, SizeType, ReverseIncrType > reverse() const
Index operator[](Index i) const
static const symbolic::AddExpr< symbolic::SymbolExpr< internal::symbolic_last_tag >, symbolic::ValueExpr< Eigen::internal::FixedInt< 1 > > > lastp1(last+fix< 1 >())
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Index eval_expr_given_size(Index x, Index)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
symbolic::AddExpr< symbolic::ProductExpr< symbolic::AddExpr< SizeType, symbolic::ValueExpr< FixedInt<-1 > > >, symbolic::ValueExpr< IncrType > >, symbolic::ValueExpr<> > type
const FirstType & firstObject() const
const SizeType & sizeObject() const
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
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)
void reverse(const MatrixType &m)
internal::FixedInt< N > fix()
symbolic::AddExpr< FirstType, symbolic::ProductExpr< symbolic::AddExpr< SizeType, symbolic::ValueExpr< FixedInt<-1 > > >, symbolic::ValueExpr< IncrType > > > type
ArithmeticSequence< Index, typename make_size_type< SizeType >::type, IncrType > makeIndexedViewCompatible(const ArithmeticSequence< FirstType, SizeType, IncrType > &ids, Index size, SpecializedType)
internal::aseq_reverse_first_type< FirstType, SizeType, IncrType >::type ReverseFirstType
const Derived & derived() const
Definition: SymbolicIndex.h:80
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)
SpecializedType
Definition: Constants.h:309
Definition: pytypes.h:1370


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:33:53