From e62d16d7b1c42163de7b21ab74a780c3c1cf8e45 Mon Sep 17 00:00:00 2001 From: Arnur Nigmetov Date: Sat, 16 Oct 2021 13:01:59 -0700 Subject: Change example in matching distance --- matching/example/module_example.cpp | 88 +++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 33 deletions(-) diff --git a/matching/example/module_example.cpp b/matching/example/module_example.cpp index aec38c2..6fa2e5a 100644 --- a/matching/example/module_example.cpp +++ b/matching/example/module_example.cpp @@ -5,61 +5,83 @@ using namespace md; int main(int /*argc*/, char** /*argv*/) { - // create generators. - // A generator is a point in plane, - // generators are stored in a vector of points: - PointVec gens_a; - - // module A will have one generator that appears at point (0, 0) - gens_a.emplace_back(0, 0); - - // relations are stored in a vector of relations using RelationVec = ModulePresentation::RelVec; + using Relation = ModulePresentation::Relation; + + // Module A (three rectangles) + PointVec gens_a; RelationVec rels_a; - // A relation is a struct with position and column - using Relation = ModulePresentation::Relation; - // at this point the relation rel_a_1 will appear: - Point rel_a_1_position { 1, 1 }; + // First rectangle + gens_a.emplace_back(-3, -1); - // vector IndexVec contains non-zero indices of the corresponding relation - // (we work over Z/2). Since we have one generator only, the relation - // contains only one entry, 0 + Point rel_a_1_position { -3, 3 }; IndexVec rel_a_1_components { 0 }; - - // construct a relation from position and column: Relation rel_a_1 { rel_a_1_position, rel_a_1_components }; - - // and add it to a vector of relations rels_a.push_back(rel_a_1); - // after populating vectors of generators and relations - // construct a module: - ModulePresentation module_a { gens_a, rels_a }; + Point rel_a_2_position { 1, -1 }; + IndexVec rel_a_2_components { 0 }; + Relation rel_a_2 { rel_a_2_position, rel_a_2_components }; + rels_a.push_back(rel_a_2); + // Second rectangle + gens_a.emplace_back(-1, -1); - // same for module_b. It will also have just one - // generator and one relation, but at different positions. + Point rel_a_3_position { -1, 1 }; + IndexVec rel_a_3_components { 1 }; + Relation rel_a_3 { rel_a_3_position, rel_a_3_components }; + rels_a.push_back(rel_a_3); - PointVec gens_b; - gens_b.emplace_back(1, 1); + Point rel_a_4_position { 1, -1 }; + IndexVec rel_a_4_components { 1 }; + Relation rel_a_4 { rel_a_4_position, rel_a_4_components }; + rels_a.push_back(rel_a_4); + // Third rectangle + gens_a.emplace_back(-1, -3); + + Point rel_a_5_position { -1, 1 }; + IndexVec rel_a_5_components { 2 }; + Relation rel_a_5 { rel_a_5_position, rel_a_5_components }; + rels_a.push_back(rel_a_5); + + Point rel_a_6_position { 3, -3 }; + IndexVec rel_a_6_components { 2 }; + Relation rel_a_6 { rel_a_6_position, rel_a_6_components }; + rels_a.push_back(rel_a_6); + + + ModulePresentation module_a { gens_a, rels_a }; + + + // Module B (one rectangle) + PointVec gens_b; RelationVec rels_b; - Point rel_b_1_position { 2, 2 }; + // Rectangle + gens_b.emplace_back(-2, -2); + + Point rel_b_1_position { -2, 2 }; IndexVec rel_b_1_components { 0 }; + Relation rel_b_1 { rel_b_1_position, rel_b_1_components }; + rels_b.push_back(rel_b_1); + + Point rel_b_2_position { 2, -2 }; + IndexVec rel_b_2_components { 0 }; + Relation rel_b_2 { rel_b_2_position, rel_b_2_components }; + rels_b.push_back(rel_b_2); - rels_b.emplace_back(rel_b_1_position, rel_b_1_components); ModulePresentation module_b { gens_b, rels_b }; - // create CalculationParams + + // Computations CalculationParams params; - // set relative error to 10 % : params.delta = 0.1; - // go at most 8 levels deep in quadtree: - params.max_depth = 8; + params.max_depth = 5; + params.initialization_depth = 0; double dist = matching_distance(module_a, module_b, params); std::cout << "dist = " << dist << std::endl; -- cgit v1.2.3 From 8fbae1d789b3c9d7e9b079284c85489d8dcd7e65 Mon Sep 17 00:00:00 2001 From: Arnur Nigmetov Date: Sat, 9 Apr 2022 17:33:15 -0700 Subject: Major cleanup --- wasserstein/CMakeLists.txt | 59 +- wasserstein/example/CMakeLists.txt | 21 + wasserstein/example/wasserstein_dist.cpp | 11 +- wasserstein/example/wasserstein_dist_dipha.cpp | 12 +- .../example/wasserstein_dist_point_cloud.cpp | 8 +- .../include/auction_oracle_kdtree_restricted.hpp | 4 - wasserstein/include/auction_runner_fr.h | 67 +- wasserstein/include/auction_runner_fr.hpp | 299 +- wasserstein/include/auction_runner_gs.h | 16 +- wasserstein/include/auction_runner_gs.hpp | 129 +- .../include/auction_runner_gs_single_diag.h | 11 - .../include/auction_runner_gs_single_diag.hpp | 109 - wasserstein/include/auction_runner_jac.h | 53 +- wasserstein/include/auction_runner_jac.hpp | 306 +- wasserstein/include/basic_defs_ws.h | 2 +- wasserstein/include/catch/catch.hpp | 24281 ++++++++++++------- wasserstein/include/dnn/parallel/tbb.h | 4 +- wasserstein/include/wasserstein.h | 15 +- wasserstein/tests/CMakeLists.txt | 9 + wasserstein/tests/test_hera_wasserstein.cpp | 3 - .../tests/test_hera_wasserstein_pure_geom.cpp | 2 - wasserstein/tests/tests_main.cpp | 1 - 22 files changed, 15422 insertions(+), 10000 deletions(-) create mode 100644 wasserstein/example/CMakeLists.txt create mode 100644 wasserstein/tests/CMakeLists.txt diff --git a/wasserstein/CMakeLists.txt b/wasserstein/CMakeLists.txt index dea4550..0a0fa4e 100644 --- a/wasserstein/CMakeLists.txt +++ b/wasserstein/CMakeLists.txt @@ -1,62 +1,25 @@ -project (wasserstein) -cmake_minimum_required (VERSION 3.5.1) +project(wasserstein) +cmake_minimum_required(VERSION 3.5.1) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) -include (GenerateExportHeader) - -include(TestBigEndian) -test_big_endian(BIG_ENDIAN) -if(BIG_ENDIAN) - add_definitions(-DBIGENDIAN) -endif() - -# Default to Release - -if (NOT CMAKE_BUILD_TYPE) - set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -endif (NOT CMAKE_BUILD_TYPE) +endif(NOT CMAKE_BUILD_TYPE) # Boost -find_package (Boost) -include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include - SYSTEM ${Boost_INCLUDE_DIR}) - -if(NOT WIN32) - add_definitions(-std=c++14) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -D_GLIBCXX_DEBUG") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 ") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -O2 -g -ggdb") -endif(NOT WIN32) +find_package(Boost) -file(GLOB WS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp) - -#add_library(wasserstein ${WS_SOURCES}) - -#if (WIN32) - #GENERATE_EXPORT_HEADER(wasserstein - #BASE_NAME wasserstein - #EXPORT_MACRO_NAME wasserstein_EXPORT - #EXPORT_FILE_NAME wasserstein_export.h - #STATIC_DEFINE wasserstein_BUILT_AS_STATIC) -#endif(WIN32) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include SYSTEM ${Boost_INCLUDE_DIR}) find_package (Threads) set (libraries ${libraries} ${CMAKE_THREAD_LIBS_INIT}) -add_executable(wasserstein_dist ${CMAKE_CURRENT_SOURCE_DIR}/example/wasserstein_dist.cpp ${WS_HEADERS} include/hera_infinity.h) -target_link_libraries(wasserstein_dist PUBLIC ${libraries}) - -add_executable(wasserstein_dist_dipha ${CMAKE_CURRENT_SOURCE_DIR}/example/wasserstein_dist_dipha.cpp ${WS_HEADERS} include/hera_infinity.h) -target_link_libraries(wasserstein_dist_dipha PUBLIC ${libraries}) - -# pure geometric version, arbitrary dimension -add_executable(wasserstein_dist_point_cloud ${CMAKE_CURRENT_SOURCE_DIR}/example/wasserstein_dist_point_cloud.cpp ${WS_HEADERS} include/hera_infinity.h) -target_link_libraries(wasserstein_dist_point_cloud PUBLIC ${libraries}) +add_subdirectory(example) +#add_subdirectory(tests) # Tests add_executable(wasserstein_test ${CMAKE_CURRENT_SOURCE_DIR}/tests/tests_main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_hera_wasserstein.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_hera_wasserstein_pure_geom.cpp include/hera_infinity.h tests/tests_reader.h) -#add_executable(wasserstein_test EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_hera_wasserstein.cpp) target_link_libraries(wasserstein_test PUBLIC ${libraries}) diff --git a/wasserstein/example/CMakeLists.txt b/wasserstein/example/CMakeLists.txt new file mode 100644 index 0000000..2e2f1f2 --- /dev/null +++ b/wasserstein/example/CMakeLists.txt @@ -0,0 +1,21 @@ +add_executable(wasserstein_dist wasserstein_dist.cpp) +target_link_libraries(wasserstein_dist PUBLIC ${libraries}) + +add_executable(wasserstein_dist_dipha wasserstein_dist_dipha.cpp) +target_link_libraries(wasserstein_dist_dipha PUBLIC ${libraries}) + +# pure geometric version, arbitrary dimension +add_executable(wasserstein_dist_point_cloud wasserstein_dist_point_cloud.cpp) +target_link_libraries(wasserstein_dist_point_cloud PUBLIC ${libraries}) + +if(MSVC) + target_compile_options(wasserstein_dist PRIVATE /W4 /WX) + target_compile_options(wasserstein_dist_dipha PRIVATE /W4 /WX) + target_compile_options(wasserstein_dist_point_cloud PRIVATE /W4 /WX) +else() + target_compile_options(wasserstein_dist PRIVATE -Wall -Wextra -Wpedantic) + target_compile_options(wasserstein_dist_dipha PRIVATE -Wall -Wextra -Wpedantic) + target_compile_options(wasserstein_dist_point_cloud PRIVATE -Wall -Wextra -Wpedantic) +endif() + + diff --git a/wasserstein/example/wasserstein_dist.cpp b/wasserstein/example/wasserstein_dist.cpp index cbe83e2..46f06fc 100644 --- a/wasserstein/example/wasserstein_dist.cpp +++ b/wasserstein/example/wasserstein_dist.cpp @@ -33,8 +33,6 @@ derivative works thereof, in binary and source code form. #include "opts/opts.h" -//#define LOG_AUCTION - //#include "auction_runner_fr.h" //#include "auction_runner_fr.hpp" @@ -138,14 +136,7 @@ int main(int argc, char* argv[]) params.max_bids_per_round = std::numeric_limits::max(); - std::string log_filename_prefix = ( 11 <= argc ) ? argv[10] : ""; - - -#ifdef LOG_AUCTION - spdlog::set_level(spdlog::level::info); -#endif - - Real res = hera::wasserstein_dist(diagramA, diagramB, params, log_filename_prefix); + Real res = hera::wasserstein_dist(diagramA, diagramB, params); std::cout << std::setprecision(15) << res << std::endl; if (print_relative_error) diff --git a/wasserstein/example/wasserstein_dist_dipha.cpp b/wasserstein/example/wasserstein_dist_dipha.cpp index 2ed9c2c..1bfc41b 100644 --- a/wasserstein/example/wasserstein_dist_dipha.cpp +++ b/wasserstein/example/wasserstein_dist_dipha.cpp @@ -32,8 +32,6 @@ derivative works thereof, in binary and source code form. #include #include -//#define LOG_AUCTION - //#include "auction_runner_fr.h" //#include "auction_runner_fr.hpp" @@ -50,7 +48,7 @@ int main(int argc, char* argv[]) hera::AuctionParams params; if (argc < 4 ) { - std::cerr << "Usage: " << argv[0] << " file1 file2 ph_dim [wasserstein_degree] [relative_error] [internal norm] [initial epsilon] [epsilon_factor] [max_bids_per_round] [gamma_threshold][log_filename_prefix]. By default power is 1.0, relative error is 0.01, internal norm is l_infinity, initall epsilon is chosen automatically, epsilon factor is 5.0, Jacobi variant is used (max bids per round is maximal), gamma_threshold = 0.0." << std::endl; + std::cerr << "Usage: " << argv[0] << " file1 file2 ph_dim [wasserstein_degree] [relative_error] [internal norm] [initial epsilon] [epsilon_factor] [max_bids_per_round] [gamma_threshold]. By default power is 1.0, relative error is 0.01, internal norm is l_infinity, initall epsilon is chosen automatically, epsilon factor is 5.0, Jacobi variant is used (max bids per round is maximal), gamma_threshold = 0.0." << std::endl; return 1; } @@ -116,15 +114,9 @@ int main(int argc, char* argv[]) params.gamma_threshold = (11 <= argc) ? atof(argv[10]) : 0.0; - std::string log_filename_prefix = ( 12 <= argc ) ? argv[11] : ""; - params.max_num_phases = 800; -#ifdef LOG_AUCTION - spdlog::set_level(spdlog::level::info); -#endif - - double res = hera::wasserstein_dist(diagramA, diagramB, params, log_filename_prefix); + double res = hera::wasserstein_dist(diagramA, diagramB, params); std::cout << std::setprecision(15) << res << std::endl; diff --git a/wasserstein/example/wasserstein_dist_point_cloud.cpp b/wasserstein/example/wasserstein_dist_point_cloud.cpp index ab7ff4f..754d0e3 100644 --- a/wasserstein/example/wasserstein_dist_point_cloud.cpp +++ b/wasserstein/example/wasserstein_dist_point_cloud.cpp @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) hera::AuctionParams params; if (argc < 3 ) { - std::cerr << "Usage: " << argv[0] << " file1 file2 [wasserstein_degree] [relative_error] [internal norm] [initial epsilon] [epsilon_factor] [max_bids_per_round] [gamma_threshold][log_filename_prefix]. By default power is 1.0, relative error is 0.01, internal norm is l_infinity, initall epsilon is chosen automatically, epsilon factor is 5.0, Jacobi variant is used (max bids per round is maximal), gamma_threshold = 0.0." << std::endl; + std::cerr << "Usage: " << argv[0] << " file1 file2 [wasserstein_degree] [relative_error] [internal norm] [initial epsilon] [epsilon_factor] [max_bids_per_round] [gamma_threshold]. By default power is 1.0, relative error is 0.01, internal norm is l_infinity, initall epsilon is chosen automatically, epsilon factor is 5.0, Jacobi variant is used (max bids per round is maximal), gamma_threshold = 0.0." << std::endl; return 1; } @@ -159,14 +159,8 @@ int main(int argc, char* argv[]) params.gamma_threshold = (10 <= argc) ? atof(argv[9]) : 0.0; - std::string log_filename_prefix = ( 11 <= argc ) ? argv[10] : ""; - params.max_num_phases = 800; -#ifdef LOG_AUCTION - spdlog::set_level(spdlog::level::critical); -#endif - Real res = hera::ws::wasserstein_dist(set_A, set_B, params); std::cout << std::setprecision(15) << res << std::endl; diff --git a/wasserstein/include/auction_oracle_kdtree_restricted.hpp b/wasserstein/include/auction_oracle_kdtree_restricted.hpp index f0e7ac6..e86a5d5 100644 --- a/wasserstein/include/auction_oracle_kdtree_restricted.hpp +++ b/wasserstein/include/auction_oracle_kdtree_restricted.hpp @@ -270,7 +270,6 @@ IdxValPair AuctionOracleKDTreeRestricted::get_opt // and vice versa. size_t best_item_idx { k_invalid_index }; - size_t second_best_item_idx { k_invalid_index }; size_t best_diagonal_item_idx { k_invalid_index }; Real best_item_value; Real second_best_item_value; @@ -297,17 +296,14 @@ IdxValPair AuctionOracleKDTreeRestricted::get_opt best_item_idx = proj_item_idx; best_item_value = proj_item_value; second_best_item_value = best_diagonal_item_value_; - second_best_item_idx = best_diagonal_item_idx; } else if (proj_item_value < second_best_diagonal_item_value_) { best_item_idx = best_diagonal_item_idx; best_item_value = best_diagonal_item_value_; second_best_item_value = proj_item_value; - second_best_item_idx = proj_item_idx; } else { best_item_idx = best_diagonal_item_idx; best_item_value = best_diagonal_item_value_; second_best_item_value = second_best_diagonal_item_value_; - second_best_item_idx = second_best_diagonal_item_idx_; } } else { // for normal bidder get 2 best items among non-diagonal points from diff --git a/wasserstein/include/auction_runner_fr.h b/wasserstein/include/auction_runner_fr.h index 0c67b65..3ee659c 100644 --- a/wasserstein/include/auction_runner_fr.h +++ b/wasserstein/include/auction_runner_fr.h @@ -64,8 +64,7 @@ public: const Real _eps_factor = 5.0, const int _max_num_phases = std::numeric_limits::max(), const Real _gamma_threshold = 0.0, - const size_t _max_bids_per_round = std::numeric_limits::max(), - const std::string& _log_filename_prefix = ""); + const size_t _max_bids_per_round = std::numeric_limits::max()); void set_epsilon(Real new_val); Real get_epsilon() const { return epsilon; } @@ -188,7 +187,6 @@ private: void print_debug(); void print_matching(); - std::string log_filename_prefix; const Real k_max_relative_error = 2.0; // if relative error cannot be estimated or is too large, use this value void reset_round_stat(); // empty, if logging is disable void reset_phase_stat(); @@ -196,69 +194,6 @@ private: std::unordered_set never_assigned_bidders; std::unordered_set never_assigned_items; -#ifdef LOG_AUCTION - std::unordered_set unassigned_normal_bidders; - std::unordered_set unassigned_diag_bidders; - - std::unordered_set unassigned_normal_items; - std::unordered_set unassigned_diag_items; - - - size_t all_assigned_round { 0 }; - size_t all_assigned_round_found { false }; - - int num_forward_rounds_non_cumulative { 0 }; - int num_forward_rounds { 0 }; - - int num_reverse_rounds_non_cumulative { 0 }; - int num_reverse_rounds { 0 }; - - // all per-round vars are non-cumulative - - // forward rounds - int num_normal_forward_bids_submitted { 0 }; - int num_diag_forward_bids_submitted { 0 }; - - int num_forward_diag_to_diag_assignments { 0 }; - int num_forward_diag_to_normal_assignments { 0 }; - int num_forward_normal_to_diag_assignments { 0 }; - int num_forward_normal_to_normal_assignments { 0 }; - - int num_forward_diag_from_diag_thefts { 0 }; - int num_forward_diag_from_normal_thefts { 0 }; - int num_forward_normal_from_diag_thefts { 0 }; - int num_forward_normal_from_normal_thefts { 0 }; - - // reverse rounds - int num_normal_reverse_bids_submitted { 0 }; - int num_diag_reverse_bids_submitted { 0 }; - - int num_reverse_diag_to_diag_assignments { 0 }; - int num_reverse_diag_to_normal_assignments { 0 }; - int num_reverse_normal_to_diag_assignments { 0 }; - int num_reverse_normal_to_normal_assignments { 0 }; - - int num_reverse_diag_from_diag_thefts { 0 }; - int num_reverse_diag_from_normal_thefts { 0 }; - int num_reverse_normal_from_diag_thefts { 0 }; - int num_reverse_normal_from_normal_thefts { 0 }; - - // price change statistics - std::vector> forward_price_change_cnt_vec; - std::vector> reverse_price_change_cnt_vec; - - size_t parallel_threshold = 5000; - int num_parallelizable_rounds { 0 }; - int num_parallelizable_forward_rounds { 0 }; - int num_parallelizable_reverse_rounds { 0 }; - - int num_parallel_bids { 0 }; - int num_total_bids { 0 }; - - int num_parallel_assignments { 0 }; - int num_total_assignments { 0 }; -#endif - }; diff --git a/wasserstein/include/auction_runner_fr.hpp b/wasserstein/include/auction_runner_fr.hpp index b0b65d0..ba36006 100644 --- a/wasserstein/include/auction_runner_fr.hpp +++ b/wasserstein/include/auction_runner_fr.hpp @@ -61,9 +61,7 @@ AuctionRunnerFR::AuctionRunnerFR(const std::vector& A, const Real _eps_factor, const int _max_num_phases, const Real _gamma_threshold, - const size_t _max_bids_per_round, - const std::string& _log_filename_prefix - ) : + const size_t _max_bids_per_round) : bidders(A), items(B), num_bidders(A.size()), @@ -96,8 +94,7 @@ AuctionRunnerFR::AuctionRunnerFR(const std::vector& A, partial_cost(0.0), unassigned_bidders_persistence(total_bidders_persistence), unassigned_items_persistence(total_items_persistence), - gamma_threshold(_gamma_threshold), - log_filename_prefix(_log_filename_prefix) + gamma_threshold(_gamma_threshold) { assert(A.size() == B.size()); for(const auto& p : bidders) { @@ -157,13 +154,6 @@ template void AuctionRunnerFR::reset_phase_stat() { num_rounds_non_cumulative = 0; -#ifdef LOG_AUCTION - num_parallelizable_rounds = 0; - num_parallelizable_forward_rounds = 0; - num_parallelizable_reverse_rounds = 0; - num_forward_rounds_non_cumulative = 0; - num_reverse_rounds_non_cumulative = 0; -#endif } @@ -172,34 +162,6 @@ void AuctionRunnerFR::reset_round_stat() { num_forward_bids_submitted = 0; num_reverse_bids_submitted = 0; -#ifdef LOG_AUCTION - num_normal_forward_bids_submitted = 0; - num_diag_forward_bids_submitted = 0; - - num_forward_diag_to_diag_assignments = 0; - num_forward_diag_to_normal_assignments = 0; - num_forward_normal_to_diag_assignments = 0; - num_forward_normal_to_normal_assignments = 0; - - num_forward_diag_from_diag_thefts = 0; - num_forward_diag_from_normal_thefts = 0; - num_forward_normal_from_diag_thefts = 0; - num_forward_normal_from_normal_thefts = 0; - - // reverse rounds - num_normal_reverse_bids_submitted = 0; - num_diag_reverse_bids_submitted = 0; - - num_reverse_diag_to_diag_assignments = 0; - num_reverse_diag_to_normal_assignments = 0; - num_reverse_normal_to_diag_assignments = 0; - num_reverse_normal_to_normal_assignments = 0; - - num_reverse_diag_from_diag_thefts = 0; - num_reverse_diag_from_normal_thefts = 0; - num_reverse_normal_from_diag_thefts = 0; - num_reverse_normal_from_normal_thefts = 0; -#endif } @@ -233,63 +195,6 @@ void AuctionRunnerFR::assign_forward(IdxType item_idx, IdxType bidder_idx // new edge was added to matching, increase partial cost partial_cost += get_item_bidder_cost(item_idx, bidder_idx); -#ifdef LOG_AUCTION - - if (unassigned_bidders.size() > parallel_threshold) { - num_parallel_assignments++; - } - num_total_assignments++; - - - int it_d = is_item_diagonal(item_idx); - int b_d = is_bidder_diagonal(bidder_idx); - // 2 - None - int old_d = ( k_invalid_index == old_item_owner ) ? 2 : is_bidder_diagonal(old_item_owner); - int key = 100 * old_d + 10 * b_d + it_d; - switch(key) { - case 211 : num_forward_diag_to_diag_assignments++; - break; - case 210 : num_forward_diag_to_normal_assignments++; - break; - case 201 : num_forward_normal_to_diag_assignments++; - break; - case 200 : num_forward_normal_to_normal_assignments++; - break; - - case 111 : num_forward_diag_to_diag_assignments++; - num_forward_diag_from_diag_thefts++; - break; - case 110 : num_forward_diag_to_normal_assignments++; - num_forward_diag_from_diag_thefts++; - break; - break; - case 101 : num_forward_normal_to_diag_assignments++; - num_forward_normal_from_diag_thefts++; - break; - break; - case 100 : num_forward_normal_to_normal_assignments++; - num_forward_normal_from_diag_thefts++; - break; - - case 11 : num_forward_diag_to_diag_assignments++; - num_forward_diag_from_normal_thefts++; - break; - case 10 : num_forward_diag_to_normal_assignments++; - num_forward_diag_from_normal_thefts++; - break; - break; - case 1 : num_forward_normal_to_diag_assignments++; - num_forward_normal_from_normal_thefts++; - break; - break; - case 0 : num_forward_normal_to_normal_assignments++; - num_forward_normal_from_normal_thefts++; - break; - default : std::cerr << "key = " << key << std::endl; - throw std::runtime_error("Bug in logging, wrong key"); - break; - } -#endif sanity_check(); } @@ -323,63 +228,6 @@ void AuctionRunnerFR::assign_reverse(IdxType item_idx, IdxType bidder_idx // new edge was added to matching, increase partial cost partial_cost += get_item_bidder_cost(item_idx, bidder_idx); - -#ifdef LOG_AUCTION - if (unassigned_items.size() > parallel_threshold) { - num_parallel_assignments++; - } - num_total_assignments++; - - int it_d = is_item_diagonal(item_idx); - int b_d = is_bidder_diagonal(bidder_idx); - // 2 - None - int old_d = (k_invalid_index == old_bidder_owner) ? 2 : is_item_diagonal(old_bidder_owner); - int key = 100 * old_d + 10 * it_d + b_d; - switch(key) { - case 211 : num_reverse_diag_to_diag_assignments++; - break; - case 210 : num_reverse_diag_to_normal_assignments++; - break; - case 201 : num_reverse_normal_to_diag_assignments++; - break; - case 200 : num_reverse_normal_to_normal_assignments++; - break; - - case 111 : num_reverse_diag_to_diag_assignments++; - num_reverse_diag_from_diag_thefts++; - break; - case 110 : num_reverse_diag_to_normal_assignments++; - num_reverse_diag_from_diag_thefts++; - break; - break; - case 101 : num_reverse_normal_to_diag_assignments++; - num_reverse_normal_from_diag_thefts++; - break; - break; - case 100 : num_reverse_normal_to_normal_assignments++; - num_reverse_normal_from_diag_thefts++; - break; - - case 11 : num_reverse_diag_to_diag_assignments++; - num_reverse_diag_from_normal_thefts++; - break; - case 10 : num_reverse_diag_to_normal_assignments++; - num_reverse_diag_from_normal_thefts++; - break; - break; - case 1 : num_reverse_normal_to_diag_assignments++; - num_reverse_normal_from_normal_thefts++; - break; - break; - case 0 : num_reverse_normal_to_normal_assignments++; - num_reverse_normal_from_normal_thefts++; - break; - default : std::cerr << "key = " << key << std::endl; - throw std::runtime_error("Bug in logging, wrong key"); - break; - } - -#endif } template @@ -409,10 +257,6 @@ void AuctionRunnerFR::assign_to_best_bidder(IdxType item_idx) auto new_bidder_price = -get_item_bidder_cost(item_idx, best_bidder_idx) - best_bid_value; reverse_oracle.set_price(best_bidder_idx, new_bidder_price, false); check_epsilon_css(); -#ifdef LOG_AUCTION - forward_price_change_cnt_vec.back()[item_idx]++; - reverse_price_change_cnt_vec.back()[best_bidder_idx]++; -#endif } template @@ -430,10 +274,6 @@ void AuctionRunnerFR::assign_to_best_item(IdxType bidder_idx) reverse_oracle.sanity_check(); auto new_item_price = -get_item_bidder_cost(best_item_idx, bidder_idx) - best_bid_value; forward_oracle.set_price(best_item_idx, new_item_price, false); -#ifdef LOG_AUCTION - forward_price_change_cnt_vec.back()[best_item_idx]++; - reverse_price_change_cnt_vec.back()[bidder_idx]++; -#endif check_epsilon_css(); } @@ -487,20 +327,6 @@ void AuctionRunnerFR::submit_forward_bid(IdxType bidder_idx, const IdxVal items_with_bids.insert(best_item_idx); -#ifdef LOG_AUCTION - - if (unassigned_bidders.size() > parallel_threshold) { - num_parallel_bids++; - } - num_total_bids++; - - - if (is_bidder_diagonal(bidder_idx)) { - num_diag_forward_bids_submitted++; - } else { - num_normal_forward_bids_submitted++; - } -#endif } template @@ -525,19 +351,6 @@ void AuctionRunnerFR::submit_reverse_bid(IdxType item_idx, const IdxValPa } bidders_with_bids.insert(best_bidder_idx); -#ifdef LOG_AUCTION - - if (unassigned_items.size() > parallel_threshold) { - num_parallel_bids++; - } - num_total_bids++; - - if (is_item_diagonal(item_idx)) { - num_diag_reverse_bids_submitted++; - } else { - num_normal_reverse_bids_submitted++; - } -#endif } @@ -628,35 +441,6 @@ void AuctionRunnerFR::flush_assignment() unassigned_items_by_persistence.insert(std::make_pair(items[item_idx].persistence_lp(1.0), item_idx)); } #endif - -#ifdef LOG_AUCTION - - reset_phase_stat(); - - forward_price_change_cnt_vec.push_back(std::vector(num_items, 0)); - reverse_price_change_cnt_vec.push_back(std::vector(num_bidders, 0)); - - // all bidders and items become unassigned - for(size_t bidder_idx = 0; bidder_idx < num_bidders; ++bidder_idx) { - if (is_bidder_normal(bidder_idx)) { - unassigned_normal_bidders.insert(bidder_idx); - } else { - unassigned_diag_bidders.insert(bidder_idx); - } - } - - never_assigned_bidders = unassigned_bidders; - - for(size_t item_idx = 0; item_idx < items.size(); ++item_idx) { - if (is_item_normal(item_idx)) { - unassigned_normal_items.insert(item_idx); - } else { - unassigned_diag_items.insert(item_idx); - } - } - - never_assigned_items = unassigned_items; -#endif check_epsilon_css(); } @@ -803,13 +587,6 @@ void AuctionRunnerFR::add_unassigned_bidder(const size_t bidder_idx) unassigned_bidders_by_persistence.insert(std::make_pair(bidder.persistence_lp(1.0), bidder_idx)); #endif -#ifdef LOG_AUCTION - if (is_bidder_diagonal(bidder_idx)) { - unassigned_diag_bidders.insert(bidder_idx); - } else { - unassigned_normal_bidders.insert(bidder_idx); - } -#endif } template @@ -823,13 +600,6 @@ void AuctionRunnerFR::add_unassigned_item(const size_t item_idx) unassigned_items_by_persistence.insert(std::make_pair(item.persistence_lp(1.0), item_idx)); #endif -#ifdef LOG_AUCTION - if (is_item_diagonal(item_idx)) { - unassigned_diag_items.insert(item_idx); - } else { - unassigned_normal_items.insert(item_idx); - } -#endif } @@ -845,17 +615,6 @@ void AuctionRunnerFR::remove_unassigned_bidder(const size_t bidder_idx) unassigned_bidders_by_persistence.erase(std::make_pair(bidders[bidder_idx].persistence_lp(1.0), bidder_idx)); #endif -#ifdef LOG_AUCTION - if (is_bidder_diagonal(bidder_idx)) { - unassigned_diag_bidders.erase(bidder_idx); - } else { - unassigned_normal_bidders.erase(bidder_idx); - } - if (never_assigned_bidders.empty() and not all_assigned_round_found) { - all_assigned_round = num_rounds_non_cumulative; - all_assigned_round_found = true; - } -#endif } template @@ -870,17 +629,6 @@ void AuctionRunnerFR::remove_unassigned_item(const size_t item_idx) unassigned_items_by_persistence.erase(std::make_pair(items[item_idx].persistence_lp(1.0), item_idx)); #endif -#ifdef LOG_AUCTION - if (is_item_normal(item_idx)) { - unassigned_normal_items.erase(item_idx); - } else { - unassigned_diag_items.erase(item_idx); - } - if (never_assigned_items.empty() and not all_assigned_round_found) { - all_assigned_round = num_rounds_non_cumulative; - all_assigned_round_found = true; - } -#endif } template @@ -906,14 +654,6 @@ void AuctionRunnerFR::run_reverse_auction_phase() num_rounds_non_cumulative++; check_epsilon_css(); -#ifdef LOG_AUCTION - if (unassigned_items.size() >= parallel_threshold) { - ++num_parallelizable_reverse_rounds; - ++num_parallelizable_rounds; - } - num_reverse_rounds++; - num_reverse_rounds_non_cumulative++; -#endif reset_round_stat(); // bidding @@ -986,14 +726,6 @@ void AuctionRunnerFR::run_forward_auction_phase() while (continue_forward(original_unassigned_bidders, min_forward_matching_increment)) { check_epsilon_css(); num_rounds++; -#ifdef LOG_AUCTION - if (unassigned_bidders.size() >= parallel_threshold) { - ++num_parallelizable_forward_rounds; - ++num_parallelizable_rounds; - } - num_forward_rounds++; - num_forward_rounds_non_cumulative++; -#endif reset_round_stat(); // bidding step @@ -1024,33 +756,6 @@ void AuctionRunnerFR::run_forward_auction_phase() check_epsilon_css(); -#ifdef LOG_AUCTION - forward_plot_logger->info("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14} {15} {16} {17} {18} {19} {20} {21} {22}", - num_phase, - num_rounds, - num_forward_rounds, - unassigned_bidders.size(), - get_gamma(), - partial_cost, - forward_oracle.get_epsilon(), - num_normal_forward_bids_submitted, - num_diag_forward_bids_submitted, - num_forward_diag_to_diag_assignments, - num_forward_diag_to_normal_assignments, - num_forward_normal_to_diag_assignments, - num_forward_normal_to_normal_assignments, - num_forward_diag_from_diag_thefts, - num_forward_diag_from_normal_thefts, - num_forward_normal_from_diag_thefts, - num_forward_normal_from_normal_thefts, - unassigned_normal_bidders.size(), - unassigned_diag_bidders.size(), - unassigned_normal_items.size(), - unassigned_diag_items.size(), - forward_oracle.get_heap_top_size(), - get_relative_error(false) - ); -#endif } ; } diff --git a/wasserstein/include/auction_runner_gs.h b/wasserstein/include/auction_runner_gs.h index 8ad95c2..3616a98 100644 --- a/wasserstein/include/auction_runner_gs.h +++ b/wasserstein/include/auction_runner_gs.h @@ -49,8 +49,7 @@ public: AuctionRunnerGS(const PointContainer& A, const PointContainer& B, - const AuctionParams& params, - const std::string& _log_filename_prefix = ""); + const AuctionParams& params); void set_epsilon(Real new_val) { assert(epsilon > 0.0); epsilon = new_val; }; Real get_epsilon() const { return oracle.get_epsilon(); } @@ -98,19 +97,6 @@ public: int num_phase { 0 }; int num_rounds { 0 }; bool is_distance_computed {false}; -#ifdef LOG_AUCTION - bool log_auction { false }; - std::shared_ptr console_logger; - std::shared_ptr plot_logger; - std::unordered_set unassigned_items; - size_t max_unassigned_to_log { 0 }; - const char* logger_name = "auction_detailed_logger"; // the name in spdlog registry; filename is provided as parameter in enable_logging - const Real total_items_persistence; - const Real total_bidders_persistence; - Real partial_cost; - Real unassigned_bidders_persistence; - Real unassigned_items_persistence; -#endif }; } // ws diff --git a/wasserstein/include/auction_runner_gs.hpp b/wasserstein/include/auction_runner_gs.hpp index 4ef94db..dcc8960 100644 --- a/wasserstein/include/auction_runner_gs.hpp +++ b/wasserstein/include/auction_runner_gs.hpp @@ -54,8 +54,7 @@ namespace ws { template AuctionRunnerGS::AuctionRunnerGS(const PC& A, const PC& B, - const AuctionParams& params, - const std::string& _log_filename_prefix) : + const AuctionParams& params) : bidders(A), items(B), num_bidders(A.size()), @@ -71,63 +70,14 @@ AuctionRunnerGS::AuctionRunnerGS(const PC& A, tolerate_max_iter_exceeded(params.tolerate_max_iter_exceeded), dimension(params.dim), oracle(bidders, items, params) -#ifdef LOG_AUCTION - , total_items_persistence(std::accumulate(items.begin(), - items.end(), - R(0.0), - [params](const Real& ps, const DgmPoint& item) - { return ps + std::pow(item.persistence_lp(params.internal_p), params.wasserstein_power); } - )) - - , total_bidders_persistence(std::accumulate(bidders.begin(), - bidders.end(), - R(0.0), - [params](const Real& ps, const DgmPoint& bidder) - { return ps + std::pow(bidder.persistence_lp(params.internal_p), params.wasserstein_power); } - )) - , partial_cost(0.0) - , unassigned_bidders_persistence(0.0) - , unassigned_items_persistence(0.0) -#endif { assert(initial_epsilon >= 0.0 ); assert(epsilon_common_ratio >= 0.0 ); assert(A.size() == B.size()); -#ifdef LOG_AUCTION - - unassigned_items_persistence = total_items_persistence; - unassigned_bidders_persistence = total_bidders_persistence; - - console_logger = spdlog::get("console"); - if (not console_logger) { - console_logger = spdlog::stdout_logger_st("console"); - } - console_logger->set_pattern("[%H:%M:%S.%e] %v"); - console_logger->debug("Gauss-Seidel, num_bidders = {0}", num_bidders); - - plot_logger = spdlog::get("plot_logger"); - if (not plot_logger) { - plot_logger = spdlog::basic_logger_st("plot_logger", "plot_logger.txt"); - plot_logger->info("New plot starts here"); - plot_logger->set_pattern("%v"); - } -#endif } -#ifdef LOG_AUCTION -template -void AuctionRunnerGS::enable_logging(const char* log_filename, const size_t _max_unassigned_to_log) -{ - log_auction = true; - max_unassigned_to_log = _max_unassigned_to_log; - - auto log = spdlog::basic_logger_st(logger_name, log_filename); - log->set_pattern("%v"); -} -#endif - template void AuctionRunnerGS::assign_item_to_bidder(IdxType item_idx, IdxType bidder_idx) { @@ -148,58 +98,6 @@ void AuctionRunnerGS::assign_item_to_bidder(IdxType item_idx, IdxType bidders_to_items[old_item_owner] = k_invalid_index; unassigned_bidders.insert(old_item_owner); } - - -#ifdef LOG_AUCTION - - partial_cost += get_item_bidder_cost(item_idx, bidder_idx, true); - partial_cost -= get_item_bidder_cost(item_idx, old_item_owner, true); - - unassigned_items.erase(item_idx); - - unassigned_bidders_persistence -= std::pow(bidders[bidder_idx].persistence_lp(internal_p), wasserstein_power); - - if (old_item_owner != k_invalid_index) { - // item has been assigned to some other bidder, - // and he became unassigned - unassigned_bidders_persistence += std::pow(bidders[old_item_owner].persistence_lp(internal_p), wasserstein_power); - } else { - // item was unassigned before - unassigned_items_persistence -= std::pow(items[item_idx].persistence_lp(internal_p), wasserstein_power); - } - - if (log_auction) - plot_logger->info("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9}", - num_phase, - num_rounds, - unassigned_bidders.size(), - unassigned_items_persistence, - unassigned_bidders_persistence, - unassigned_items_persistence + unassigned_bidders_persistence, - partial_cost, - total_bidders_persistence, - total_items_persistence, - oracle.get_epsilon() - ); - - - if (log_auction and unassigned_bidders.size() <= max_unassigned_to_log) { - auto logger = spdlog::get(logger_name); - if (logger) { - auto item = items[item_idx]; - auto bidder = bidders[bidder_idx]; - logger->info("{0} # ({1}, {2}) # ({3}, {4}) # {5} # {6} # {7}", - num_rounds, - item.getRealX(), - item.getRealY(), - bidder.getRealX(), - bidder.getRealY(), - format_point_set_to_log(unassigned_bidders, bidders), - format_point_set_to_log(unassigned_items, items), - oracle.get_epsilon()); - } - } -#endif } @@ -220,16 +118,6 @@ void AuctionRunnerGS::flush_assignment() } assert(unassigned_bidders.size() == bidders.size()); -#ifdef LOG_AUCTION - partial_cost = 0.0; - unassigned_bidders_persistence = total_bidders_persistence; - unassigned_items_persistence = total_items_persistence; - - for(size_t item_idx = 0; item_idx < items.size(); ++item_idx) { - unassigned_items.insert(item_idx); - } -#endif - oracle.adjust_prices(); } @@ -253,24 +141,13 @@ void AuctionRunnerGS::run_auction_phases(const int max_num_phases, co // assert(fabs(current_result - current_result_1) < 0.001); Real denominator = current_result - num_bidders * oracle.get_epsilon(); current_result = pow(current_result, 1.0 / wasserstein_power); -#ifdef LOG_AUCTION - console_logger->info("Phase {0} done, num_rounds (cumulative) = {1}, current_result = {2}, epsilon = {3}", - phase_num, format_int(num_rounds), current_result, - oracle.get_epsilon()); -#endif + if ( denominator <= 0 ) { -#ifdef LOG_AUCTION - console_logger->info("Epsilon is too large"); -#endif + ; } else { denominator = pow(denominator, 1.0 / wasserstein_power); Real numerator = current_result - denominator; relative_error = numerator / denominator; - // spdlog::get("console")->info("relative error = {} / {} = {}, result = {}", numerator, denominator, relative_error, current_result); -#ifdef LOG_AUCTION - console_logger->info("error = {0} / {1} = {2}", - numerator, denominator, relative_error); -#endif if (relative_error <= delta) { break; } diff --git a/wasserstein/include/auction_runner_gs_single_diag.h b/wasserstein/include/auction_runner_gs_single_diag.h index f32fbbc..9746255 100644 --- a/wasserstein/include/auction_runner_gs_single_diag.h +++ b/wasserstein/include/auction_runner_gs_single_diag.h @@ -127,17 +127,6 @@ public: Real getDistanceToQthPowerInternal(); int num_phase { 0 }; int num_rounds { 0 }; -#ifdef LOG_AUCTION - bool log_auction { false }; - std::unordered_set unassigned_items; - size_t max_unassigned_to_log { 0 }; - const char* logger_name = "auction_detailed_logger"; // the name in spdlog registry; filename is provided as parameter in enable_logging - const Real total_items_persistence; - const Real total_bidders_persistence; - Real partial_cost; - Real unassigned_bidders_persistence; - Real unassigned_items_persistence; -#endif }; } // ws diff --git a/wasserstein/include/auction_runner_gs_single_diag.hpp b/wasserstein/include/auction_runner_gs_single_diag.hpp index a3c401e..b56fbfb 100644 --- a/wasserstein/include/auction_runner_gs_single_diag.hpp +++ b/wasserstein/include/auction_runner_gs_single_diag.hpp @@ -96,24 +96,6 @@ AuctionRunnerGaussSeidelSingleDiag::AuctionRunnerGaussSeidelSingleDiag(co initial_epsilon(_initial_epsilon), epsilon_common_ratio(_eps_factor == 0.0 ? 5.0 : _eps_factor), max_iter_num(_max_iter_num) -#ifdef LOG_AUCTION - , total_items_persistence(std::accumulate(items.begin(), - items.end(), - R(0.0), - [_internal_p, q](const Real& ps, const DgmPoint& item) - { return ps + std::pow(item.persistence_lp(_internal_p), q); } - )) - - , total_bidders_persistence(std::accumulate(bidders.begin(), - bidders.end(), - R(0.0), - [_internal_p, q](const Real& ps, const DgmPoint& bidder) - { return ps + std::pow(bidder.persistence_lp(_internal_p), q); } - )) - , partial_cost(0.0) - , unassigned_bidders_persistence(0.0) - , unassigned_items_persistence(0.0) -#endif { assert(initial_epsilon >= 0.0 ); @@ -133,33 +115,8 @@ AuctionRunnerGaussSeidelSingleDiag::AuctionRunnerGaussSeidelSingleDiag(co for(size_t i = num_normal_bidders; i < num_bidders; ++i) { assert(bidders[i].is_diagonal()); } - -#ifdef LOG_AUCTION - - unassigned_items_persistence = total_items_persistence; - unassigned_bidders_persistence = total_bidders_persistence; - - if (not spdlog::get("plot_logger")) { - auto log = spdlog::basic_logger_st("plot_logger", "plot_logger.txt"); - log->info("New plot starts here"); - log->set_pattern("%v"); - } -#endif - } -#ifdef LOG_AUCTION -template -void AuctionRunnerGaussSeidelSingleDiag::enable_logging(const char* log_filename, const size_t _max_unassigned_to_log) -{ - log_auction = true; - max_unassigned_to_log = _max_unassigned_to_log; - - auto log = spdlog::basic_logger_st(logger_name, log_filename); - log->set_pattern("%v"); -} -#endif - template void AuctionRunnerGaussSeidelSingleDiag::process_diagonal_bid(const DiagonalBidR& bid) { @@ -337,61 +294,6 @@ void AuctionRunnerGaussSeidelSingleDiag::assign_item_to_bidder(const IdxT if (call_set_price) { oracle->set_price(item_idx, new_price, item_is_diagonal, bidder_is_diagonal, old_owner_type); } - - //std::cout << "Exit assign_item_to_bidder, state\n" << *this << std::endl; - -#ifdef LOG_AUCTION - - partial_cost += get_item_bidder_cost(item_idx, bidder_idx, true); - partial_cost -= get_item_bidder_cost(item_idx, old_owner_idx, true); - - unassigned_items.erase(item_idx); - - unassigned_bidders_persistence -= std::pow(bidders[bidder_idx].persistence_lp(internal_p), wasserstein_power); - - if (old_owner_type != OwnerType::k_none) { - // item has been assigned to some other bidder, - // and he became unassigned - unassigned_bidders_persistence += std::pow(bidders[old_owner_idx].persistence_lp(internal_p), wasserstein_power); - } else { - // item was unassigned before - unassigned_items_persistence -= std::pow(items[item_idx].persistence_lp(internal_p), wasserstein_power); - } - - auto plot_logger = spdlog::get("plot_logger"); - plot_logger->info("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10}", - num_phase, - num_rounds, - unassigned_normal_bidders.size(), - unassigned_diag_bidders.size(), - unassigned_items_persistence, - unassigned_bidders_persistence, - unassigned_items_persistence + unassigned_bidders_persistence, - partial_cost, - total_bidders_persistence, - total_items_persistence, - oracle->get_epsilon() - ); - - - if (log_auction and unassigned_normal_bidders.size() + unassigned_diag_bidders.size() <= max_unassigned_to_log) { - auto logger = spdlog::get(logger_name); - if (logger) { - auto item = items[item_idx]; - auto bidder = bidders[bidder_idx]; - logger->info("{0} # ({1}, {2}) # ({3}, {4}) # {5} # {6} # {7} # {8}", - num_rounds, - item.getRealX(), - item.getRealY(), - bidder.getRealX(), - bidder.getRealY(), - format_point_set_to_log(unassigned_diag_bidders, bidders), - format_point_set_to_log(unassigned_normal_bidders, bidders), - format_point_set_to_log(unassigned_items, items), - oracle->get_epsilon()); - } - } -#endif } @@ -421,17 +323,6 @@ void AuctionRunnerGaussSeidelSingleDiag::flush_assignment() oracle->flush_assignment(); oracle->adjust_prices(); - -#ifdef LOG_AUCTION - partial_cost = 0.0; - unassigned_bidders_persistence = total_bidders_persistence; - unassigned_items_persistence = total_items_persistence; - - for(size_t item_idx = 0; item_idx < items.size(); ++item_idx) { - unassigned_items.insert(item_idx); - } -#endif - } diff --git a/wasserstein/include/auction_runner_jac.h b/wasserstein/include/auction_runner_jac.h index 252ca32..11b8f8e 100644 --- a/wasserstein/include/auction_runner_jac.h +++ b/wasserstein/include/auction_runner_jac.h @@ -30,7 +30,6 @@ derivative works thereof, in binary and source code form. #define HERA_AUCTION_RUNNER_JAC_H #ifdef WASSERSTEIN_PURE_GEOM -#undef LOG_AUCTION #undef ORDERED_BY_PERSISTENCE #endif @@ -62,8 +61,7 @@ public: AuctionRunnerJac(const PointContainer& A, const PointContainer& B, - const AuctionParams& params, - const std::string& _log_filename_prefix = ""); + const AuctionParams& params); void set_epsilon(Real new_val); Real get_epsilon() const { return epsilon; } @@ -74,7 +72,7 @@ public: void decrease_epsilon(); Real get_wasserstein_distance(); Real get_wasserstein_cost(); - Real get_relative_error(const bool debug_output = false) const; + Real get_relative_error() const; //private: // private data PointContainer bidders; @@ -169,54 +167,7 @@ public: void print_debug(); void print_matching(); - std::string log_filename_prefix; const Real k_max_relative_error = 2.0; // if relative error cannot be estimated or is too large, use this value - -#ifdef LOG_AUCTION - - size_t parallel_threshold { 5000 }; - bool is_step_parallel {false}; - std::unordered_set unassigned_items; - std::unordered_set unassigned_normal_items; - std::unordered_set unassigned_diag_items; - std::unordered_set never_assigned_bidders; - size_t all_assigned_round { 0 }; - size_t all_assigned_round_found { false }; - - int num_rounds_non_cumulative { 0 }; // set to 0 in the beginning of each phase - int num_diag_assignments { 0 }; - int num_diag_assignments_non_cumulative { 0 }; - int num_diag_bids_submitted { 0 }; - int num_diag_stole_from_diag { 0 }; - int num_normal_assignments { 0 }; - int num_normal_assignments_non_cumulative { 0 }; - int num_normal_bids_submitted { 0 }; - - std::vector> price_change_cnt_vec; - - - const char* plot_logger_name = "plot_logger"; - const char* price_state_logger_name = "price_stat_logger"; - std::string plot_logger_file_name; - std::string price_stat_logger_file_name; - std::shared_ptr plot_logger; - std::shared_ptr price_stat_logger; - std::shared_ptr console_logger; - - - int num_parallel_bids { 0 }; - int num_total_bids { 0 }; - - int num_parallel_diag_bids { 0 }; - int num_total_diag_bids { 0 }; - - int num_parallel_normal_bids { 0 }; - int num_total_normal_bids { 0 }; - - int num_parallel_assignments { 0 }; - int num_total_assignments { 0 }; -#endif - }; // AuctionRunnerJac diff --git a/wasserstein/include/auction_runner_jac.hpp b/wasserstein/include/auction_runner_jac.hpp index e623f4a..4dcb235 100644 --- a/wasserstein/include/auction_runner_jac.hpp +++ b/wasserstein/include/auction_runner_jac.hpp @@ -53,9 +53,7 @@ namespace ws { template AuctionRunnerJac::AuctionRunnerJac(const PointContainer& A, const PointContainer& B, - const AuctionParams& params, - const std::string &_log_filename_prefix - ) : + const AuctionParams& params) : bidders(A), items(B), num_bidders(A.size()), @@ -71,9 +69,9 @@ namespace ws { bid_table(A.size(), std::make_pair(k_invalid_index, k_lowest_bid_value)), oracle(bidders, items, params), max_bids_per_round(params.max_bids_per_round), - dimension(params.dim), + dimension(params.dim) #ifndef WASSERSTEIN_PURE_GEOM - total_items_persistence(std::accumulate(items.begin(), + , total_items_persistence(std::accumulate(items.begin(), items.end(), R(0.0), [params](const Real &ps, const DgmPoint &item) { @@ -89,9 +87,8 @@ namespace ws { )), unassigned_bidders_persistence(total_bidders_persistence), unassigned_items_persistence(total_items_persistence), - gamma_threshold(params.gamma_threshold), + gamma_threshold(params.gamma_threshold) #endif - log_filename_prefix(_log_filename_prefix) { assert(A.size() == B.size()); @@ -119,74 +116,6 @@ namespace ws { } #endif -#ifdef LOG_AUCTION - parallel_threshold = 16; - console_logger = spdlog::get("console"); - if (not console_logger) { - console_logger = spdlog::stdout_logger_st("console"); - } - console_logger->set_pattern("[%H:%M:%S.%e] %v"); -#ifdef ORDERED_BY_PERSISTENCE - if (max_bids_per_round == 1) { - console_logger->info("Gauss-Seidel imitated by Jacobi runner, q = {0}, max_bids_per_round = {1}, batch_size = {4}, gamma_threshold = {2}, diag_first = {3} ORDERED_BY_PERSISTENCE", - wasserstein_power, - max_bids_per_round, - gamma_threshold, - diag_first, - batch_size); - } else { - console_logger->info("Jacobi runner, q = {0}, max_bids_per_round = {1}, batch_size = {4}, gamma_threshold = {2}, diag_first = {3} ORDERED_BY_PERSISTENCE", - wasserstein_power, - max_bids_per_round, - gamma_threshold, - diag_first, - batch_size); - } - -#else - if (max_bids_per_round == 1) { - console_logger->info( - "Gauss-Seidel imitated by Jacobi runner, q = {0}, max_bids_per_round = {1}, batch_size = {4}, gamma_threshold = {2}, diag_first = {3}", - wasserstein_power, - max_bids_per_round, - gamma_threshold, - diag_first, - batch_size); - } else { - console_logger->info( - "Jacobi runner, q = {0}, max_bids_per_round = {1}, batch_size = {4}, gamma_threshold = {2}, diag_first = {3}", - wasserstein_power, - max_bids_per_round, - gamma_threshold, - diag_first, - batch_size); - } -#endif - - plot_logger_file_name = log_filename_prefix + "_plot.txt"; - plot_logger = spdlog::get(plot_logger_name); - if (not plot_logger) { - plot_logger = spdlog::basic_logger_st(plot_logger_name, plot_logger_file_name); - } - plot_logger->info("New plot starts here, diagram size = {0}, gamma_threshold = {1}, epsilon_common_ratio = {2}", - bidders.size(), - gamma_threshold, - epsilon_common_ratio); - plot_logger->set_pattern("%v"); - - price_stat_logger_file_name = log_filename_prefix + "_price_change_stat"; - price_stat_logger = spdlog::get(price_state_logger_name); - if (not price_stat_logger) { - price_stat_logger = spdlog::basic_logger_st(price_state_logger_name, - price_stat_logger_file_name); - } - price_stat_logger->info( - "New price statistics starts here, diagram size = {0}, gamma_threshold = {1}, epsilon_common_ratio = {2}", - bidders.size(), - gamma_threshold, - epsilon_common_ratio); - price_stat_logger->set_pattern("%v"); -#endif } #ifndef WASSERSTEIN_PURE_GEOM @@ -233,24 +162,6 @@ namespace ws { // new edge was added to matching, increase partial cost partial_cost += get_item_bidder_cost(item_idx, bidder_idx); - -#ifdef LOG_AUCTION - if (is_item_diagonal(item_idx)) { - num_diag_assignments++; - num_diag_assignments_non_cumulative++; - } else { - num_normal_assignments++; - num_normal_assignments_non_cumulative++; - } - - if (k_invalid_index != old_item_owner) { - if (is_bidder_diagonal(bidder_idx) and is_bidder_diagonal(old_item_owner)) { - num_diag_stole_from_diag++; - } - } -#endif - - //sanity_check(); } template @@ -268,15 +179,6 @@ namespace ws { IdxValPairR best_bid{bid_table[item_idx]}; assign_item_to_bidder(item_idx, best_bid.first); oracle.set_price(item_idx, best_bid.second); -#ifdef LOG_AUCTION - - if (is_step_parallel) { - num_parallel_assignments++; - } - num_total_assignments++; - - price_change_cnt_vec.back()[item_idx]++; -#endif } template @@ -300,18 +202,6 @@ namespace ws { bid_table[item_idx].second = bid_value; } items_with_bids.insert(item_idx); - -#ifdef LOG_AUCTION - - num_total_bids++; - - - if (is_bidder_diagonal(bidder_idx)) { - num_diag_bids_submitted++; - } else { - num_normal_bids_submitted++; - } -#endif } template @@ -347,7 +237,7 @@ namespace ws { template typename AuctionRunnerJac::Real - AuctionRunnerJac::get_relative_error(const bool debug_output) const + AuctionRunnerJac::get_relative_error() const { if (partial_cost == 0.0 and unassigned_bidders.empty()) return 0.0; @@ -360,21 +250,10 @@ namespace ws { // cost minus n epsilon Real reduced_cost = partial_cost - num_bidders * get_epsilon(); if (reduced_cost < 0) { -#ifdef LOG_AUCTION - if (debug_output) { - console_logger->info("Epsilon too large, reduced_cost = {0}, gamma = {1}", reduced_cost, gamma); - } -#endif result = k_max_relative_error; } else { Real denominator = std::pow(reduced_cost, 1.0 / wasserstein_power) - gamma; if (denominator <= 0) { -#ifdef LOG_AUCTION - if (debug_output) { - console_logger->info("Epsilon too large, reduced_cost = {0}, denominator = {1}, gamma = {2}", - reduced_cost, denominator, gamma); - } -#endif result = k_max_relative_error; } else { Real numerator = 2 * gamma + @@ -382,17 +261,6 @@ namespace ws { std::pow(reduced_cost, 1.0 / wasserstein_power); result = numerator / denominator; -#ifdef LOG_AUCTION - if (debug_output) { - console_logger->info( - "Reduced_cost = {0}, denominator = {1}, numerator {2}, error = {3}, gamma = {4}", - reduced_cost, - denominator, - numerator, - result, - gamma); - } -#endif } } return result; @@ -437,30 +305,6 @@ namespace ws { unassigned_bidders_persistence = total_bidders_persistence; unassigned_items_persistence = total_items_persistence; -#ifdef LOG_AUCTION - - price_change_cnt_vec.push_back(std::vector(num_items, 0)); - - never_assigned_bidders = unassigned_bidders; - - for (size_t item_idx = 0; item_idx < items.size(); ++item_idx) { - unassigned_items.insert(item_idx); - if (is_item_normal(item_idx)) { - unassigned_normal_items.insert(item_idx); - } else { - unassigned_diag_items.insert(item_idx); - } - } - - num_diag_bids_submitted = 0; - num_normal_bids_submitted = 0; - num_diag_assignments = 0; - num_normal_assignments = 0; - - all_assigned_round = 0; - all_assigned_round_found = false; - num_rounds_non_cumulative = 0; -#endif #endif } // flush_assignment @@ -481,65 +325,6 @@ namespace ws { flush_assignment(); run_auction_phase(); -#ifdef LOG_AUCTION - console_logger->info( - "Phase {0} done, current_result = {1}, eps = {2}, error = {7}, num_rounds = {3}, num_assignments = {4}, num_bids_submitted = {5}, # unassigned = {6}", - num_phase, - partial_cost, - get_epsilon(), - format_int<>(num_rounds), - format_int<>(num_normal_assignments + num_diag_assignments), - format_int<>(num_normal_bids_submitted + num_diag_bids_submitted), - unassigned_bidders.size(), - get_relative_error(num_phase == 1) - ); - -// console_logger->info("num_rounds (non-cumulative)= {0}, num_diag_assignments = {1}, num_normal_assignments = {2}, num_diag_bids_submitted = {3}, num_normal_bids_submitted = {4}", -// format_int<>(num_rounds_non_cumulative), -// format_int<>(num_diag_assignments), -// format_int<>(num_normal_assignments), -// format_int<>(num_diag_bids_submitted), -// format_int<>(num_normal_bids_submitted) -// ); - - console_logger->info( - "num_parallel_bids / num_total_bids = {0} / {1} = {2}, num_parallel_assignments / num_total_aassignments = {3} / {4} = {5}", - format_int<>(num_parallel_bids), - format_int<>(num_total_bids), - static_cast(num_parallel_bids) / static_cast(num_total_bids), - format_int<>(num_parallel_assignments), - format_int<>(num_total_assignments), - static_cast(num_parallel_assignments) / static_cast(num_total_assignments) - ); - - console_logger->info( - "num_parallel_diag_bids / num_total_diag_bids = {0} / {1} = {2}, num_parallel_normal_bids / num_total_normal_bids = {3} / {4} = {5}", - format_int<>(num_parallel_diag_bids), - format_int<>(num_total_diag_bids), - static_cast(num_parallel_diag_bids) / static_cast(num_total_diag_bids), - format_int<>(num_parallel_normal_bids), - format_int<>(num_total_normal_bids), - static_cast(num_parallel_normal_bids) / static_cast(num_total_normal_bids) - ); - -// console_logger->info("num_rounds before all biders assigned = {0}, num_rounds (non-cumulative)= {1}, fraction = {2}", -// format_int<>(all_assigned_round), -// format_int<>(num_rounds_non_cumulative), -// static_cast(all_assigned_round) / static_cast(num_rounds_non_cumulative) -// ); - - for (size_t item_idx = 0; item_idx < num_items; ++item_idx) { - price_stat_logger->info("{0} {1} {2} {3} {4}", - phase_num, - item_idx, - items[item_idx][0], - items[item_idx][1], - price_change_cnt_vec.back()[item_idx] - ); - } -#endif - - if (is_done()) break; else @@ -618,31 +403,15 @@ namespace ws { unassigned_normal_bidders.erase(bidder_idx); } - -#ifdef LOG_AUCTION - never_assigned_bidders.erase(bidder_idx); - if (never_assigned_bidders.empty() and not all_assigned_round_found) { - all_assigned_round = num_rounds_non_cumulative; - all_assigned_round_found = true; - } -#endif #endif } template void AuctionRunnerJac::remove_unassigned_item(const size_t item_idx) { + // to suppress unused parameter warning + (void)item_idx; #ifndef WASSERSTEIN_PURE_GEOM unassigned_items_persistence -= get_cost_to_diagonal(items[item_idx]); - -#ifdef LOG_AUCTION - unassigned_items.erase(item_idx); - - if (is_item_normal(item_idx)) { - unassigned_normal_items.erase(item_idx); - } else { - unassigned_diag_items.erase(item_idx); - } -#endif #endif } @@ -650,12 +419,6 @@ namespace ws { template void AuctionRunnerJac::run_bidding_step(const Range &active_bidders) { -#ifdef LOG_AUCTION - is_step_parallel = false; - size_t diag_bids_submitted = 0; - size_t normal_bids_submitted = 0; -#endif - clear_bid_table(); size_t bids_submitted = 0; for (const auto bidder_idx : active_bidders) { @@ -663,37 +426,8 @@ namespace ws { ++bids_submitted; submit_bid(bidder_idx, oracle.get_optimal_bid(bidder_idx)); - -#ifdef LOG_AUCTION - if (is_bidder_diagonal(bidder_idx)) { - diag_bids_submitted++; - } else { - normal_bids_submitted++; - } - - if (bids_submitted >= parallel_threshold) { - is_step_parallel = true; - } - - if (bids_submitted >= max_bids_per_round) { - break; - } - if (diag_first and not unassigned_diag_bidders.empty() and - diag_bids_submitted >= oracle.get_heap_top_size()) { - continue; - } -#endif } -#ifdef LOG_AUCTION - num_total_diag_bids += diag_bids_submitted; - num_total_normal_bids += normal_bids_submitted; - if (is_step_parallel) { - num_parallel_bids += bids_submitted; - num_parallel_diag_bids += diag_bids_submitted; - num_parallel_normal_bids += normal_bids_submitted; - } -#endif } template @@ -720,12 +454,6 @@ namespace ws { do { num_rounds++; -#ifdef LOG_AUCTION - num_diag_stole_from_diag = 0; - num_normal_assignments_non_cumulative = 0; - num_diag_assignments_non_cumulative = 0; - num_rounds_non_cumulative++; -#endif // bidding #ifdef ORDERED_BY_PERSISTENCE @@ -756,26 +484,6 @@ namespace ws { for (auto item_idx : items_with_bids) { assign_to_best_bidder(item_idx); } -#ifdef LOG_AUCTION - plot_logger->info("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14}", - num_phase, - num_rounds, - unassigned_bidders.size(), - get_gamma(), - partial_cost, - oracle.get_epsilon(), - unassigned_normal_bidders.size(), - unassigned_diag_bidders.size(), - unassigned_normal_items.size(), - unassigned_diag_items.size(), - num_normal_assignments_non_cumulative, - num_diag_assignments_non_cumulative, - oracle.get_heap_top_size(), - get_relative_error(false), - num_diag_stole_from_diag - ); -#endif - //sanity_check(); } while (continue_auction_phase()); } diff --git a/wasserstein/include/basic_defs_ws.h b/wasserstein/include/basic_defs_ws.h index bdcfd75..73c761c 100644 --- a/wasserstein/include/basic_defs_ws.h +++ b/wasserstein/include/basic_defs_ws.h @@ -236,7 +236,7 @@ namespace ws template struct DistImpl> { - Real operator()(const DiagramPoint& a, const DiagramPoint& b, const Real p, const int dim) + Real operator()(const DiagramPoint& a, const DiagramPoint& b, const Real p, const int /*dim */) { Real result = 0.0; if ( a.is_diagonal() and b.is_diagonal()) { diff --git a/wasserstein/include/catch/catch.hpp b/wasserstein/include/catch/catch.hpp index f7681f4..db1fed3 100644 --- a/wasserstein/include/catch/catch.hpp +++ b/wasserstein/include/catch/catch.hpp @@ -1,17 +1,21 @@ /* - * Catch v1.9.6 - * Generated: 2017-06-27 12:19:54.557875 + * Catch v2.13.8 + * Generated: 2022-01-03 21:20:09.589503 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly - * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. + * Copyright (c) 2022 Two Blue Cubes Ltd. All rights reserved. * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED #define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +// start catch.hpp -#define TWOBLUECUBES_CATCH_HPP_INCLUDED + +#define CATCH_VERSION_MAJOR 2 +#define CATCH_VERSION_MINOR 13 +#define CATCH_VERSION_PATCH 8 #ifdef __clang__ # pragma clang system_header @@ -19,36 +23,69 @@ # pragma GCC system_header #endif -// #included from: internal/catch_suppress_warnings.h +// start catch_suppress_warnings.h #ifdef __clang__ # ifdef __ICC // icpc defines the __clang__ macro # pragma warning(push) # pragma warning(disable: 161 1682) # else // __ICC -# pragma clang diagnostic ignored "-Wglobal-constructors" -# pragma clang diagnostic ignored "-Wvariadic-macros" -# pragma clang diagnostic ignored "-Wc99-extensions" -# pragma clang diagnostic ignored "-Wunused-variable" # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wpadded" -# pragma clang diagnostic ignored "-Wc++98-compat" -# pragma clang diagnostic ignored "-Wc++98-compat-pedantic" # pragma clang diagnostic ignored "-Wswitch-enum" # pragma clang diagnostic ignored "-Wcovered-switch-default" # endif #elif defined __GNUC__ -# pragma GCC diagnostic ignored "-Wvariadic-macros" -# pragma GCC diagnostic ignored "-Wunused-variable" -# pragma GCC diagnostic ignored "-Wparentheses" + // Because REQUIREs trigger GCC's -Wparentheses, and because still + // supported version of g++ have only buggy support for _Pragmas, + // Wparentheses have to be suppressed globally. +# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details # pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-variable" # pragma GCC diagnostic ignored "-Wpadded" #endif +// end catch_suppress_warnings.h #if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) # define CATCH_IMPL +# define CATCH_CONFIG_ALL_PARTS +#endif + +// In the impl file, we want to have access to all parts of the headers +// Can also be used to sanely support PCHs +#if defined(CATCH_CONFIG_ALL_PARTS) +# define CATCH_CONFIG_EXTERNAL_INTERFACES +# if defined(CATCH_CONFIG_DISABLE_MATCHERS) +# undef CATCH_CONFIG_DISABLE_MATCHERS +# endif +# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +# endif +#endif + +#if !defined(CATCH_CONFIG_IMPL_ONLY) +// start catch_platform.h + +// See e.g.: +// https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/TargetConditionals.h.auto.html +#ifdef __APPLE__ +# include +# if (defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1) || \ + (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1) +# define CATCH_PLATFORM_MAC +# elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1) +# define CATCH_PLATFORM_IPHONE +# endif + +#elif defined(linux) || defined(__linux) || defined(__linux__) +# define CATCH_PLATFORM_LINUX + +#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) +# define CATCH_PLATFORM_WINDOWS #endif +// end catch_platform.h + #ifdef CATCH_IMPL # ifndef CLARA_CONFIG_MAIN # define CLARA_CONFIG_MAIN_NOT_DEFINED @@ -56,93 +93,130 @@ # endif #endif -// #included from: internal/catch_notimplemented_exception.h -#define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED +// start catch_user_interfaces.h -// #included from: catch_common.h -#define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED +namespace Catch { + unsigned int rngSeed(); +} + +// end catch_user_interfaces.h +// start catch_tag_alias_autoregistrar.h -// #included from: catch_compiler_capabilities.h -#define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED +// start catch_common.h -// Detect a number of compiler features - mostly C++11/14 conformance - by compiler +// start catch_compiler_capabilities.h + +// Detect a number of compiler features - by compiler // The following features are defined: // -// CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported? -// CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported? -// CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods -// CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported? -// CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported -// CATCH_CONFIG_CPP11_LONG_LONG : is long long supported? -// CATCH_CONFIG_CPP11_OVERRIDE : is override supported? -// CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr) -// CATCH_CONFIG_CPP11_SHUFFLE : is std::shuffle supported? -// CATCH_CONFIG_CPP11_TYPE_TRAITS : are type_traits and enable_if supported? - -// CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported? - -// CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported? // CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? // CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? // CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? +// CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled? // **************** // Note to maintainers: if new toggles are added please document them // in configuration.md, too // **************** // In general each macro has a _NO_ form -// (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature. +// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. // Many features, at point of detection, define an _INTERNAL_ macro, so they // can be combined, en-mass, with the _NO_ forms later. -// All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11 - #ifdef __cplusplus -# if __cplusplus >= 201103L -# define CATCH_CPP11_OR_GREATER +# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) +# define CATCH_CPP14_OR_GREATER # endif -# if __cplusplus >= 201402L -# define CATCH_CPP14_OR_GREATER +# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) +# define CATCH_CPP17_OR_GREATER # endif #endif -#ifdef __clang__ +// Only GCC compiler should be used in this block, so other compilers trying to +// mask themselves as GCC should be ignored. +#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) -# if __has_feature(cxx_nullptr) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -# endif +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) + +#endif -# if __has_feature(cxx_noexcept) -# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT +#if defined(__clang__) + +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) + +// As of this writing, IBM XL's implementation of __builtin_constant_p has a bug +// which results in calls to destructors being emitted for each temporary, +// without a matching initialization. In practice, this can result in something +// like `std::string::~string` being called on an uninitialized value. +// +// For example, this code will likely segfault under IBM XL: +// ``` +// REQUIRE(std::string("12") + "34" == "1234") +// ``` +// +// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented. +# if !defined(__ibmxl__) && !defined(__CUDACC__) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */ # endif -# if defined(CATCH_CPP11_OR_GREATER) -# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ - _Pragma( "clang diagnostic push" ) \ - _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) -# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \ - _Pragma( "clang diagnostic pop" ) - -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ - _Pragma( "clang diagnostic push" ) \ - _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) -# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ - _Pragma( "clang diagnostic pop" ) -# endif +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ + _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") + +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) + +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) #endif // __clang__ +//////////////////////////////////////////////////////////////////////////////// +// Assume that non-Windows platforms support posix signals by default +#if !defined(CATCH_PLATFORM_WINDOWS) + #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS +#endif + //////////////////////////////////////////////////////////////////////////////// // We know some environments not to support full POSIX signals -#if defined(__CYGWIN__) || defined(__QNX__) +#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) + #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +#endif -# if !defined(CATCH_CONFIG_POSIX_SIGNALS) +#ifdef __OS400__ # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS -# endif +# define CATCH_CONFIG_COLOUR_NONE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Android somehow still does not support std::to_string +#if defined(__ANDROID__) +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING +# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Not all Windows environments support SEH properly +#if defined(__MINGW32__) +# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH +#endif +//////////////////////////////////////////////////////////////////////////////// +// PS4 +#if defined(__ORBIS__) +# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE #endif //////////////////////////////////////////////////////////////////////////////// @@ -152,217 +226,245 @@ // Required for some versions of Cygwin to declare gettimeofday // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin # define _BSD_SOURCE +// some versions of cygwin (most) do not support std::to_string. Use the libstd check. +// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 +# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ + && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) -#endif // __CYGWIN__ - -//////////////////////////////////////////////////////////////////////////////// -// Borland -#ifdef __BORLANDC__ +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING -#endif // __BORLANDC__ +# endif +#endif // __CYGWIN__ //////////////////////////////////////////////////////////////////////////////// -// EDG -#ifdef __EDG_VERSION__ - -#endif // __EDG_VERSION__ +// Visual C++ +#if defined(_MSC_VER) -//////////////////////////////////////////////////////////////////////////////// -// Digital Mars -#ifdef __DMC__ +// Universal Windows platform does not support SEH +// Or console colours (or console at all...) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +# define CATCH_CONFIG_COLOUR_NONE +# else +# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH +# endif -#endif // __DMC__ +# if !defined(__clang__) // Handle Clang masquerading for msvc -//////////////////////////////////////////////////////////////////////////////// -// GCC -#ifdef __GNUC__ +// MSVC traditional preprocessor needs some workaround for __VA_ARGS__ +// _MSVC_TRADITIONAL == 0 means new conformant preprocessor +// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor +# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) +# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +# endif // MSVC_TRADITIONAL -# if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -# endif +// Only do this if we're not using clang on Windows, which uses `diagnostic push` & `diagnostic pop` +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) ) +# endif // __clang__ -// - otherwise more recent versions define __cplusplus >= 201103L -// and will get picked up below +#endif // _MSC_VER -#endif // __GNUC__ +#if defined(_REENTRANT) || defined(_MSC_VER) +// Enable async processing, as -pthread is specified or no additional linking is required +# define CATCH_INTERNAL_CONFIG_USE_ASYNC +#endif // _MSC_VER //////////////////////////////////////////////////////////////////////////////// -// Visual C++ -#ifdef _MSC_VER - -#define CATCH_INTERNAL_CONFIG_WINDOWS_SEH - -#if (_MSC_VER >= 1600) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR -#endif - -#if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015)) -#define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -#define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS -#define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE -#define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS +// Check if we are compiled with -fno-exceptions or equivalent +#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) +# define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED #endif -#endif // _MSC_VER - //////////////////////////////////////////////////////////////////////////////// +// DJGPP +#ifdef __DJGPP__ +# define CATCH_INTERNAL_CONFIG_NO_WCHAR +#endif // __DJGPP__ -// Use variadic macros if the compiler supports them -#if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \ - ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \ - ( defined __GNUC__ && __GNUC__ >= 3 ) || \ - ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L ) - -#define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS - +//////////////////////////////////////////////////////////////////////////////// +// Embarcadero C++Build +#if defined(__BORLANDC__) + #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN #endif -// Use __COUNTER__ if the compiler supports it -#if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \ - ( defined __GNUC__ && ( __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3 )) ) || \ - ( defined __clang__ && __clang_major__ >= 3 ) - -#define CATCH_INTERNAL_CONFIG_COUNTER +//////////////////////////////////////////////////////////////////////////////// +// Use of __COUNTER__ is suppressed during code analysis in +// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly +// handled by it. +// Otherwise all supported compilers support COUNTER macro, +// but user still might want to turn it off +#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) + #define CATCH_INTERNAL_CONFIG_COUNTER #endif //////////////////////////////////////////////////////////////////////////////// -// C++ language feature support - -// catch all support for C++11 -#if defined(CATCH_CPP11_OR_GREATER) - -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -# endif -# ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -# endif +// RTX is a special version of Windows that is real time. +// This means that it is detected as Windows, but does not provide +// the same set of capabilities as real Windows does. +#if defined(UNDER_RTSS) || defined(RTX64_BUILD) + #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH + #define CATCH_INTERNAL_CONFIG_NO_ASYNC + #define CATCH_CONFIG_COLOUR_NONE +#endif -# ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS -# define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS -# endif +#if !defined(_GLIBCXX_USE_C99_MATH_TR1) +#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER +#endif -# ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM -# define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM -# endif +// Various stdlib support checks that require __has_include +#if defined(__has_include) + // Check if string_view is available and usable + #if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW + #endif + + // Check if optional is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if byte is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # include + # if defined(__cpp_lib_byte) && (__cpp_lib_byte > 0) + # define CATCH_INTERNAL_CONFIG_CPP17_BYTE + # endif + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if variant is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # if defined(__clang__) && (__clang_major__ < 8) + // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 + // fix should be in clang 8, workaround in libstdc++ 8.2 + # include + # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # define CATCH_CONFIG_NO_CPP17_VARIANT + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__clang__) && (__clang_major__ < 8) + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) +#endif // defined(__has_include) + +#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) +# define CATCH_CONFIG_COUNTER +#endif +#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH) +# define CATCH_CONFIG_WINDOWS_SEH +#endif +// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. +#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) +# define CATCH_CONFIG_POSIX_SIGNALS +#endif +// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. +#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) +# define CATCH_CONFIG_WCHAR +#endif -# ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE -# define CATCH_INTERNAL_CONFIG_CPP11_TUPLE -# endif +#if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) +# define CATCH_CONFIG_CPP11_TO_STRING +#endif -# ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS -# define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS -# endif +#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) +# define CATCH_CONFIG_CPP17_OPTIONAL +#endif -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) -# define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG -# endif +#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) +# define CATCH_CONFIG_CPP17_STRING_VIEW +#endif -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) -# define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE -# endif -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) -# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR -# endif -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) -# define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE -# endif -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) -# define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS -# endif +#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) +# define CATCH_CONFIG_CPP17_VARIANT +#endif -#endif // __cplusplus >= 201103L +#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) +# define CATCH_CONFIG_CPP17_BYTE +#endif -// Now set the actual defines based on the above + anything the user has configured -#if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_NULLPTR +#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) +# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_NOEXCEPT + +#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE) +# define CATCH_CONFIG_NEW_CAPTURE #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_GENERATED_METHODS + +#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +# define CATCH_CONFIG_DISABLE_EXCEPTIONS #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_NO_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_IS_ENUM + +#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) +# define CATCH_CONFIG_POLYFILL_ISNAN #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_TUPLE + +#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) +# define CATCH_CONFIG_USE_ASYNC #endif -#if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS) -# define CATCH_CONFIG_VARIADIC_MACROS + +#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE) +# define CATCH_CONFIG_ANDROID_LOGWRITE #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_LONG_LONG + +#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) +# define CATCH_CONFIG_GLOBAL_NEXTAFTER #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_OVERRIDE + +// Even if we do not think the compiler has that warning, we still have +// to provide a macro that can be used by the code. +#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_UNIQUE_PTR +#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION #endif -// Use of __COUNTER__ is suppressed if __JETBRAINS_IDE__ is #defined (meaning we're being parsed by a JetBrains IDE for -// analytics) because, at time of writing, __COUNTER__ is not properly handled by it. -// This does not affect compilation -#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) && !defined(__JETBRAINS_IDE__) -# define CATCH_CONFIG_COUNTER +#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_SHUFFLE +#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS #endif -# if defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_NO_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_TYPE_TRAITS -# endif -#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) -# define CATCH_CONFIG_WINDOWS_SEH +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS #endif -// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. -#if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) -# define CATCH_CONFIG_POSIX_SIGNALS +#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS #endif -#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS -# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS -# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS +// The goal of this macro is to avoid evaluation of the arguments, but +// still have the compiler warn on problems inside... +#if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) #endif -// noexcept support: -#if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT) -# define CATCH_NOEXCEPT noexcept -# define CATCH_NOEXCEPT_IS(x) noexcept(x) -#else -# define CATCH_NOEXCEPT throw() -# define CATCH_NOEXCEPT_IS(x) +#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#elif defined(__clang__) && (__clang_major__ < 5) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS #endif -// nullptr support -#ifdef CATCH_CONFIG_CPP11_NULLPTR -# define CATCH_NULL nullptr -#else -# define CATCH_NULL NULL +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS #endif -// override support -#ifdef CATCH_CONFIG_CPP11_OVERRIDE -# define CATCH_OVERRIDE override +#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +#define CATCH_TRY if ((true)) +#define CATCH_CATCH_ALL if ((false)) +#define CATCH_CATCH_ANON(type) if ((false)) #else -# define CATCH_OVERRIDE +#define CATCH_TRY try +#define CATCH_CATCH_ALL catch (...) +#define CATCH_CATCH_ANON(type) catch (type) #endif -// unique_ptr support -#ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR -# define CATCH_AUTO_PTR( T ) std::unique_ptr -#else -# define CATCH_AUTO_PTR( T ) std::auto_ptr +#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) +#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR #endif +// end catch_compiler_capabilities.h #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) #ifdef CATCH_CONFIG_COUNTER @@ -371,95 +473,48 @@ # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) #endif -#define INTERNAL_CATCH_STRINGIFY2( expr ) #expr -#define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr ) +#include +#include +#include -#include -#include +// We need a dummy global operator<< so we can bring it into Catch namespace later +struct Catch_global_namespace_dummy {}; +std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); namespace Catch { - struct IConfig; - struct CaseSensitive { enum Choice { Yes, No }; }; class NonCopyable { -#ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS NonCopyable( NonCopyable const& ) = delete; NonCopyable( NonCopyable && ) = delete; NonCopyable& operator = ( NonCopyable const& ) = delete; NonCopyable& operator = ( NonCopyable && ) = delete; -#else - NonCopyable( NonCopyable const& info ); - NonCopyable& operator = ( NonCopyable const& ); -#endif protected: - NonCopyable() {} + NonCopyable(); virtual ~NonCopyable(); }; - class SafeBool { - public: - typedef void (SafeBool::*type)() const; - - static type makeSafe( bool value ) { - return value ? &SafeBool::trueValue : 0; - } - private: - void trueValue() const {} - }; - - template - inline void deleteAll( ContainerT& container ) { - typename ContainerT::const_iterator it = container.begin(); - typename ContainerT::const_iterator itEnd = container.end(); - for(; it != itEnd; ++it ) - delete *it; - } - template - inline void deleteAllValues( AssociativeContainerT& container ) { - typename AssociativeContainerT::const_iterator it = container.begin(); - typename AssociativeContainerT::const_iterator itEnd = container.end(); - for(; it != itEnd; ++it ) - delete it->second; - } - - bool startsWith( std::string const& s, std::string const& prefix ); - bool startsWith( std::string const& s, char prefix ); - bool endsWith( std::string const& s, std::string const& suffix ); - bool endsWith( std::string const& s, char suffix ); - bool contains( std::string const& s, std::string const& infix ); - void toLowerInPlace( std::string& s ); - std::string toLower( std::string const& s ); - std::string trim( std::string const& str ); - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); - - struct pluralise { - pluralise( std::size_t count, std::string const& label ); - - friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); + struct SourceLineInfo { - std::size_t m_count; - std::string m_label; - }; + SourceLineInfo() = delete; + SourceLineInfo( char const* _file, std::size_t _line ) noexcept + : file( _file ), + line( _line ) + {} - struct SourceLineInfo { + SourceLineInfo( SourceLineInfo const& other ) = default; + SourceLineInfo& operator = ( SourceLineInfo const& ) = default; + SourceLineInfo( SourceLineInfo&& ) noexcept = default; + SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default; - SourceLineInfo(); - SourceLineInfo( char const* _file, std::size_t _line ); -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - SourceLineInfo(SourceLineInfo const& other) = default; - SourceLineInfo( SourceLineInfo && ) = default; - SourceLineInfo& operator = ( SourceLineInfo const& ) = default; - SourceLineInfo& operator = ( SourceLineInfo && ) = default; -# endif - bool empty() const; - bool operator == ( SourceLineInfo const& other ) const; - bool operator < ( SourceLineInfo const& other ) const; + bool empty() const noexcept { return file[0] == '\0'; } + bool operator == ( SourceLineInfo const& other ) const noexcept; + bool operator < ( SourceLineInfo const& other ) const noexcept; char const* file; std::size_t line; @@ -467,24 +522,17 @@ namespace Catch { std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); - // This is just here to avoid compiler warnings with macro constants and boolean literals - inline bool isTrue( bool value ){ return value; } - inline bool alwaysTrue() { return true; } - inline bool alwaysFalse() { return false; } - - void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ); - - void seedRng( IConfig const& config ); - unsigned int rngSeed(); + // Bring in operator<< from global namespace into Catch namespace + // This is necessary because the overload of operator<< above makes + // lookup stop at namespace Catch + using ::operator<<; // Use this in variadic streaming macros to allow // >> +StreamEndStop // as well as // >> stuff +StreamEndStop struct StreamEndStop { - std::string operator+() { - return std::string(); - } + std::string operator+() const; }; template T const& operator + ( T const& value, StreamEndStop ) { @@ -492,364 +540,812 @@ namespace Catch { } } -#define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) -#define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO ); +#define CATCH_INTERNAL_LINEINFO \ + ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) +// end catch_common.h namespace Catch { - class NotImplementedException : public std::exception - { - public: - NotImplementedException( SourceLineInfo const& lineInfo ); - NotImplementedException( NotImplementedException const& ) {} - - virtual ~NotImplementedException() CATCH_NOEXCEPT {} - - virtual const char* what() const CATCH_NOEXCEPT; - - private: - std::string m_what; - SourceLineInfo m_lineInfo; + struct RegistrarForTagAliases { + RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); }; } // end namespace Catch -/////////////////////////////////////////////////////////////////////////////// -#define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO ) +#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION -// #included from: internal/catch_context.h -#define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED +// end catch_tag_alias_autoregistrar.h +// start catch_test_registry.h -// #included from: catch_interfaces_generators.h -#define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED +// start catch_interfaces_testcase.h -#include +#include namespace Catch { - struct IGeneratorInfo { - virtual ~IGeneratorInfo(); - virtual bool moveNext() = 0; - virtual std::size_t getCurrentIndex() const = 0; + class TestSpec; + + struct ITestInvoker { + virtual void invoke () const = 0; + virtual ~ITestInvoker(); }; - struct IGeneratorsForTest { - virtual ~IGeneratorsForTest(); + class TestCase; + struct IConfig; - virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0; - virtual bool moveNext() = 0; + struct ITestCaseRegistry { + virtual ~ITestCaseRegistry(); + virtual std::vector const& getAllTests() const = 0; + virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; }; - IGeneratorsForTest* createGeneratorsForTest(); + bool isThrowSafe( TestCase const& testCase, IConfig const& config ); + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); -} // end namespace Catch +} -// #included from: catch_ptr.hpp -#define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED +// end catch_interfaces_testcase.h +// start catch_stringref.h -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif +#include +#include +#include +#include namespace Catch { - // An intrusive reference counting smart pointer. - // T must implement addRef() and release() methods - // typically implementing the IShared interface - template - class Ptr { + /// A non-owning string class (similar to the forthcoming std::string_view) + /// Note that, because a StringRef may be a substring of another string, + /// it may not be null terminated. + class StringRef { public: - Ptr() : m_p( CATCH_NULL ){} - Ptr( T* p ) : m_p( p ){ - if( m_p ) - m_p->addRef(); - } - Ptr( Ptr const& other ) : m_p( other.m_p ){ - if( m_p ) - m_p->addRef(); - } - ~Ptr(){ - if( m_p ) - m_p->release(); - } - void reset() { - if( m_p ) - m_p->release(); - m_p = CATCH_NULL; - } - Ptr& operator = ( T* p ){ - Ptr temp( p ); - swap( temp ); - return *this; - } - Ptr& operator = ( Ptr const& other ){ - Ptr temp( other ); - swap( temp ); - return *this; - } - void swap( Ptr& other ) { std::swap( m_p, other.m_p ); } - T* get() const{ return m_p; } - T& operator*() const { return *m_p; } - T* operator->() const { return m_p; } - bool operator !() const { return m_p == CATCH_NULL; } - operator SafeBool::type() const { return SafeBool::makeSafe( m_p != CATCH_NULL ); } + using size_type = std::size_t; + using const_iterator = const char*; private: - T* m_p; - }; + static constexpr char const* const s_empty = ""; - struct IShared : NonCopyable { - virtual ~IShared(); - virtual void addRef() const = 0; - virtual void release() const = 0; - }; + char const* m_start = s_empty; + size_type m_size = 0; + + public: // construction + constexpr StringRef() noexcept = default; - template - struct SharedImpl : T { + StringRef( char const* rawChars ) noexcept; + + constexpr StringRef( char const* rawChars, size_type size ) noexcept + : m_start( rawChars ), + m_size( size ) + {} - SharedImpl() : m_rc( 0 ){} + StringRef( std::string const& stdString ) noexcept + : m_start( stdString.c_str() ), + m_size( stdString.size() ) + {} - virtual void addRef() const { - ++m_rc; + explicit operator std::string() const { + return std::string(m_start, m_size); } - virtual void release() const { - if( --m_rc == 0 ) - delete this; + + public: // operators + auto operator == ( StringRef const& other ) const noexcept -> bool; + auto operator != (StringRef const& other) const noexcept -> bool { + return !(*this == other); } - mutable unsigned int m_rc; - }; + auto operator[] ( size_type index ) const noexcept -> char { + assert(index < m_size); + return m_start[index]; + } -} // end namespace Catch + public: // named queries + constexpr auto empty() const noexcept -> bool { + return m_size == 0; + } + constexpr auto size() const noexcept -> size_type { + return m_size; + } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif + // Returns the current start pointer. If the StringRef is not + // null-terminated, throws std::domain_exception + auto c_str() const -> char const*; -namespace Catch { + public: // substrings and searches + // Returns a substring of [start, start + length). + // If start + length > size(), then the substring is [start, size()). + // If start > size(), then the substring is empty. + auto substr( size_type start, size_type length ) const noexcept -> StringRef; - class TestCase; - class Stream; - struct IResultCapture; - struct IRunner; - struct IGeneratorsForTest; - struct IConfig; + // Returns the current start pointer. May not be null-terminated. + auto data() const noexcept -> char const*; - struct IContext - { - virtual ~IContext(); + constexpr auto isNullTerminated() const noexcept -> bool { + return m_start[m_size] == '\0'; + } - virtual IResultCapture* getResultCapture() = 0; - virtual IRunner* getRunner() = 0; - virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0; - virtual bool advanceGeneratorsForCurrentTest() = 0; - virtual Ptr getConfig() const = 0; + public: // iterators + constexpr const_iterator begin() const { return m_start; } + constexpr const_iterator end() const { return m_start + m_size; } }; - struct IMutableContext : IContext - { - virtual ~IMutableContext(); - virtual void setResultCapture( IResultCapture* resultCapture ) = 0; - virtual void setRunner( IRunner* runner ) = 0; - virtual void setConfig( Ptr const& config ) = 0; - }; + auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; + auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; - IContext& getCurrentContext(); - IMutableContext& getCurrentMutableContext(); - void cleanUpContext(); - Stream createStream( std::string const& streamName ); + constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { + return StringRef( rawChars, size ); + } +} // namespace Catch +constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { + return Catch::StringRef( rawChars, size ); } -// #included from: internal/catch_test_registry.hpp -#define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED +// end catch_stringref.h +// start catch_preprocessor.hpp -// #included from: catch_interfaces_testcase.h -#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED -#include +#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ +#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__))) -namespace Catch { +#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__ +// MSVC needs more evaluations +#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__))) +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__)) +#else +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__) +#endif - class TestSpec; +#define CATCH_REC_END(...) +#define CATCH_REC_OUT + +#define CATCH_EMPTY() +#define CATCH_DEFER(id) id CATCH_EMPTY() + +#define CATCH_REC_GET_END2() 0, CATCH_REC_END +#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2 +#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1 +#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT +#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0) +#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next) + +#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) + +#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) + +// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results, +// and passes userdata as the first parameter to each invocation, +// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c) +#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param) +#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__ +#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__ +#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) +#else +// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) +#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) +#endif - struct ITestCase : IShared { - virtual void invoke () const = 0; - protected: - virtual ~ITestCase(); - }; +#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__ +#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) - class TestCase; - struct IConfig; +#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__) - struct ITestCaseRegistry { - virtual ~ITestCaseRegistry(); - virtual std::vector const& getAllTests() const = 0; - virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper()) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) +#else +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper())) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) +#endif + +#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\ + CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__) + +#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0) +#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1) +#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2) +#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3) +#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4) +#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5) +#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _3, _4, _5, _6) +#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7) +#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8) +#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9) +#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) + +#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N + +#define INTERNAL_CATCH_TYPE_GEN\ + template struct TypeList {};\ + template\ + constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\ + template class...> struct TemplateTypeList{};\ + template class...Cs>\ + constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\ + template\ + struct append;\ + template\ + struct rewrap;\ + template class, typename...>\ + struct create;\ + template class, typename>\ + struct convert;\ + \ + template \ + struct append { using type = T; };\ + template< template class L1, typename...E1, template class L2, typename...E2, typename...Rest>\ + struct append, L2, Rest...> { using type = typename append, Rest...>::type; };\ + template< template class L1, typename...E1, typename...Rest>\ + struct append, TypeList, Rest...> { using type = L1; };\ + \ + template< template class Container, template class List, typename...elems>\ + struct rewrap, List> { using type = TypeList>; };\ + template< template class Container, template class List, class...Elems, typename...Elements>\ + struct rewrap, List, Elements...> { using type = typename append>, typename rewrap, Elements...>::type>::type; };\ + \ + template