1*bf2c3715SXin Li // This file is part of Eigen, a lightweight C++ template library
2*bf2c3715SXin Li // for linear algebra.
3*bf2c3715SXin Li //
4*bf2c3715SXin Li // Copyright (C) 2017 Gael Guennebaud <[email protected]>
5*bf2c3715SXin Li //
6*bf2c3715SXin Li // This Source Code Form is subject to the terms of the Mozilla
7*bf2c3715SXin Li // Public License v. 2.0. If a copy of the MPL was not distributed
8*bf2c3715SXin Li // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9*bf2c3715SXin Li
10*bf2c3715SXin Li #ifdef EIGEN_TEST_PART_2
11*bf2c3715SXin Li #define EIGEN_MAX_CPP_VER 03
12*bf2c3715SXin Li
13*bf2c3715SXin Li // see indexed_view.cpp
14*bf2c3715SXin Li #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
15*bf2c3715SXin Li #pragma GCC diagnostic ignored "-Wdeprecated"
16*bf2c3715SXin Li #endif
17*bf2c3715SXin Li
18*bf2c3715SXin Li #endif
19*bf2c3715SXin Li
20*bf2c3715SXin Li #include "main.h"
21*bf2c3715SXin Li
22*bf2c3715SXin Li template<typename T1,typename T2>
is_same_symb(const T1 & a,const T2 & b,Index size)23*bf2c3715SXin Li bool is_same_symb(const T1& a, const T2& b, Index size)
24*bf2c3715SXin Li {
25*bf2c3715SXin Li return a.eval(last=size-1) == b.eval(last=size-1);
26*bf2c3715SXin Li }
27*bf2c3715SXin Li
28*bf2c3715SXin Li template<typename T>
check_is_symbolic(const T &)29*bf2c3715SXin Li void check_is_symbolic(const T&) {
30*bf2c3715SXin Li STATIC_CHECK(( symbolic::is_symbolic<T>::value ))
31*bf2c3715SXin Li }
32*bf2c3715SXin Li
33*bf2c3715SXin Li template<typename T>
check_isnot_symbolic(const T &)34*bf2c3715SXin Li void check_isnot_symbolic(const T&) {
35*bf2c3715SXin Li STATIC_CHECK(( !symbolic::is_symbolic<T>::value ))
36*bf2c3715SXin Li }
37*bf2c3715SXin Li
38*bf2c3715SXin Li #define VERIFY_EQ_INT(A,B) VERIFY_IS_APPROX(int(A),int(B))
39*bf2c3715SXin Li
check_symbolic_index()40*bf2c3715SXin Li void check_symbolic_index()
41*bf2c3715SXin Li {
42*bf2c3715SXin Li check_is_symbolic(last);
43*bf2c3715SXin Li check_is_symbolic(lastp1);
44*bf2c3715SXin Li check_is_symbolic(last+1);
45*bf2c3715SXin Li check_is_symbolic(last-lastp1);
46*bf2c3715SXin Li check_is_symbolic(2*last-lastp1/2);
47*bf2c3715SXin Li check_isnot_symbolic(fix<3>());
48*bf2c3715SXin Li
49*bf2c3715SXin Li Index size=100;
50*bf2c3715SXin Li
51*bf2c3715SXin Li // First, let's check FixedInt arithmetic:
52*bf2c3715SXin Li VERIFY( is_same_type( (fix<5>()-fix<3>())*fix<9>()/(-fix<3>()), fix<-(5-3)*9/3>() ) );
53*bf2c3715SXin Li VERIFY( is_same_type( (fix<5>()-fix<3>())*fix<9>()/fix<2>(), fix<(5-3)*9/2>() ) );
54*bf2c3715SXin Li VERIFY( is_same_type( fix<9>()/fix<2>(), fix<9/2>() ) );
55*bf2c3715SXin Li VERIFY( is_same_type( fix<9>()%fix<2>(), fix<9%2>() ) );
56*bf2c3715SXin Li VERIFY( is_same_type( fix<9>()&fix<2>(), fix<9&2>() ) );
57*bf2c3715SXin Li VERIFY( is_same_type( fix<9>()|fix<2>(), fix<9|2>() ) );
58*bf2c3715SXin Li VERIFY( is_same_type( fix<9>()/2, int(9/2) ) );
59*bf2c3715SXin Li
60*bf2c3715SXin Li VERIFY( is_same_symb( lastp1-1, last, size) );
61*bf2c3715SXin Li VERIFY( is_same_symb( lastp1-fix<1>, last, size) );
62*bf2c3715SXin Li
63*bf2c3715SXin Li VERIFY_IS_EQUAL( ( (last*5-2)/3 ).eval(last=size-1), ((size-1)*5-2)/3 );
64*bf2c3715SXin Li VERIFY_IS_EQUAL( ( (last*fix<5>-fix<2>)/fix<3> ).eval(last=size-1), ((size-1)*5-2)/3 );
65*bf2c3715SXin Li VERIFY_IS_EQUAL( ( -last*lastp1 ).eval(last=size-1), -(size-1)*size );
66*bf2c3715SXin Li VERIFY_IS_EQUAL( ( lastp1-3*last ).eval(last=size-1), size- 3*(size-1) );
67*bf2c3715SXin Li VERIFY_IS_EQUAL( ( (lastp1-3*last)/lastp1 ).eval(last=size-1), (size- 3*(size-1))/size );
68*bf2c3715SXin Li
69*bf2c3715SXin Li #if EIGEN_HAS_CXX14
70*bf2c3715SXin Li {
71*bf2c3715SXin Li struct x_tag {}; static const symbolic::SymbolExpr<x_tag> x;
72*bf2c3715SXin Li struct y_tag {}; static const symbolic::SymbolExpr<y_tag> y;
73*bf2c3715SXin Li struct z_tag {}; static const symbolic::SymbolExpr<z_tag> z;
74*bf2c3715SXin Li
75*bf2c3715SXin Li VERIFY_IS_APPROX( int(((x+3)/y+z).eval(x=6,y=3,z=-13)), (6+3)/3+(-13) );
76*bf2c3715SXin Li }
77*bf2c3715SXin Li #endif
78*bf2c3715SXin Li }
79*bf2c3715SXin Li
EIGEN_DECLARE_TEST(symbolic_index)80*bf2c3715SXin Li EIGEN_DECLARE_TEST(symbolic_index)
81*bf2c3715SXin Li {
82*bf2c3715SXin Li CALL_SUBTEST_1( check_symbolic_index() );
83*bf2c3715SXin Li CALL_SUBTEST_2( check_symbolic_index() );
84*bf2c3715SXin Li }
85