symbolic_index.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) 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 #ifdef EIGEN_TEST_PART_2
11 #define EIGEN_MAX_CPP_VER 03
12 
13 // see indexed_view.cpp
14 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
15  #pragma GCC diagnostic ignored "-Wdeprecated"
16 #endif
17 
18 #endif
19 
20 #include "main.h"
21 
22 template<typename T1,typename T2>
23 bool is_same_symb(const T1& a, const T2& b, Index size)
24 {
25  return a.eval(last=size-1) == b.eval(last=size-1);
26 }
27 
28 template<typename T>
29 void check_is_symbolic(const T&) {
31 }
32 
33 template<typename T>
34 void check_isnot_symbolic(const T&) {
36 }
37 
38 #define VERIFY_EQ_INT(A,B) VERIFY_IS_APPROX(int(A),int(B))
39 
41 {
47  check_isnot_symbolic(fix<3>());
48 
49  Index size=100;
50 
51  // First, let's check FixedInt arithmetic:
52  VERIFY( is_same_type( (fix<5>()-fix<3>())*fix<9>()/(-fix<3>()), fix<-(5-3)*9/3>() ) );
53  VERIFY( is_same_type( (fix<5>()-fix<3>())*fix<9>()/fix<2>(), fix<(5-3)*9/2>() ) );
54  VERIFY( is_same_type( fix<9>()/fix<2>(), fix<9/2>() ) );
55  VERIFY( is_same_type( fix<9>()%fix<2>(), fix<9%2>() ) );
56  VERIFY( is_same_type( fix<9>()&fix<2>(), fix<9&2>() ) );
57  VERIFY( is_same_type( fix<9>()|fix<2>(), fix<9|2>() ) );
58  VERIFY( is_same_type( fix<9>()/2, int(9/2) ) );
59 
60  VERIFY( is_same_symb( lastp1-1, last, size) );
61  VERIFY( is_same_symb( lastp1-fix<1>, last, size) );
62 
63  VERIFY_IS_EQUAL( ( (last*5-2)/3 ).eval(last=size-1), ((size-1)*5-2)/3 );
64  VERIFY_IS_EQUAL( ( (last*fix<5>-fix<2>)/fix<3> ).eval(last=size-1), ((size-1)*5-2)/3 );
65  VERIFY_IS_EQUAL( ( -last*lastp1 ).eval(last=size-1), -(size-1)*size );
66  VERIFY_IS_EQUAL( ( lastp1-3*last ).eval(last=size-1), size- 3*(size-1) );
67  VERIFY_IS_EQUAL( ( (lastp1-3*last)/lastp1 ).eval(last=size-1), (size- 3*(size-1))/size );
68 
69 #if EIGEN_HAS_CXX14
70  {
71  struct x_tag {}; static const symbolic::SymbolExpr<x_tag> x;
72  struct y_tag {}; static const symbolic::SymbolExpr<y_tag> y;
73  struct z_tag {}; static const symbolic::SymbolExpr<z_tag> z;
74 
75  VERIFY_IS_APPROX( int(((x+3)/y+z).eval(x=6,y=3,z=-13)), (6+3)/3+(-13) );
76  }
77 #endif
78 }
79 
80 EIGEN_DECLARE_TEST(symbolic_index)
81 {
84 }
Scalar * y
Scalar * b
Definition: benchVecAdd.cpp:17
#define STATIC_CHECK(COND)
Definition: main.h:397
static const Pose3 T2(Rot3::Rodrigues(0.3, 0.2, 0.1), P2)
static const symbolic::SymbolExpr< internal::symbolic_last_tag > last
void check_isnot_symbolic(const T &)
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
#define VERIFY_IS_APPROX(a, b)
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
#define CALL_SUBTEST_1(FUNC)
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
void check_symbolic_index()
void check_is_symbolic(const T &)
EIGEN_DECLARE_TEST(symbolic_index)
internal::enable_if< internal::is_same< T1, T2 >::value, bool >::type is_same_type(const T1 &, const T2 &)
Definition: main.h:410
#define VERIFY(a)
Definition: main.h:380
static const Similarity3 T1(R, Point3(3.5, -8.2, 4.2), 1)
internal::FixedInt< N > fix()
#define CALL_SUBTEST_2(FUNC)
bool is_same_symb(const T1 &a, const T2 &b, Index size)
internal::nested_eval< T, 1 >::type eval(const T &xpr)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:36:34