12 #ifndef MLPACK_TESTS_TEST_TOOLS_HPP 13 #define MLPACK_TESTS_TEST_TOOLS_HPP 15 #include <boost/version.hpp> 18 #if BOOST_VERSION < 103600 20 #include <boost/test/floating_point_comparison.hpp> 21 #include <boost/test/auto_unit_test.hpp> 25 #define BOOST_REQUIRE_GE( L, R ) \ 26 BOOST_REQUIRE_EQUAL( (L >= R), true ) 28 #define BOOST_REQUIRE_NE( L, R ) \ 29 BOOST_REQUIRE_EQUAL( (L != R), true ) 31 #define BOOST_REQUIRE_LE( L, R ) \ 32 BOOST_REQUIRE_EQUAL( (L <= R), true ) 34 #define BOOST_REQUIRE_LT( L, R ) \ 35 BOOST_REQUIRE_EQUAL( (L < R), true ) 37 #define BOOST_REQUIRE_GT( L, R ) \ 38 BOOST_REQUIRE_EQUAL( (L > R), true ) 44 #define REQUIRE_RELATIVE_ERR( L, R, E ) \ 45 BOOST_REQUIRE_LE( std::abs((R) - (L)), (E) * std::abs(R)) 51 double tolerance = 1e-5)
53 BOOST_REQUIRE_EQUAL(a.n_rows, b.n_rows);
54 BOOST_REQUIRE_EQUAL(a.n_cols, b.n_cols);
56 for (
size_t i = 0; i < a.n_elem; ++i)
58 if (std::abs(a[i]) < tolerance / 2)
59 BOOST_REQUIRE_SMALL(b[i], tolerance / 2);
61 BOOST_REQUIRE_CLOSE(a[i], b[i], tolerance);
66 inline void CheckMatrices(
const arma::Mat<size_t>& a,
const arma::Mat<size_t>& b)
68 BOOST_REQUIRE_EQUAL(a.n_rows, b.n_rows);
69 BOOST_REQUIRE_EQUAL(a.n_cols, b.n_cols);
71 for (
size_t i = 0; i < a.n_elem; ++i)
72 BOOST_REQUIRE_EQUAL(a[i], b[i]);
The core includes that mlpack expects; standard C++ includes and Armadillo.