EmulateArray.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) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
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_EMULATE_ARRAY_H
11 #define EIGEN_EMULATE_ARRAY_H
12 
13 
14 
15 // The array class is only available starting with cxx11. Emulate our own here
16 // if needed. Beware, msvc still doesn't advertise itself as a c++11 compiler!
17 // Moreover, CUDA doesn't support the STL containers, so we use our own instead.
18 #if (__cplusplus <= 199711L && EIGEN_COMP_MSVC < 1900) || defined(EIGEN_GPUCC) || defined(EIGEN_AVOID_STL_ARRAY)
19 
20 namespace Eigen {
21 template <typename T, size_t n> class array {
22  public:
24  EIGEN_STRONG_INLINE T& operator[] (size_t index) { eigen_internal_assert(index < size()); return values[index]; }
26  EIGEN_STRONG_INLINE const T& operator[] (size_t index) const { eigen_internal_assert(index < size()); return values[index]; }
27 
29  EIGEN_STRONG_INLINE T& at(size_t index) { eigen_assert(index < size()); return values[index]; }
31  EIGEN_STRONG_INLINE const T& at(size_t index) const { eigen_assert(index < size()); return values[index]; }
32 
34  EIGEN_STRONG_INLINE T& front() { return values[0]; }
36  EIGEN_STRONG_INLINE const T& front() const { return values[0]; }
37 
39  EIGEN_STRONG_INLINE T& back() { return values[n-1]; }
41  EIGEN_STRONG_INLINE const T& back() const { return values[n-1]; }
42 
44  static std::size_t size() { return n; }
45 
47 
52  EIGEN_STATIC_ASSERT(n==1, YOU_MADE_A_PROGRAMMING_MISTAKE)
53  values[0] = v;
54  }
56  EIGEN_STRONG_INLINE array(const T& v1, const T& v2) {
57  EIGEN_STATIC_ASSERT(n==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
58  values[0] = v1;
59  values[1] = v2;
60  }
62  EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3) {
63  EIGEN_STATIC_ASSERT(n==3, YOU_MADE_A_PROGRAMMING_MISTAKE)
64  values[0] = v1;
65  values[1] = v2;
66  values[2] = v3;
67  }
69  EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3,
70  const T& v4) {
71  EIGEN_STATIC_ASSERT(n==4, YOU_MADE_A_PROGRAMMING_MISTAKE)
72  values[0] = v1;
73  values[1] = v2;
74  values[2] = v3;
75  values[3] = v4;
76  }
78  EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3, const T& v4,
79  const T& v5) {
80  EIGEN_STATIC_ASSERT(n==5, YOU_MADE_A_PROGRAMMING_MISTAKE)
81  values[0] = v1;
82  values[1] = v2;
83  values[2] = v3;
84  values[3] = v4;
85  values[4] = v5;
86  }
88  EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3, const T& v4,
89  const T& v5, const T& v6) {
90  EIGEN_STATIC_ASSERT(n==6, YOU_MADE_A_PROGRAMMING_MISTAKE)
91  values[0] = v1;
92  values[1] = v2;
93  values[2] = v3;
94  values[3] = v4;
95  values[4] = v5;
96  values[5] = v6;
97  }
99  EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3, const T& v4,
100  const T& v5, const T& v6, const T& v7) {
101  EIGEN_STATIC_ASSERT(n==7, YOU_MADE_A_PROGRAMMING_MISTAKE)
102  values[0] = v1;
103  values[1] = v2;
104  values[2] = v3;
105  values[3] = v4;
106  values[4] = v5;
107  values[5] = v6;
108  values[6] = v7;
109  }
112  const T& v1, const T& v2, const T& v3, const T& v4,
113  const T& v5, const T& v6, const T& v7, const T& v8) {
114  EIGEN_STATIC_ASSERT(n==8, YOU_MADE_A_PROGRAMMING_MISTAKE)
115  values[0] = v1;
116  values[1] = v2;
117  values[2] = v3;
118  values[3] = v4;
119  values[4] = v5;
120  values[5] = v6;
121  values[6] = v7;
122  values[7] = v8;
123  }
124 
125 #if EIGEN_HAS_VARIADIC_TEMPLATES
127  EIGEN_STRONG_INLINE array(std::initializer_list<T> l) {
128  eigen_assert(l.size() == n);
129  internal::smart_copy(l.begin(), l.end(), values);
130  }
131 #endif
132 };
133 
134 
135 // Specialize array for zero size
136 template <typename T> class array<T, 0> {
137  public:
140  eigen_assert(false && "Can't index a zero size array");
141  return dummy;
142  }
144  EIGEN_STRONG_INLINE const T& operator[] (size_t) const {
145  eigen_assert(false && "Can't index a zero size array");
146  return dummy;
147  }
148 
151  eigen_assert(false && "Can't index a zero size array");
152  return dummy;
153  }
155  EIGEN_STRONG_INLINE const T& front() const {
156  eigen_assert(false && "Can't index a zero size array");
157  return dummy;
158  }
161  eigen_assert(false && "Can't index a zero size array");
162  return dummy;
163  }
165  EIGEN_STRONG_INLINE const T& back() const {
166  eigen_assert(false && "Can't index a zero size array");
167  return dummy;
168  }
169 
171 
174 
175 #if EIGEN_HAS_VARIADIC_TEMPLATES
176  EIGEN_DEVICE_FUNC array(std::initializer_list<T> l) : dummy() {
178  eigen_assert(l.size() == 0);
179  }
180 #endif
181 
182  private:
184 };
185 
186 // Comparison operator
187 // Todo: implement !=, <, <=, >, and >=
188 template<class T, std::size_t N>
189 EIGEN_DEVICE_FUNC bool operator==(const array<T,N>& lhs, const array<T,N>& rhs) {
190  for (std::size_t i = 0; i < N; ++i) {
191  if (lhs[i] != rhs[i]) {
192  return false;
193  }
194  }
195  return true;
196 }
197 
198 
199 namespace internal {
200 template<std::size_t I_, class T, std::size_t N>
202  return a[I_];
203 }
204 template<std::size_t I_, class T, std::size_t N>
206  return a[I_];
207 }
208 
209 template<class T, std::size_t N> struct array_size<array<T,N> > {
210  enum { value = N };
211 };
212 template<class T, std::size_t N> struct array_size<array<T,N>& > {
213  enum { value = N };
214 };
215 template<class T, std::size_t N> struct array_size<const array<T,N> > {
216  enum { value = N };
217 };
218 template<class T, std::size_t N> struct array_size<const array<T,N>& > {
219  enum { value = N };
220 };
221 
222 } // end namespace internal
223 } // end namespace Eigen
224 
225 #else
226 
227 // The compiler supports c++11, and we're not targeting cuda: use std::array as Eigen::array
228 #include <array>
229 namespace Eigen {
230 
231 template <typename T, std::size_t N> using array = std::array<T, N>;
232 
233 namespace internal {
234 /* std::get is only constexpr in C++14, not yet in C++11
235  * - libstdc++ from version 4.7 onwards has it nevertheless,
236  * so use that
237  * - libstdc++ older versions: use _M_instance directly
238  * - libc++ all versions so far: use __elems_ directly
239  * - all other libs: use std::get to be portable, but
240  * this may not be constexpr
241  */
242 #if defined(__GLIBCXX__) && __GLIBCXX__ < 20120322
243 #define STD_GET_ARR_HACK a._M_instance[I_]
244 #elif defined(_LIBCPP_VERSION)
245 #define STD_GET_ARR_HACK a.__elems_[I_]
246 #else
247 #define STD_GET_ARR_HACK std::template get<I_, T, N>(a)
248 #endif
249 
250 template<std::size_t I_, class T, std::size_t N> constexpr inline T& array_get(std::array<T,N>& a) { return (T&) STD_GET_ARR_HACK; }
251 template<std::size_t I_, class T, std::size_t N> constexpr inline T&& array_get(std::array<T,N>&& a) { return (T&&) STD_GET_ARR_HACK; }
252 template<std::size_t I_, class T, std::size_t N> constexpr inline T const& array_get(std::array<T,N> const& a) { return (T const&) STD_GET_ARR_HACK; }
253 
254 #undef STD_GET_ARR_HACK
255 
256 } // end namespace internal
257 } // end namespace Eigen
258 
259 #endif
260 
261 #endif // EIGEN_EMULATE_ARRAY_H
Eigen::array::array
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array(const T &v1, const T &v2, const T &v3, const T &v4, const T &v5, const T &v6, const T &v7)
Definition: EmulateArray.h:99
Eigen::array< T, 0 >::size
static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE std::size_t size()
Definition: EmulateArray.h:170
Eigen::internal::array_size::value
@ value
Definition: Meta.h:446
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::array
Definition: EmulateArray.h:21
Eigen::array< T, 0 >::array
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array()
Definition: EmulateArray.h:173
Eigen::array::array
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array(const T &v1, const T &v2, const T &v3, const T &v4, const T &v5, const T &v6, const T &v7, const T &v8)
Definition: EmulateArray.h:111
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
Eigen::array< T, 0 >::back
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T & back()
Definition: EmulateArray.h:160
Eigen::array::array
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array(const T &v1, const T &v2)
Definition: EmulateArray.h:56
pybind_wrapper_test_script.dummy
dummy
Definition: pybind_wrapper_test_script.py:42
eigen_internal_assert
#define eigen_internal_assert(x)
Definition: Macros.h:1043
Eigen::internal::array_get
const Index array_get(DimensionList< Index, Rank > &)
Definition: TensorDimensionList.h:39
n
int n
Definition: BiCGSTAB_simple.cpp:1
Eigen::array::array
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array(const T &v1, const T &v2, const T &v3, const T &v4, const T &v5)
Definition: EmulateArray.h:78
Eigen::array::front
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T & front()
Definition: EmulateArray.h:34
Eigen::array< T, 0 >::front
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T & front()
Definition: EmulateArray.h:150
EIGEN_UNUSED_VARIABLE
#define EIGEN_UNUSED_VARIABLE(var)
Definition: Macros.h:1076
Eigen::array::values
T values[n]
Definition: EmulateArray.h:46
l
static const Line3 l(Rot3(), 1, 1)
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::array::back
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE T & back() const
Definition: EmulateArray.h:41
EIGEN_ALWAYS_INLINE
#define EIGEN_ALWAYS_INLINE
Definition: Macros.h:932
Eigen::Triplet< double >
Eigen::array::array
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array(const T &v1, const T &v2, const T &v3, const T &v4)
Definition: EmulateArray.h:69
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:490
Eigen::array::array
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array()
Definition: EmulateArray.h:49
Eigen::array< T, 0 >::front
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE T & front() const
Definition: EmulateArray.h:155
Eigen::internal::array_size
Definition: Meta.h:445
Eigen::array< T, 0 >::back
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE T & back() const
Definition: EmulateArray.h:165
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
array
Definition: numpy.h:821
Eigen::array::back
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T & back()
Definition: EmulateArray.h:39
EIGEN_STATIC_ASSERT
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:127
Eigen::operator==
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator==(const Tuple< U, V > &x, const Tuple< U, V > &y)
Definition: TensorMeta.h:235
Eigen::array::size
EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE std::size_t size()
Definition: EmulateArray.h:44
v2
Vector v2
Definition: testSerializationBase.cpp:39
Eigen::array< T, 0 >::dummy
T dummy
Definition: EmulateArray.h:183
Eigen::array::at
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE T & at(size_t index) const
Definition: EmulateArray.h:31
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
Eigen::array::array
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array(const T &v)
Definition: EmulateArray.h:51
N
#define N
Definition: igam.h:9
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::smart_copy
EIGEN_DEVICE_FUNC void smart_copy(const T *start, const T *end, T *target)
Definition: Memory.h:515
Eigen::array::front
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE T & front() const
Definition: EmulateArray.h:36
v3
Vector v3
Definition: testSerializationBase.cpp:40
Eigen::array::array
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array(const T &v1, const T &v2, const T &v3)
Definition: EmulateArray.h:62
test_callbacks.value
value
Definition: test_callbacks.py:160
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::array::array
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE array(const T &v1, const T &v2, const T &v3, const T &v4, const T &v5, const T &v6)
Definition: EmulateArray.h:88
Eigen::array::operator[]
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T & operator[](size_t index)
Definition: EmulateArray.h:24
v1
Vector v1
Definition: testSerializationBase.cpp:38
Eigen::array::at
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T & at(size_t index)
Definition: EmulateArray.h:29


gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:01:05