cxx11_meta.cpp
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) 2013 Christian Seiler <christian@iwakd.de>
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 #include "main.h"
11 
12 #include <array>
14 
49 
50 struct dummy_a {};
51 struct dummy_b {};
52 struct dummy_c {};
53 struct dummy_d {};
54 struct dummy_e {};
55 
56 // dummy operation for testing apply
57 template<typename A, typename B> struct dummy_op;
58 template<> struct dummy_op<dummy_a, dummy_b> { typedef dummy_c type; };
59 template<> struct dummy_op<dummy_b, dummy_a> { typedef dummy_d type; };
60 template<> struct dummy_op<dummy_b, dummy_c> { typedef dummy_a type; };
61 template<> struct dummy_op<dummy_c, dummy_b> { typedef dummy_d type; };
62 template<> struct dummy_op<dummy_c, dummy_a> { typedef dummy_b type; };
63 template<> struct dummy_op<dummy_a, dummy_c> { typedef dummy_d type; };
64 template<> struct dummy_op<dummy_a, dummy_a> { typedef dummy_e type; };
65 template<> struct dummy_op<dummy_b, dummy_b> { typedef dummy_e type; };
66 template<> struct dummy_op<dummy_c, dummy_c> { typedef dummy_e type; };
67 
68 template<typename A, typename B> struct dummy_test { constexpr static bool value = false; constexpr static int global_flags = 0; };
69 template<> struct dummy_test<dummy_a, dummy_a> { constexpr static bool value = true; constexpr static int global_flags = 1; };
70 template<> struct dummy_test<dummy_b, dummy_b> { constexpr static bool value = true; constexpr static int global_flags = 2; };
71 template<> struct dummy_test<dummy_c, dummy_c> { constexpr static bool value = true; constexpr static int global_flags = 4; };
72 
73 struct times2_op { template<typename A> static A run(A v) { return v * 2; } };
74 
75 struct dummy_inst
76 {
77  int c;
78 
79  dummy_inst() : c(0) {}
80  explicit dummy_inst(int) : c(1) {}
81  dummy_inst(int, int) : c(2) {}
82  dummy_inst(int, int, int) : c(3) {}
83  dummy_inst(int, int, int, int) : c(4) {}
84  dummy_inst(int, int, int, int, int) : c(5) {}
85 };
86 
87 static void test_gen_numeric_list()
88 {
94 
100 
106 
112 
118 
124 
130 }
131 
132 static void test_concat()
133 {
139 
145 
151 
157 }
158 
159 static void test_slice()
160 {
163 
171 
179 
187 
195 
200 }
201 
202 static void test_get()
203 {
206 
213 
220 }
221 
223 {
224  (void)a;
225  (void)b;
226  (void)c;
227 }
228 
229 template<int... ii>
230 static void test_id_numeric()
231 {
233 }
234 
235 template<typename... tt>
236 static void test_id_type()
237 {
239 }
240 
241 static void test_id()
242 {
243  // don't call VERIFY here, just assume it works if it compiles
244  // (otherwise it will complain that it can't find the function)
245  test_id_numeric<1, 4, 6>();
246  test_id_type<dummy_a, dummy_b, dummy_c>();
247 }
248 
249 static void test_is_same_gf()
250 {
255 }
256 
257 static void test_apply_op()
258 {
262 }
263 
265 {
267 
273 
279 
285 }
286 
287 static void test_arg_reductions()
288 {
289  VERIFY_IS_EQUAL(arg_sum(1,2,3,4), 10);
290  VERIFY_IS_EQUAL(arg_prod(1,2,3,4), 24);
291  VERIFY_IS_APPROX(arg_sum(0.5, 2, 5), 7.5);
292  VERIFY_IS_APPROX(arg_prod(0.5, 2, 5), 5.0);
293 }
294 
296 {
297  array<int, 6> a{{4, 8, 15, 16, 23, 42}};
298  array<int, 6> b{{42, 23, 16, 15, 8, 4}};
299 
300  // there is no operator<< for std::array, so VERIFY_IS_EQUAL will
301  // not compile
302  VERIFY((array_reverse(a) == b));
303  VERIFY((array_reverse(b) == a));
304  VERIFY_IS_EQUAL((array_sum(a)), 108);
305  VERIFY_IS_EQUAL((array_sum(b)), 108);
306  VERIFY_IS_EQUAL((array_prod(a)), 7418880);
307  VERIFY_IS_EQUAL((array_prod(b)), 7418880);
308 }
309 
311 {
312  array<int, 6> a{{4, 8, 15, 16, 23, 42}};
313  array<int, 6> b{{0, 1, 2, 3, 4, 5}};
314  array<int, 6> c{{4, 9, 17, 19, 27, 47}};
315  array<int, 6> d{{0, 8, 30, 48, 92, 210}};
316  array<int, 6> e{{0, 2, 4, 6, 8, 10}};
317 
318  VERIFY((array_zip<sum_op>(a, b) == c));
319  VERIFY((array_zip<product_op>(a, b) == d));
320  VERIFY((array_apply<times2_op>(b) == e));
321  VERIFY_IS_EQUAL((array_apply_and_reduce<sum_op, times2_op>(a)), 216);
322  VERIFY_IS_EQUAL((array_apply_and_reduce<sum_op, times2_op>(b)), 30);
323  VERIFY_IS_EQUAL((array_zip_and_reduce<product_op, sum_op>(a, b)), 14755932);
324  VERIFY_IS_EQUAL((array_zip_and_reduce<sum_op, product_op>(a, b)), 388);
325 }
326 
327 static void test_array_misc()
328 {
329  array<int, 3> a3{{1, 1, 1}};
330  array<int, 6> a6{{2, 2, 2, 2, 2, 2}};
331  VERIFY((repeat<3, int>(1) == a3));
332  VERIFY((repeat<6, int>(2) == a6));
333 
334  int data[5] = { 0, 1, 2, 3, 4 };
335  VERIFY_IS_EQUAL((instantiate_by_c_array<dummy_inst, int, 0>(data).c), 0);
336  VERIFY_IS_EQUAL((instantiate_by_c_array<dummy_inst, int, 1>(data).c), 1);
337  VERIFY_IS_EQUAL((instantiate_by_c_array<dummy_inst, int, 2>(data).c), 2);
338  VERIFY_IS_EQUAL((instantiate_by_c_array<dummy_inst, int, 3>(data).c), 3);
339  VERIFY_IS_EQUAL((instantiate_by_c_array<dummy_inst, int, 4>(data).c), 4);
340  VERIFY_IS_EQUAL((instantiate_by_c_array<dummy_inst, int, 5>(data).c), 5);
341 }
342 
344 {
357 }
Eigen::internal::array_reverse
constexpr EIGEN_STRONG_INLINE array< T, N > array_reverse(array< T, N > arr)
Definition: CXX11Meta.h:344
Eigen::internal::concat
Definition: CXX11Meta.h:65
Eigen::internal::arg_prod
constexpr EIGEN_DEVICE_FUNCdecltype(reduce< product_op, Ts... >::run((*((Ts *) 0))...)) EIGEN_STRONG_INLIN arg_prod)(Ts... ts)
Definition: CXX11Meta.h:324
Eigen::internal::array_sum
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE auto array_sum(const array< T, N > &arr) -> decltype(array_reduce< sum_op, T, N >(arr, static_cast< T >(0)))
Definition: CXX11Meta.h:392
test_is_same_gf
static void test_is_same_gf()
Definition: cxx11_meta.cpp:249
dummy_op< dummy_a, dummy_a >::type
dummy_e type
Definition: cxx11_meta.cpp:64
Eigen::internal::contained_in_list
Definition: CXX11Meta.h:186
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
Eigen::internal::instantiate_by_c_array
InstType instantiate_by_c_array(ArrType *arr)
Definition: CXX11Meta.h:528
Eigen::internal::id_numeric
Definition: CXX11Meta.h:129
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
d
static const double d[K][N]
Definition: igam.h:11
Eigen::internal::slice
Definition: CXX11Meta.h:111
Eigen::internal::array_zip_and_reduce
constexpr EIGEN_STRONG_INLINE auto array_zip_and_reduce(array< A, N > a, array< B, N > b) -> decltype(h_array_zip_and_reduce< Reducer, Op, A, B, N >(a, b, typename gen_numeric_list< int, N >::type()))
Definition: CXX11Meta.h:434
Eigen::internal::arg_sum
constexpr decltype(reduce< sum_op, Ts... >::run((*((Ts *) 0))...)) EIGEN_STRONG_INLIN arg_sum)(Ts... ts)
Definition: CXX11Meta.h:330
Eigen::array
Definition: EmulateArray.h:21
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
dummy_inst
Definition: cxx11_meta.cpp:75
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
b
Scalar * b
Definition: benchVecAdd.cpp:17
test_array_misc
static void test_array_misc()
Definition: cxx11_meta.cpp:327
test_array_zip_and_apply
static void test_array_zip_and_apply()
Definition: cxx11_meta.cpp:310
test_id_numeric
static void test_id_numeric()
Definition: cxx11_meta.cpp:230
test_apply_op
static void test_apply_op()
Definition: cxx11_meta.cpp:257
dummy_d
Definition: cxx11_meta.cpp:53
test_get
static void test_get()
Definition: cxx11_meta.cpp:202
Eigen::internal::array_reduce
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE auto array_reduce(const array< T, N > &arr, T identity) -> decltype(h_array_reduce< Reducer, T, N >::run(arr, identity))
Definition: CXX11Meta.h:384
Eigen::internal::mconcat
Definition: CXX11Meta.h:70
Eigen::internal::gen_numeric_list_swapped_pair
Definition: CXX11Meta.h:57
Eigen::internal::array_apply_and_reduce
constexpr EIGEN_STRONG_INLINE auto array_apply_and_reduce(array< A, N > a) -> decltype(h_array_apply_and_reduce< Reducer, Op, A, N >(a, typename gen_numeric_list< int, N >::type()))
Definition: CXX11Meta.h:462
test_gen_numeric_list
static void test_gen_numeric_list()
Definition: cxx11_meta.cpp:87
dummy_op
Definition: cxx11_meta.cpp:57
dummy_op< dummy_b, dummy_a >::type
dummy_d type
Definition: cxx11_meta.cpp:59
dummy_inst::dummy_inst
dummy_inst(int, int)
Definition: cxx11_meta.cpp:81
dummy_inst::dummy_inst
dummy_inst()
Definition: cxx11_meta.cpp:79
align_3::a3
Point2 a3
Definition: testPose2.cpp:771
dummy_a
Definition: cxx11_meta.cpp:50
data
int data[]
Definition: Map_placement_new.cpp:1
Eigen::internal::apply_op_from_right
Definition: CXX11Meta.h:176
dummy_inst::dummy_inst
dummy_inst(int, int, int, int, int)
Definition: cxx11_meta.cpp:84
Eigen::internal::get
Definition: CXX11Meta.h:115
test_id
static void test_id()
Definition: cxx11_meta.cpp:241
test_id_helper
static void test_id_helper(dummy_a a, dummy_a b, dummy_a c)
Definition: cxx11_meta.cpp:222
Eigen::internal::gen_numeric_list_repeated
Definition: CXX11Meta.h:60
dummy_op< dummy_b, dummy_c >::type
dummy_a type
Definition: cxx11_meta.cpp:60
dummy_op< dummy_a, dummy_c >::type
dummy_d type
Definition: cxx11_meta.cpp:63
dummy_test::value
constexpr static bool value
Definition: cxx11_meta.cpp:68
Eigen::internal::repeat
constexpr array< t, n > repeat(t v)
Definition: CXX11Meta.h:483
Eigen::internal::take
Definition: CXX11Meta.h:77
Eigen::internal::gen_numeric_list
Definition: CXX11Meta.h:51
dummy_e
Definition: cxx11_meta.cpp:54
times2_op::run
static A run(A v)
Definition: cxx11_meta.cpp:73
dummy_op< dummy_c, dummy_c >::type
dummy_e type
Definition: cxx11_meta.cpp:66
concat
constexpr descr< 0 > concat()
Definition: descr.h:139
Eigen::internal::array_apply
constexpr EIGEN_STRONG_INLINE array< decltype(Op::run(A())), N > array_apply(array< A, N > a)
Definition: CXX11Meta.h:448
Eigen::internal::gen_numeric_list_reversed
Definition: CXX11Meta.h:54
E1::A
@ A
Eigen::internal::array_zip
constexpr EIGEN_STRONG_INLINE array< decltype(Op::run(A(), B())), N > array_zip(array< A, N > a, array< B, N > b)
Definition: CXX11Meta.h:420
Eigen::internal::type_list
Definition: CXX11Meta.h:29
test_contained_in_list
static void test_contained_in_list()
Definition: cxx11_meta.cpp:264
dummy_op< dummy_c, dummy_a >::type
dummy_b type
Definition: cxx11_meta.cpp:62
Eigen::internal::array_prod
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes< Indices... > &)
Definition: TensorDimensions.h:140
dummy_b
Definition: cxx11_meta.cpp:51
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:15
Eigen::internal::numeric_list
Definition: CXX11Meta.h:35
times2_op
Definition: cxx11_meta.cpp:73
Eigen::internal::sum_op
Definition: CXX11Meta.h:292
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
test_concat
static void test_concat()
Definition: cxx11_meta.cpp:132
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_meta)
Definition: cxx11_meta.cpp:343
main.h
Eigen::internal::contained_in_list_gf
Definition: CXX11Meta.h:223
Eigen::internal::skip
Definition: CXX11Meta.h:109
dummy_inst::dummy_inst
dummy_inst(int, int, int)
Definition: cxx11_meta.cpp:82
test_slice
static void test_slice()
Definition: cxx11_meta.cpp:159
test_arg_reductions
static void test_arg_reductions()
Definition: cxx11_meta.cpp:287
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
dummy_test::global_flags
constexpr static int global_flags
Definition: cxx11_meta.cpp:68
dummy_op< dummy_b, dummy_b >::type
dummy_e type
Definition: cxx11_meta.cpp:65
dummy_test
Definition: cxx11_meta.cpp:68
Eigen::internal::is_same
Definition: Meta.h:148
test_id_type
static void test_id_type()
Definition: cxx11_meta.cpp:236
CXX11Meta.h
test_array_reverse_and_reduce
static void test_array_reverse_and_reduce()
Definition: cxx11_meta.cpp:295
Eigen::internal::id_type
Definition: CXX11Meta.h:130
dummy_op< dummy_a, dummy_b >::type
dummy_c type
Definition: cxx11_meta.cpp:58
dummy_op< dummy_c, dummy_b >::type
dummy_d type
Definition: cxx11_meta.cpp:61
Eigen::internal::apply_op_from_left
Definition: CXX11Meta.h:169
dummy_inst::c
int c
Definition: cxx11_meta.cpp:77
get
Container::iterator get(Container &c, Position position)
Definition: stdlist_overload.cpp:29
test_callbacks.value
value
Definition: test_callbacks.py:160
dummy_inst::dummy_inst
dummy_inst(int)
Definition: cxx11_meta.cpp:80
Eigen::internal::product_op
Definition: CXX11Meta.h:296
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition: main.h:399
dummy_c
Definition: cxx11_meta.cpp:52
VERIFY
#define VERIFY(a)
Definition: main.h:380
dummy_inst::dummy_inst
dummy_inst(int, int, int, int)
Definition: cxx11_meta.cpp:83
Eigen::internal::is_same_gf
Definition: CXX11Meta.h:134


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:07