12 #ifndef MLPACK_TESTS_MAIN_TESTS_RANGE_SEARCH_TEST_UTILS_HPP
13 #define MLPACK_TESTS_MAIN_TESTS_RANGE_SEARCH_TEST_UTILS_HPP
15 #include <boost/test/unit_test.hpp>
27 std::ostringstream oss;
28 boost::archive::text_oarchive oa(oss);
42 std::vector<std::vector<double>>& vec2,
43 const double tolerance = 1e-3)
45 BOOST_REQUIRE_EQUAL(vec1.size() , vec2.size());
46 for (
size_t i = 0; i < vec1.size(); i++)
48 BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size());
49 std::sort(vec1[i].begin(), vec1[i].end());
50 std::sort(vec2[i].begin(), vec2[i].end());
51 for (
size_t j = 0 ; j < vec1[i].size(); j++)
53 BOOST_REQUIRE_CLOSE(vec1[i][j], vec2[i][j], tolerance);
65 std::vector<std::vector<size_t>>& vec2)
67 BOOST_REQUIRE_EQUAL(vec1.size() , vec2.size());
68 for (
size_t i = 0; i < vec1.size(); i++)
70 BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size());
71 std::sort(vec1[i].begin(), vec1[i].end());
72 std::sort(vec2[i].begin(), vec2[i].end());
73 for (
size_t j = 0; j < vec1[i].size(); j++)
75 BOOST_REQUIRE_EQUAL(vec1[i][j], vec2[i][j]);
88 std::vector<std::vector<T>>
ReadData(
const std::string& filename)
90 std::ifstream ifs(filename);
91 std::vector<std::vector<T>> table;
93 while (std::getline(ifs, line))
95 std::vector<T> numbers;
97 std::replace(line.begin(), line.end(),
',',
' ');
98 std::istringstream stm(line);
100 numbers.push_back(n);
101 table.push_back(numbers);
std::string ModelToString(RSModel *model)
Convert a model to a string using the text_oarchive of boost::serialization.
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
void CheckMatrices(std::vector< std::vector< double >> &vec1, std::vector< std::vector< double >> &vec2, const double tolerance=1e-3)
Check that 2 matrices of type vector<vector<double>> are close to equal, using the given tolerance...
std::vector< std::vector< T > > ReadData(const std::string &filename)
Load a CSV file into a vector of vector with a templated datatype.