numext.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 #include "main.h"
11 
12 template<typename T>
13 void check_abs() {
14  typedef typename NumTraits<T>::Real Real;
15 
17  VERIFY_IS_EQUAL(numext::abs(-T(1)), T(1));
18  VERIFY_IS_EQUAL(numext::abs(T(0)), T(0));
19  VERIFY_IS_EQUAL(numext::abs(T(1)), T(1));
20 
21  for(int k=0; k<g_repeat*100; ++k)
22  {
23  T x = internal::random<T>();
25  x = x/Real(2);
27  {
29  VERIFY( numext::abs(-x) >= Real(0));
30  }
31  VERIFY( numext::abs(x) >= Real(0));
33  }
34 }
35 
36 void test_numext() {
37  CALL_SUBTEST( check_abs<bool>() );
38  CALL_SUBTEST( check_abs<signed char>() );
39  CALL_SUBTEST( check_abs<unsigned char>() );
40  CALL_SUBTEST( check_abs<short>() );
41  CALL_SUBTEST( check_abs<unsigned short>() );
42  CALL_SUBTEST( check_abs<int>() );
43  CALL_SUBTEST( check_abs<unsigned int>() );
44  CALL_SUBTEST( check_abs<long>() );
45  CALL_SUBTEST( check_abs<unsigned long>() );
46  CALL_SUBTEST( check_abs<half>() );
47  CALL_SUBTEST( check_abs<float>() );
48  CALL_SUBTEST( check_abs<double>() );
49  CALL_SUBTEST( check_abs<long double>() );
50 
51  CALL_SUBTEST( check_abs<std::complex<float> >() );
52  CALL_SUBTEST( check_abs<std::complex<double> >() );
53 }
void test_numext()
Definition: numext.cpp:36
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:150
void check_abs()
Definition: numext.cpp:13
#define VERIFY_IS_APPROX(a, b)
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:331
static int g_repeat
Definition: main.h:144
Eigen::Triplet< double > T
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Abs2ReturnType abs2() const
mp::number< mp::cpp_dec_float< 100 >, mp::et_on > Real
#define CALL_SUBTEST(FUNC)
Definition: main.h:342
#define VERIFY(a)
Definition: main.h:325
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
#define abs(x)
Definition: datatypes.h:17


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:05