Loading test_map.hpp +10 −10 Original line number Original line Diff line number Diff line Loading @@ -72,19 +72,19 @@ bool StdMapWrapper<Coordinates3D, int, Device>::Comparator::operator()(const Coo template<template<typename, typename, class> class M, typename K, typename V> template<template<typename, typename, class> class M, typename K, typename V> M<K, V, Device> build_table(const PairArray<K, V>& pairs, const Pair<K, V>& defPair, int toAdd) { M<K, V, Device> build_table(const PairArray<K, V>& pairs, int toAdd) { Array<Pair<K, V>, Device> arr(toAdd); Array<Pair<K, V>, Device> arr(toAdd); for (int i = 0; i < arr.getSize(); i++) for (int i = 0; i < arr.getSize(); i++) arr.setElement(i, pairs.getElement(i)); arr.setElement(i, pairs.getElement(i)); return M<K, V, Device>(arr, defPair); return M<K, V, Device>(arr); } } template<template<typename, typename, class> class M, typename K, typename V> template<template<typename, typename, class> class M, typename K, typename V> M<K, V, Device> test_building(const PairArray<K, V>& pairs, const Pair<K, V>& defPair) { M<K, V, Device> test_building(const PairArray<K, V>& pairs) { BEGIN_TEST(BUILDING) BEGIN_TEST(BUILDING) std::cerr << "\t\tInserting " << pairs.getSize() << " entries" << std::endl; std::cerr << "\t\tInserting " << pairs.getSize() << " entries" << std::endl; auto table = build_table<M, K, V>(pairs, defPair, pairs.getSize()); auto table = build_table<M, K, V>(pairs, pairs.getSize()); if constexpr (std::is_same<M<K, V, Device>, CuckooHashMap<K, V, Device>>::value) { if constexpr (std::is_same<M<K, V, Device>, CuckooHashMap<K, V, Device>>::value) { std::cerr << "\t\t - " << table.generations() std::cerr << "\t\t - " << table.generations() << " generation(s) before success" << std::endl; << " generation(s) before success" << std::endl; Loading Loading @@ -140,9 +140,9 @@ void test_wrong_query(const M<K, V, Device>& table, } } template<template<typename, typename, class> class M, typename K, typename V> template<template<typename, typename, class> class M, typename K, typename V> void test_random(const PairArray<K, V>& pairs, const CpuPairs<K, V>& cpuPairs, const Pair<K, V>& defPair, int nTests, double addedPart) { void test_random(const PairArray<K, V>& pairs, const CpuPairs<K, V>& cpuPairs, int nTests, double addedPart) { int nAdded = int(pairs.getSize() * addedPart); int nAdded = int(pairs.getSize() * addedPart); auto table = build_table<M, K, V>(pairs, defPair, nAdded); auto table = build_table<M, K, V>(pairs, nAdded); int correct = 0, wrong = 0; int correct = 0, wrong = 0; BEGIN_TEST(RANDOM) BEGIN_TEST(RANDOM) std::cerr << "\t\tFor " << pairs.getSize() << " entries, " std::cerr << "\t\tFor " << pairs.getSize() << " entries, " Loading Loading @@ -185,13 +185,13 @@ template<typename K, typename V> PairArray<K, V> read_data(const char* fileName, CpuPairs<K, V>& cpuPairs); PairArray<K, V> read_data(const char* fileName, CpuPairs<K, V>& cpuPairs); template<template<typename, typename, class> class M, typename K, typename V> template<template<typename, typename, class> class M, typename K, typename V> void test(const char* fileName, const Pair<K, V> defPair) { void test(const char* fileName) { std::vector<Pair<K, V>> cpuPairs; std::vector<Pair<K, V>> cpuPairs; auto pairs = read_data<K, V>(fileName, cpuPairs); auto pairs = read_data<K, V>(fileName, cpuPairs); auto table = test_building<M, K, V>(pairs, defPair); auto table = test_building<M, K, V>(pairs); test_correct_query<M, K, V>(table, pairs, cpuPairs, pairs.getSize()); test_correct_query<M, K, V>(table, pairs, cpuPairs, pairs.getSize()); test_wrong_query<M, K, V>(table, pairs, cpuPairs, pairs.getSize()); test_wrong_query<M, K, V>(table, pairs, cpuPairs, pairs.getSize()); test_random<M, K, V>(pairs, cpuPairs, defPair, 100000, 0.5); test_random<M, K, V>(pairs, cpuPairs, 100000, 0.5); g_row++; g_row++; g_col = 0; g_col = 0; Loading Loading @@ -258,7 +258,7 @@ void test_class(const std::string className) { //test<M, std::string, std::string>("data/cities.txt", {"", ""}); //test<M, std::string, std::string>("data/cities.txt", {"", ""}); std::cerr << "Testing " << className << "<TNL::Containers::StaticArray<3, int>, int>:" << std::endl; std::cerr << "Testing " << className << "<TNL::Containers::StaticArray<3, int>, int>:" << std::endl; test<M, Coordinates3D, int>("data/coordinates.txt", {{0, 0, 0}, 0}); test<M, Coordinates3D, int>("data/coordinates.txt"); //test<M, Coordinates3D, int>("data/crd1.txt", {{0, 0, 0}, 0}); //test<M, Coordinates3D, int>("data/crd1.txt", {{0, 0, 0}, 0}); } } Loading test_set.hpp +12 −16 Original line number Original line Diff line number Diff line Loading @@ -34,8 +34,7 @@ class StdSetWrapper { }; }; public: public: StdSetWrapper(const std::vector<T>& values, StdSetWrapper(const std::vector<T>& values) : const T& defValue) : m_set(values.begin(), values.end()) {} m_set(values.begin(), values.end()) {} bool contains(const T& value) const { bool contains(const T& value) const { Loading @@ -58,20 +57,20 @@ bool StdSetWrapper<Cell>::Comparator::operator()(const Cell& v1, const Cell& v2) } } template<template<class> class S, typename T> template<template<class> class S, typename T> S<T> build_table(const std::vector<T>& values, const T& defValue, int toAdd) { S<T> build_table(const std::vector<T>& values, int toAdd) { int tableSize = values.size() * 1.25; int tableSize = values.size() * 1.25; int nIterations = 7 * log(values.size()); int nIterations = 7 * log(values.size()); std::cerr << "\t\tBuilding table with parameters:" << std::endl std::cerr << "\t\tBuilding table with parameters:" << std::endl << "\t\t\tTable size: " << tableSize << std::endl << "\t\t\tTable size: " << tableSize << std::endl << "\t\t\tNumber of iterations: " << nIterations << std::endl; << "\t\t\tNumber of iterations: " << nIterations << std::endl; return S<T>(std::vector<T>(values.begin(), values.begin() + toAdd), defValue); return S<T>(std::vector<T>(values.begin(), values.begin() + toAdd)); } } template<template<class> class S, typename T> template<template<class> class S, typename T> S<T> test_building(const std::vector<T>& values, const T& defValue) { S<T> test_building(const std::vector<T>& values) { BEGIN_TEST(BUILDING) BEGIN_TEST(BUILDING) std::cerr << "\t\tInserting " << values.size() << " entries" << std::endl; std::cerr << "\t\tInserting " << values.size() << " entries" << std::endl; auto table = build_table<S, T>(values, defValue, values.size()); auto table = build_table<S, T>(values, values.size()); if constexpr (std::is_same<S<T>, CuckooHashSet<T>>::value) { if constexpr (std::is_same<S<T>, CuckooHashSet<T>>::value) { std::cerr << "\t\t - " << table.generations() std::cerr << "\t\t - " << table.generations() << " generation(s) before success" << std::endl; << " generation(s) before success" << std::endl; Loading Loading @@ -116,9 +115,9 @@ void test_wrong_query(const S<T>& table, } } template<template<class> class S, typename T> template<template<class> class S, typename T> void test_random(const std::vector<T>& values, const T& defValue, int nTests, double addedPart) { void test_random(const std::vector<T>& values, int nTests, double addedPart) { int nAdded = int(values.size() * addedPart); int nAdded = int(values.size() * addedPart); auto table = build_table<S, T>(values, defValue, nAdded); auto table = build_table<S, T>(values, nAdded); int correct = 0, wrong = 0; int correct = 0, wrong = 0; BEGIN_TEST(RANDOM) BEGIN_TEST(RANDOM) std::cerr << "\t\tFor " << values.size() << " entries, " std::cerr << "\t\tFor " << values.size() << " entries, " Loading Loading @@ -194,13 +193,13 @@ std::vector<Cell> read_data(std::string fileName) { template<template<class> class S, typename T> template<template<class> class S, typename T> void test(std::string fileName, const T defValue, bool testRandom = true) { void test(std::string fileName, bool testRandom = true) { auto values = get_data<T>(fileName); auto values = get_data<T>(fileName); auto table = test_building<S, T>(values, defValue); auto table = test_building<S, T>(values); test_correct_query<S, T>(table, values, values.size()); test_correct_query<S, T>(table, values, values.size()); test_wrong_query<S, T>(table, values, values.size()); test_wrong_query<S, T>(table, values, values.size()); if (testRandom) if (testRandom) test_random<S, T>(values, defValue, 100000, 0.5); test_random<S, T>(values, 100000, 0.5); else else g_results[g_row][g_col] = nan(""); g_results[g_row][g_col] = nan(""); g_row++; g_row++; Loading Loading @@ -228,13 +227,10 @@ Triangle ruin<Triangle>(const Triangle& value) { template<template<class> class S> template<template<class> class S> void test_class(const std::string className, const std::string dataFile) { void test_class(const std::string className, const std::string dataFile) { std::cerr << "Testing " << className << "<TNL::Containers::StaticArray<4, int>> with " << dataFile << ':' << std::endl; std::cerr << "Testing " << className << "<TNL::Containers::StaticArray<4, int>> with " << dataFile << ':' << std::endl; test<S, Cell>(dataFile, {0, 0, 0, 0}); test<S, Cell>(dataFile); static int def3[] = {0, 0, 0}; static const Triangle defTriangle(def3); std::cerr << "Testing " << className << "<Triangle> with " << dataFile << ':' << std::endl; std::cerr << "Testing " << className << "<Triangle> with " << dataFile << ':' << std::endl; test<S, Triangle>(dataFile, defTriangle, false); test<S, Triangle>(dataFile, false); } } Loading Loading
test_map.hpp +10 −10 Original line number Original line Diff line number Diff line Loading @@ -72,19 +72,19 @@ bool StdMapWrapper<Coordinates3D, int, Device>::Comparator::operator()(const Coo template<template<typename, typename, class> class M, typename K, typename V> template<template<typename, typename, class> class M, typename K, typename V> M<K, V, Device> build_table(const PairArray<K, V>& pairs, const Pair<K, V>& defPair, int toAdd) { M<K, V, Device> build_table(const PairArray<K, V>& pairs, int toAdd) { Array<Pair<K, V>, Device> arr(toAdd); Array<Pair<K, V>, Device> arr(toAdd); for (int i = 0; i < arr.getSize(); i++) for (int i = 0; i < arr.getSize(); i++) arr.setElement(i, pairs.getElement(i)); arr.setElement(i, pairs.getElement(i)); return M<K, V, Device>(arr, defPair); return M<K, V, Device>(arr); } } template<template<typename, typename, class> class M, typename K, typename V> template<template<typename, typename, class> class M, typename K, typename V> M<K, V, Device> test_building(const PairArray<K, V>& pairs, const Pair<K, V>& defPair) { M<K, V, Device> test_building(const PairArray<K, V>& pairs) { BEGIN_TEST(BUILDING) BEGIN_TEST(BUILDING) std::cerr << "\t\tInserting " << pairs.getSize() << " entries" << std::endl; std::cerr << "\t\tInserting " << pairs.getSize() << " entries" << std::endl; auto table = build_table<M, K, V>(pairs, defPair, pairs.getSize()); auto table = build_table<M, K, V>(pairs, pairs.getSize()); if constexpr (std::is_same<M<K, V, Device>, CuckooHashMap<K, V, Device>>::value) { if constexpr (std::is_same<M<K, V, Device>, CuckooHashMap<K, V, Device>>::value) { std::cerr << "\t\t - " << table.generations() std::cerr << "\t\t - " << table.generations() << " generation(s) before success" << std::endl; << " generation(s) before success" << std::endl; Loading Loading @@ -140,9 +140,9 @@ void test_wrong_query(const M<K, V, Device>& table, } } template<template<typename, typename, class> class M, typename K, typename V> template<template<typename, typename, class> class M, typename K, typename V> void test_random(const PairArray<K, V>& pairs, const CpuPairs<K, V>& cpuPairs, const Pair<K, V>& defPair, int nTests, double addedPart) { void test_random(const PairArray<K, V>& pairs, const CpuPairs<K, V>& cpuPairs, int nTests, double addedPart) { int nAdded = int(pairs.getSize() * addedPart); int nAdded = int(pairs.getSize() * addedPart); auto table = build_table<M, K, V>(pairs, defPair, nAdded); auto table = build_table<M, K, V>(pairs, nAdded); int correct = 0, wrong = 0; int correct = 0, wrong = 0; BEGIN_TEST(RANDOM) BEGIN_TEST(RANDOM) std::cerr << "\t\tFor " << pairs.getSize() << " entries, " std::cerr << "\t\tFor " << pairs.getSize() << " entries, " Loading Loading @@ -185,13 +185,13 @@ template<typename K, typename V> PairArray<K, V> read_data(const char* fileName, CpuPairs<K, V>& cpuPairs); PairArray<K, V> read_data(const char* fileName, CpuPairs<K, V>& cpuPairs); template<template<typename, typename, class> class M, typename K, typename V> template<template<typename, typename, class> class M, typename K, typename V> void test(const char* fileName, const Pair<K, V> defPair) { void test(const char* fileName) { std::vector<Pair<K, V>> cpuPairs; std::vector<Pair<K, V>> cpuPairs; auto pairs = read_data<K, V>(fileName, cpuPairs); auto pairs = read_data<K, V>(fileName, cpuPairs); auto table = test_building<M, K, V>(pairs, defPair); auto table = test_building<M, K, V>(pairs); test_correct_query<M, K, V>(table, pairs, cpuPairs, pairs.getSize()); test_correct_query<M, K, V>(table, pairs, cpuPairs, pairs.getSize()); test_wrong_query<M, K, V>(table, pairs, cpuPairs, pairs.getSize()); test_wrong_query<M, K, V>(table, pairs, cpuPairs, pairs.getSize()); test_random<M, K, V>(pairs, cpuPairs, defPair, 100000, 0.5); test_random<M, K, V>(pairs, cpuPairs, 100000, 0.5); g_row++; g_row++; g_col = 0; g_col = 0; Loading Loading @@ -258,7 +258,7 @@ void test_class(const std::string className) { //test<M, std::string, std::string>("data/cities.txt", {"", ""}); //test<M, std::string, std::string>("data/cities.txt", {"", ""}); std::cerr << "Testing " << className << "<TNL::Containers::StaticArray<3, int>, int>:" << std::endl; std::cerr << "Testing " << className << "<TNL::Containers::StaticArray<3, int>, int>:" << std::endl; test<M, Coordinates3D, int>("data/coordinates.txt", {{0, 0, 0}, 0}); test<M, Coordinates3D, int>("data/coordinates.txt"); //test<M, Coordinates3D, int>("data/crd1.txt", {{0, 0, 0}, 0}); //test<M, Coordinates3D, int>("data/crd1.txt", {{0, 0, 0}, 0}); } } Loading
test_set.hpp +12 −16 Original line number Original line Diff line number Diff line Loading @@ -34,8 +34,7 @@ class StdSetWrapper { }; }; public: public: StdSetWrapper(const std::vector<T>& values, StdSetWrapper(const std::vector<T>& values) : const T& defValue) : m_set(values.begin(), values.end()) {} m_set(values.begin(), values.end()) {} bool contains(const T& value) const { bool contains(const T& value) const { Loading @@ -58,20 +57,20 @@ bool StdSetWrapper<Cell>::Comparator::operator()(const Cell& v1, const Cell& v2) } } template<template<class> class S, typename T> template<template<class> class S, typename T> S<T> build_table(const std::vector<T>& values, const T& defValue, int toAdd) { S<T> build_table(const std::vector<T>& values, int toAdd) { int tableSize = values.size() * 1.25; int tableSize = values.size() * 1.25; int nIterations = 7 * log(values.size()); int nIterations = 7 * log(values.size()); std::cerr << "\t\tBuilding table with parameters:" << std::endl std::cerr << "\t\tBuilding table with parameters:" << std::endl << "\t\t\tTable size: " << tableSize << std::endl << "\t\t\tTable size: " << tableSize << std::endl << "\t\t\tNumber of iterations: " << nIterations << std::endl; << "\t\t\tNumber of iterations: " << nIterations << std::endl; return S<T>(std::vector<T>(values.begin(), values.begin() + toAdd), defValue); return S<T>(std::vector<T>(values.begin(), values.begin() + toAdd)); } } template<template<class> class S, typename T> template<template<class> class S, typename T> S<T> test_building(const std::vector<T>& values, const T& defValue) { S<T> test_building(const std::vector<T>& values) { BEGIN_TEST(BUILDING) BEGIN_TEST(BUILDING) std::cerr << "\t\tInserting " << values.size() << " entries" << std::endl; std::cerr << "\t\tInserting " << values.size() << " entries" << std::endl; auto table = build_table<S, T>(values, defValue, values.size()); auto table = build_table<S, T>(values, values.size()); if constexpr (std::is_same<S<T>, CuckooHashSet<T>>::value) { if constexpr (std::is_same<S<T>, CuckooHashSet<T>>::value) { std::cerr << "\t\t - " << table.generations() std::cerr << "\t\t - " << table.generations() << " generation(s) before success" << std::endl; << " generation(s) before success" << std::endl; Loading Loading @@ -116,9 +115,9 @@ void test_wrong_query(const S<T>& table, } } template<template<class> class S, typename T> template<template<class> class S, typename T> void test_random(const std::vector<T>& values, const T& defValue, int nTests, double addedPart) { void test_random(const std::vector<T>& values, int nTests, double addedPart) { int nAdded = int(values.size() * addedPart); int nAdded = int(values.size() * addedPart); auto table = build_table<S, T>(values, defValue, nAdded); auto table = build_table<S, T>(values, nAdded); int correct = 0, wrong = 0; int correct = 0, wrong = 0; BEGIN_TEST(RANDOM) BEGIN_TEST(RANDOM) std::cerr << "\t\tFor " << values.size() << " entries, " std::cerr << "\t\tFor " << values.size() << " entries, " Loading Loading @@ -194,13 +193,13 @@ std::vector<Cell> read_data(std::string fileName) { template<template<class> class S, typename T> template<template<class> class S, typename T> void test(std::string fileName, const T defValue, bool testRandom = true) { void test(std::string fileName, bool testRandom = true) { auto values = get_data<T>(fileName); auto values = get_data<T>(fileName); auto table = test_building<S, T>(values, defValue); auto table = test_building<S, T>(values); test_correct_query<S, T>(table, values, values.size()); test_correct_query<S, T>(table, values, values.size()); test_wrong_query<S, T>(table, values, values.size()); test_wrong_query<S, T>(table, values, values.size()); if (testRandom) if (testRandom) test_random<S, T>(values, defValue, 100000, 0.5); test_random<S, T>(values, 100000, 0.5); else else g_results[g_row][g_col] = nan(""); g_results[g_row][g_col] = nan(""); g_row++; g_row++; Loading Loading @@ -228,13 +227,10 @@ Triangle ruin<Triangle>(const Triangle& value) { template<template<class> class S> template<template<class> class S> void test_class(const std::string className, const std::string dataFile) { void test_class(const std::string className, const std::string dataFile) { std::cerr << "Testing " << className << "<TNL::Containers::StaticArray<4, int>> with " << dataFile << ':' << std::endl; std::cerr << "Testing " << className << "<TNL::Containers::StaticArray<4, int>> with " << dataFile << ':' << std::endl; test<S, Cell>(dataFile, {0, 0, 0, 0}); test<S, Cell>(dataFile); static int def3[] = {0, 0, 0}; static const Triangle defTriangle(def3); std::cerr << "Testing " << className << "<Triangle> with " << dataFile << ':' << std::endl; std::cerr << "Testing " << className << "<Triangle> with " << dataFile << ':' << std::endl; test<S, Triangle>(dataFile, defTriangle, false); test<S, Triangle>(dataFile, false); } } Loading