From eda3748a197dff5234152fa1fb52e6ed2d11ea49 Mon Sep 17 00:00:00 2001 From: Lucas Chollet Date: Thu, 1 Oct 2026 13:02:11 +0200 Subject: [PATCH] CompareAKMathAgainstMPFR: Use all CORE-MATH test cases by default And provide a flag to sample only N test cases from the list. --- .../Tools/CompareAKMathAgainstMPFR/main.cpp | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Meta/Lagom/Tools/CompareAKMathAgainstMPFR/main.cpp b/Meta/Lagom/Tools/CompareAKMathAgainstMPFR/main.cpp index df3ae19ab82..04379693bdd 100644 --- a/Meta/Lagom/Tools/CompareAKMathAgainstMPFR/main.cpp +++ b/Meta/Lagom/Tools/CompareAKMathAgainstMPFR/main.cpp @@ -46,6 +46,7 @@ struct Options { bool verbose = false; Optional accepted_range {}; Optional core_math_path {}; + Optional sample_core_math {}; Optional filter {}; }; @@ -204,17 +205,17 @@ Vector load_worst_cases(Options const& options, MathFunction const& func return result.release_value(); } -Vector sample_worst_cases(Vector worst_cases) +Vector sample_worst_cases(Options const& options, Vector worst_cases) { - // FIXME: This should be a runtime option. - static constexpr u32 TEST_SAMPLES = 1000; + if (!options.sample_core_math.has_value()) + return worst_cases; - auto number_of_sampled_cases = min(worst_cases.size(), TEST_SAMPLES); + auto number_of_sampled_cases = min(worst_cases.size(), *options.sample_core_math); Vector out; out.ensure_capacity(number_of_sampled_cases); - auto step = max(1, static_cast(worst_cases.size()) / TEST_SAMPLES); + auto step = max(1, static_cast(worst_cases.size()) / *options.sample_core_math); for (u32 i = 0; i < number_of_sampled_cases; ++i) out.unchecked_append(worst_cases[static_cast(i * step)]); @@ -250,7 +251,7 @@ Vector adjust_ranges(Options const& options, ReadonlySpan ranges) Vector generate_test_cases(Options const& options, MathFunction const& function) { auto all_worst_cases = load_worst_cases(options, function); - auto worst_cases = sample_worst_cases(move(all_worst_cases)); + auto worst_cases = sample_worst_cases(options, move(all_worst_cases)); auto filtered_edge_cases = filter_edge_cases(options, g_edge_cases); auto adjusted_test_ranges = adjust_ranges(options, function.test_ranges); @@ -399,6 +400,7 @@ ErrorOr serenity_main(Main::Arguments arguments) Optional range {}; parser.add_option(options.test_system_libm, "Test the system's libm instead of AK's math functions.", "test-system-libm"); parser.add_option(options.core_math_path, "Path to CORE-MATH root folder, used to extract hard-to-round cases", "core-math", 0, "PATH"); + parser.add_option(options.sample_core_math, "Only use N samples from CORE-MATH", "sample-core-math", 0, "N"); parser.add_option(options.filter, "Only test math functions whose names include FILTER", "filter", 'f', "FILTER"); parser.add_option(range, "Only test math function inside the given range. RANGE should have the following shape \"min:max\"", "range", 'r', "RANGE"); parser.add_option(options.wide, "Use wide formatting", "format-wide"); @@ -409,6 +411,9 @@ ErrorOr serenity_main(Main::Arguments arguments) warnln("Warning: CORE-MATH is not provided."); warnln("Please use the --core-math option to provide more test cases."); warnln("CORE-MATH can be downloaded from https://gitlab.inria.fr/core-math/core-math/"); + + if (options.sample_core_math.has_value()) + return Error::from_string_literal("Invalid argument: --sample-core-math used without --core-math"); } if (range.has_value()) { @@ -433,7 +438,12 @@ ErrorOr serenity_main(Main::Arguments arguments) // FIXME: Print values using the scientific notation. out(", with values limited to [{}, {}]", options.accepted_range->min, options.accepted_range->max); } - outln("...\n"); + outln("..."); + + if (options.sample_core_math.has_value()) + outln("Only using {} cases from CORE-MATH worst cases.", *options.sample_core_math); + + outln(); u32 w = options.wide ? 22 : 10; // width for Max ULP column u32 w2 = options.wide ? 24 : 12; // width for Mean ULP column