mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_tools.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_TESTS_TEST_TOOLS_HPP
13 #define MLPACK_TESTS_TEST_TOOLS_HPP
14 
15 #include <boost/version.hpp>
16 
17 // This is only necessary for pre-1.36 Boost.Test.
18 #if BOOST_VERSION < 103600
19 
20 #include <boost/test/floating_point_comparison.hpp>
21 #include <boost/test/auto_unit_test.hpp>
22 
23 // This depends on other macros. Probably not a great idea... but it works, and
24 // we only need it for ancient Boost versions.
25 #define BOOST_REQUIRE_GE( L, R ) \
26  BOOST_REQUIRE_EQUAL( (L >= R), true )
27 
28 #define BOOST_REQUIRE_NE( L, R ) \
29  BOOST_REQUIRE_EQUAL( (L != R), true )
30 
31 #define BOOST_REQUIRE_LE( L, R ) \
32  BOOST_REQUIRE_EQUAL( (L <= R), true )
33 
34 #define BOOST_REQUIRE_LT( L, R ) \
35  BOOST_REQUIRE_EQUAL( (L < R), true )
36 
37 #define BOOST_REQUIRE_GT( L, R ) \
38  BOOST_REQUIRE_EQUAL( (L > R), true )
39 
40 #endif
41 
42 // Require the approximation L to be within a relative error of E respect to the
43 // actual value R.
44 #define REQUIRE_RELATIVE_ERR( L, R, E ) \
45  BOOST_REQUIRE_LE( std::abs((R) - (L)), (E) * std::abs(R))
46 
47 #include <mlpack/prereqs.hpp>
48 
49 // Check the values of two matrices.
50 inline void CheckMatrices(const arma::mat& a, const arma::mat& b,
51  double tolerance = 1e-5)
52 {
53  BOOST_REQUIRE_EQUAL(a.n_rows, b.n_rows);
54  BOOST_REQUIRE_EQUAL(a.n_cols, b.n_cols);
55 
56  for (size_t i = 0; i < a.n_elem; ++i)
57  {
58  if (std::abs(a[i]) < tolerance / 2)
59  BOOST_REQUIRE_SMALL(b[i], tolerance / 2);
60  else
61  BOOST_REQUIRE_CLOSE(a[i], b[i], tolerance);
62  }
63 }
64 
65 // Check the values of two unsigned matrices.
66 inline void CheckMatrices(const arma::Mat<size_t>& a, const arma::Mat<size_t>& b)
67 {
68  BOOST_REQUIRE_EQUAL(a.n_rows, b.n_rows);
69  BOOST_REQUIRE_EQUAL(a.n_cols, b.n_cols);
70 
71  for (size_t i = 0; i < a.n_elem; ++i)
72  BOOST_REQUIRE_EQUAL(a[i], b[i]);
73 }
74 
75 #endif
The core includes that mlpack expects; standard C++ includes and Armadillo.
void CheckMatrices(const arma::mat &x, const arma::mat &xmlX, const arma::mat &textX, const arma::mat &binaryX)