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 
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 }
check_isnot_symbolic
void check_isnot_symbolic(const T &)
Definition: symbolic_index.cpp:34
check_is_symbolic
void check_is_symbolic(const T &)
Definition: symbolic_index.cpp:29
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
b
Scalar * b
Definition: benchVecAdd.cpp:17
x
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
Definition: gnuplot_common_settings.hh:12
Eigen::fix
internal::FixedInt< N > fix()
Definition: IntegralConstant.h:192
Eigen::symbolic::is_symbolic
Definition: SymbolicIndex.h:189
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(symbolic_index)
Definition: symbolic_index.cpp:80
Eigen::is_same_type
internal::enable_if< internal::is_same< T1, T2 >::value, bool >::type is_same_type(const T1 &, const T2 &)
Definition: main.h:410
Eigen::last
static const symbolic::SymbolExpr< internal::symbolic_last_tag > last
Definition: IndexedViewHelper.h:38
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
pybind_wrapper_test_script.z
z
Definition: pybind_wrapper_test_script.py:61
T2
static const Pose3 T2(Rot3::Rodrigues(0.3, 0.2, 0.1), P2)
Eigen::Triplet< double >
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
y
Scalar * y
Definition: level1_cplx_impl.h:124
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:15
check_symbolic_index
void check_symbolic_index()
Definition: symbolic_index.cpp:40
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
main.h
Eigen::lastp1
static const symbolic::AddExpr< symbolic::SymbolExpr< internal::symbolic_last_tag >, symbolic::ValueExpr< Eigen::internal::FixedInt< 1 > > > lastp1(last+fix< 1 >())
T1
static const Similarity3 T1(R, Point3(3.5, -8.2, 4.2), 1)
is_same_symb
bool is_same_symb(const T1 &a, const T2 &b, Index size)
Definition: symbolic_index.cpp:23
eval
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition: sparse_permutations.cpp:38
STATIC_CHECK
#define STATIC_CHECK(COND)
Definition: main.h:397
VERIFY
#define VERIFY(a)
Definition: main.h:380
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::symbolic::SymbolExpr
Definition: SymbolicIndex.h:213


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:05:21