Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 577310c

Browse files
committed
Replace HasDomain with a dynamic call that supports multiple arguments
This also allows reusing the same generator logic between logspace tests and extensive tests, so comes with a nice bit of cleanup. Changes: * Make the generator part of `CheckCtx` since a `Generator` and `CheckCtx` are almost always passed together. * Rename `domain_logspace` to `spaced` since this no longer only operates within a domain and we may want to handle integer spacing. * Domain is now calculated at runtime rather than using traits, which is much easier to work with. * With the above, domains for multidimensional functions are added. * The extensive test generator code tests has been combined with the domain_logspace generator code. With this, the domain tests have just become a subset of extensive tests. These were renamed to "quickspace" since, technically, the extensive tests are also "domain" or "domain logspace" tests. * Edge case generators now handle functions with multiple inputs. * The test runners can be significantly cleaned up and deduplicated.
1 parent b8005ac commit 577310c

File tree

12 files changed

+509
-503
lines changed

12 files changed

+509
-503
lines changed

crates/libm-test/benches/random.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::time::Duration;
44
use criterion::{Criterion, criterion_main};
55
use libm_test::gen::random;
66
use libm_test::gen::random::RandomInput;
7-
use libm_test::{CheckBasis, CheckCtx, MathOp, TupleCall};
7+
use libm_test::{CheckBasis, CheckCtx, GeneratorKind, MathOp, TupleCall};
88

99
/// Benchmark with this many items to get a variety
1010
const BENCH_ITER_ITEMS: usize = if cfg!(feature = "short-benchmarks") { 50 } else { 500 };
@@ -52,7 +52,7 @@ where
5252
{
5353
let name = Op::NAME;
5454

55-
let ctx = CheckCtx::new(Op::IDENTIFIER, CheckBasis::Musl);
55+
let ctx = CheckCtx::new(Op::IDENTIFIER, CheckBasis::Musl, GeneratorKind::Random);
5656
let benchvec: Vec<_> =
5757
random::get_test_cases::<Op::RustArgs>(&ctx).take(BENCH_ITER_ITEMS).collect();
5858

crates/libm-test/examples/plot_domains.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use std::path::Path;
1212
use std::process::Command;
1313
use std::{env, fs};
1414

15-
use libm_test::domain::HasDomain;
16-
use libm_test::gen::{domain_logspace, edge_cases};
17-
use libm_test::{CheckBasis, CheckCtx, MathOp, op};
15+
use libm_test::gen::spaced::SpacedInput;
16+
use libm_test::gen::{edge_cases, spaced};
17+
use libm_test::{CheckBasis, CheckCtx, GeneratorKind, MathOp, op};
1818

1919
const JL_PLOT: &str = "examples/plot_file.jl";
2020

@@ -52,23 +52,13 @@ fn main() {
5252
/// Run multiple generators for a single operator.
5353
fn plot_one_operator<Op>(out_dir: &Path, config: &mut String)
5454
where
55-
Op: MathOp<FTy = f32> + HasDomain<f32>,
55+
Op: MathOp<FTy = f32, RustArgs = (f32,)>,
56+
Op::RustArgs: SpacedInput<Op>,
5657
{
57-
let ctx = CheckCtx::new(Op::IDENTIFIER, CheckBasis::Mpfr);
58-
plot_one_generator(
59-
out_dir,
60-
&ctx,
61-
"logspace",
62-
config,
63-
domain_logspace::get_test_cases::<Op>(&ctx),
64-
);
65-
plot_one_generator(
66-
out_dir,
67-
&ctx,
68-
"edge_cases",
69-
config,
70-
edge_cases::get_test_cases::<Op, _>(&ctx),
71-
);
58+
let mut ctx = CheckCtx::new(Op::IDENTIFIER, CheckBasis::Mpfr, GeneratorKind::QuickSpaced);
59+
plot_one_generator(out_dir, &ctx, "logspace", config, spaced::get_test_cases::<Op>(&ctx).0);
60+
ctx.gen_kind = GeneratorKind::EdgeCases;
61+
plot_one_generator(out_dir, &ctx, "edge_cases", config, edge_cases::get_test_cases::<Op>(&ctx));
7262
}
7363

7464
/// Plot the output of a single generator.

0 commit comments

Comments
 (0)