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

Commit 70d9e16

Browse files
committed
Use CheckCtx in more places
Rather than passing names or identifiers, just pass `CheckCtx` in a few more places.
1 parent 18161fd commit 70d9e16

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

crates/libm-test/examples/plot_domains.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{env, fs};
1414

1515
use libm_test::domain::HasDomain;
1616
use libm_test::gen::{domain_logspace, edge_cases};
17-
use libm_test::{MathOp, op};
17+
use libm_test::{CheckBasis, CheckCtx, MathOp, op};
1818

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

@@ -54,30 +54,32 @@ fn plot_one_operator<Op>(out_dir: &Path, config: &mut String)
5454
where
5555
Op: MathOp<FTy = f32> + HasDomain<f32>,
5656
{
57+
let ctx = CheckCtx::new(Op::IDENTIFIER, CheckBasis::Mpfr);
5758
plot_one_generator(
5859
out_dir,
59-
Op::BASE_NAME.as_str(),
60+
&ctx,
6061
"logspace",
6162
config,
62-
domain_logspace::get_test_cases::<Op>(),
63+
domain_logspace::get_test_cases::<Op>(&ctx),
6364
);
6465
plot_one_generator(
6566
out_dir,
66-
Op::BASE_NAME.as_str(),
67+
&ctx,
6768
"edge_cases",
6869
config,
69-
edge_cases::get_test_cases::<Op, _>(),
70+
edge_cases::get_test_cases::<Op, _>(&ctx),
7071
);
7172
}
7273

7374
/// Plot the output of a single generator.
7475
fn plot_one_generator(
7576
out_dir: &Path,
76-
fn_name: &str,
77+
ctx: &CheckCtx,
7778
gen_name: &str,
7879
config: &mut String,
7980
gen: impl Iterator<Item = (f32,)>,
8081
) {
82+
let fn_name = ctx.base_name_str;
8183
let text_file = out_dir.join(format!("input-{fn_name}-{gen_name}.txt"));
8284

8385
let f = fs::File::create(&text_file).unwrap();

crates/libm-test/src/gen/domain_logspace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use libm::support::{IntTy, MinInt};
44

55
use crate::domain::HasDomain;
66
use crate::op::OpITy;
7-
use crate::{MathOp, logspace};
7+
use crate::{CheckCtx, MathOp, logspace};
88

99
/// Number of tests to run.
1010
// FIXME(ntests): replace this with a more logical algorithm
@@ -30,7 +30,7 @@ const NTESTS: usize = {
3030
///
3131
/// This allows us to get reasonably thorough coverage without wasting time on values that are
3232
/// NaN or out of range. Random tests will still cover values that are excluded here.
33-
pub fn get_test_cases<Op>() -> impl Iterator<Item = (Op::FTy,)>
33+
pub fn get_test_cases<Op>(_ctx: &CheckCtx) -> impl Iterator<Item = (Op::FTy,)>
3434
where
3535
Op: MathOp + HasDomain<Op::FTy>,
3636
IntTy<Op::FTy>: TryFrom<usize>,

crates/libm-test/src/gen/edge_cases.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use libm::support::Float;
44

55
use crate::domain::HasDomain;
6-
use crate::{FloatExt, MathOp};
6+
use crate::{CheckCtx, FloatExt, MathOp};
77

88
/// Number of values near an interesting point to check.
99
// FIXME(ntests): replace this with a more logical algorithm
@@ -14,7 +14,7 @@ const AROUND: usize = 100;
1414
const MAX_CHECK_POINTS: usize = 10;
1515

1616
/// Create a list of values around interesting points (infinities, zeroes, NaNs).
17-
pub fn get_test_cases<Op, F>() -> impl Iterator<Item = (F,)>
17+
pub fn get_test_cases<Op, F>(_ctx: &CheckCtx) -> impl Iterator<Item = (F,)>
1818
where
1919
Op: MathOp<FTy = F> + HasDomain<F>,
2020
F: Float,

crates/libm-test/tests/multiprecision.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,21 @@ macro_rules! mp_domain_tests {
8383
$(#[$meta])*
8484
fn [< mp_edge_case_ $fn_name >]() {
8585
type Op = libm_test::op::$fn_name::Routine;
86-
domain_test_runner::<Op>(edge_cases::get_test_cases::<Op, _>());
86+
domain_test_runner::<Op, _>(edge_cases::get_test_cases::<Op, _>);
8787
}
8888

8989
#[test]
9090
$(#[$meta])*
9191
fn [< mp_logspace_ $fn_name >]() {
9292
type Op = libm_test::op::$fn_name::Routine;
93-
domain_test_runner::<Op>(domain_logspace::get_test_cases::<Op>());
93+
domain_test_runner::<Op, _>(domain_logspace::get_test_cases::<Op>);
9494
}
9595
}
9696
};
9797
}
9898

9999
/// Test a single routine against domaine-aware inputs.
100-
fn domain_test_runner<Op>(cases: impl Iterator<Item = (Op::FTy,)>)
100+
fn domain_test_runner<Op, I>(gen: impl FnOnce(&CheckCtx) -> I)
101101
where
102102
// Complicated generics...
103103
// The operation must take a single float argument (unary only)
@@ -108,9 +108,11 @@ where
108108
Op: HasDomain<Op::FTy>,
109109
// The single float argument tuple must be able to call the `RustFn` and return `RustRet`
110110
(OpFTy<Op>,): TupleCall<OpRustFn<Op>, Output = OpRustRet<Op>>,
111+
I: Iterator<Item = (Op::FTy,)>,
111112
{
112113
let mut mp_vals = Op::new_mp();
113114
let ctx = CheckCtx::new(Op::IDENTIFIER, CheckBasis::Mpfr);
115+
let cases = gen(&ctx);
114116

115117
for input in cases {
116118
let mp_res = Op::run(&mut mp_vals, input);

0 commit comments

Comments
 (0)