special_numbers.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 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 Scalar> void special_numbers()
13 {
14  typedef Matrix<Scalar, Dynamic,Dynamic> MatType;
15  int rows = internal::random<int>(1,300);
16  int cols = internal::random<int>(1,300);
17 
18  Scalar nan = std::numeric_limits<Scalar>::quiet_NaN();
19  Scalar inf = std::numeric_limits<Scalar>::infinity();
20  Scalar s1 = internal::random<Scalar>();
21 
22  MatType m1 = MatType::Random(rows,cols),
23  mnan = MatType::Random(rows,cols),
24  minf = MatType::Random(rows,cols),
25  mboth = MatType::Random(rows,cols);
26 
27  int n = internal::random<int>(1,10);
28  for(int k=0; k<n; ++k)
29  {
30  mnan(internal::random<int>(0,rows-1), internal::random<int>(0,cols-1)) = nan;
31  minf(internal::random<int>(0,rows-1), internal::random<int>(0,cols-1)) = inf;
32  }
33  mboth = mnan + minf;
34 
35  VERIFY(!m1.hasNaN());
36  VERIFY(m1.allFinite());
37 
38  VERIFY(mnan.hasNaN());
39  VERIFY((s1*mnan).hasNaN());
40  VERIFY(!minf.hasNaN());
41  VERIFY(!(2*minf).hasNaN());
42  VERIFY(mboth.hasNaN());
43  VERIFY(mboth.array().hasNaN());
44 
45  VERIFY(!mnan.allFinite());
46  VERIFY(!minf.allFinite());
47  VERIFY(!(minf-mboth).allFinite());
48  VERIFY(!mboth.allFinite());
49  VERIFY(!mboth.array().allFinite());
50 }
51 
53 {
54  for(int i = 0; i < 10*g_repeat; i++) {
55  CALL_SUBTEST_1( special_numbers<float>() );
56  CALL_SUBTEST_1( special_numbers<double>() );
57  }
58 }
special_numbers
void special_numbers()
Definition: special_numbers.cpp:12
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(special_numbers)
Definition: special_numbers.cpp:52
m1
Matrix3d m1
Definition: IOFormat.cpp:2
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
n
int n
Definition: BiCGSTAB_simple.cpp:1
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
Eigen::g_repeat
static int g_repeat
Definition: main.h:169
main.h
Eigen::Matrix< Scalar, Dynamic, Dynamic >
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
inf
static double inf
Definition: testMatrix.cpp:31
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
VERIFY
#define VERIFY(a)
Definition: main.h:380


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:14:01