Rename canonical_name to base_name

"Canonical" isn't really the right word here, update to "base".
This commit is contained in:
Trevor Gross
2024-10-30 13:45:53 -05:00
committed by Trevor Gross
parent 776db6e1cd
commit 5523607045
5 changed files with 27 additions and 26 deletions

View File

@@ -110,6 +110,7 @@ pub fn get_test_cases<RustArgs>(ctx: &CheckCtx) -> impl Iterator<Item = RustArgs
where
CachedInput: GenerateInput<RustArgs>,
{
let inputs = if ctx.fname == "jn" || ctx.fname == "jnf" { &TEST_CASES_JN } else { &TEST_CASES };
let inputs =
if ctx.fn_name == "jn" || ctx.fn_name == "jnf" { &TEST_CASES_JN } else { &TEST_CASES };
inputs.get_cases()
}

View File

@@ -18,7 +18,7 @@ include!(concat!(env!("OUT_DIR"), "/all_files.rs"));
/// Return the unsuffixed version of a function name; e.g. `abs` and `absf` both return `abs`,
/// `lgamma_r` and `lgammaf_r` both return `lgamma_r`.
pub fn canonical_name(name: &str) -> &str {
pub fn base_name(name: &str) -> &str {
let known_mappings = &[
("erff", "erf"),
("erf", "erf"),

View File

@@ -111,25 +111,25 @@ impl MaybeOverride<(f32,)> for SpecialCase {
ctx: &CheckCtx,
) -> Option<TestResult> {
if ctx.basis == CheckBasis::Musl {
if ctx.fname == "expm1f" && input.0 > 80.0 && actual.is_infinite() {
if ctx.fn_name == "expm1f" && input.0 > 80.0 && actual.is_infinite() {
// we return infinity but the number is representable
return XFAIL;
}
if ctx.fname == "sinhf" && input.0.abs() > 80.0 && actual.is_nan() {
if ctx.fn_name == "sinhf" && input.0.abs() > 80.0 && actual.is_nan() {
// we return some NaN that should be real values or infinite
// doesn't seem to happen on x86
return XFAIL;
}
}
if ctx.fname == "acoshf" && input.0 < -1.0 {
if ctx.fn_name == "acoshf" && input.0 < -1.0 {
// acoshf is undefined for x <= 1.0, but we return a random result at lower
// values.
return XFAIL;
}
if ctx.fname == "lgammaf" || ctx.fname == "lgammaf_r" && input.0 < 0.0 {
if ctx.fn_name == "lgammaf" || ctx.fn_name == "lgammaf_r" && input.0 < 0.0 {
// loggamma should not be defined for x < 0, yet we both return results
return XFAIL;
}
@@ -146,7 +146,7 @@ impl MaybeOverride<(f32,)> for SpecialCase {
// On MPFR for lgammaf_r, we set -1 as the integer result for negative infinity but MPFR
// sets +1
if ctx.basis == CheckBasis::Mpfr
&& ctx.fname == "lgammaf_r"
&& ctx.fn_name == "lgammaf_r"
&& input.0 == f32::NEG_INFINITY
&& actual.abs() == expected.abs()
{
@@ -166,13 +166,13 @@ impl MaybeOverride<(f64,)> for SpecialCase {
ctx: &CheckCtx,
) -> Option<TestResult> {
if ctx.basis == CheckBasis::Musl {
if cfg!(target_arch = "x86") && ctx.fname == "acosh" && input.0 < 1.0 {
if cfg!(target_arch = "x86") && ctx.fn_name == "acosh" && input.0 < 1.0 {
// The function is undefined, both implementations return random results
return SKIP;
}
if cfg!(x86_no_sse)
&& ctx.fname == "ceil"
&& ctx.fn_name == "ceil"
&& input.0 < 0.0
&& input.0 > -1.0
&& expected == F::ZERO
@@ -183,13 +183,13 @@ impl MaybeOverride<(f64,)> for SpecialCase {
}
}
if ctx.fname == "acosh" && input.0 < 1.0 {
if ctx.fn_name == "acosh" && input.0 < 1.0 {
// The function is undefined for the inputs, musl and our libm both return
// random results.
return XFAIL;
}
if ctx.fname == "lgamma" || ctx.fname == "lgamma_r" && input.0 < 0.0 {
if ctx.fn_name == "lgamma" || ctx.fn_name == "lgamma_r" && input.0 < 0.0 {
// loggamma should not be defined for x < 0, yet we both return results
return XFAIL;
}
@@ -206,7 +206,7 @@ impl MaybeOverride<(f64,)> for SpecialCase {
// On MPFR for lgamma_r, we set -1 as the integer result for negative infinity but MPFR
// sets +1
if ctx.basis == CheckBasis::Mpfr
&& ctx.fname == "lgamma_r"
&& ctx.fn_name == "lgamma_r"
&& input.0 == f64::NEG_INFINITY
&& actual.abs() == expected.abs()
{
@@ -219,7 +219,7 @@ impl MaybeOverride<(f64,)> for SpecialCase {
/// Check NaN bits if the function requires it
fn maybe_check_nan_bits<F: Float>(actual: F, expected: F, ctx: &CheckCtx) -> Option<TestResult> {
if !(ctx.canonical_name == "fabs" || ctx.canonical_name == "copysign") {
if !(ctx.base_name == "fabs" || ctx.base_name == "copysign") {
return None;
}
@@ -277,7 +277,7 @@ fn maybe_skip_binop_nan<F1: Float, F2: Float>(
) -> Option<TestResult> {
match ctx.basis {
CheckBasis::Musl => {
if (ctx.canonical_name == "fmax" || ctx.canonical_name == "fmin")
if (ctx.base_name == "fmax" || ctx.base_name == "fmin")
&& (input.0.is_nan() || input.1.is_nan())
&& expected.is_nan()
{
@@ -287,7 +287,7 @@ fn maybe_skip_binop_nan<F1: Float, F2: Float>(
}
}
CheckBasis::Mpfr => {
if ctx.canonical_name == "copysign" && input.1.is_nan() {
if ctx.base_name == "copysign" && input.1.is_nan() {
SKIP
} else {
None
@@ -308,7 +308,7 @@ impl MaybeOverride<(i32, f32)> for SpecialCase {
CheckBasis::Musl => bessel_prec_dropoff(input, ulp, ctx),
CheckBasis::Mpfr => {
// We return +0.0, MPFR returns -0.0
if ctx.fname == "jnf"
if ctx.fn_name == "jnf"
&& input.1 == f32::NEG_INFINITY
&& actual == F::ZERO
&& expected == F::ZERO
@@ -333,7 +333,7 @@ impl MaybeOverride<(i32, f64)> for SpecialCase {
CheckBasis::Musl => bessel_prec_dropoff(input, ulp, ctx),
CheckBasis::Mpfr => {
// We return +0.0, MPFR returns -0.0
if ctx.fname == "jn"
if ctx.fn_name == "jn"
&& input.1 == f64::NEG_INFINITY
&& actual == F::ZERO
&& expected == F::ZERO
@@ -353,7 +353,7 @@ fn bessel_prec_dropoff<F: Float>(
ulp: &mut u32,
ctx: &CheckCtx,
) -> Option<TestResult> {
if ctx.canonical_name == "jn" {
if ctx.base_name == "jn" {
if input.0 > 4000 {
return XFAIL;
} else if input.0 > 2000 {

View File

@@ -33,17 +33,17 @@ pub struct CheckCtx {
/// Allowed ULP deviation
pub ulp: u32,
/// Function name.
pub fname: &'static str,
pub fn_name: &'static str,
/// Return the unsuffixed version of the function name.
pub canonical_name: &'static str,
pub base_name: &'static str,
/// Source of truth for tests.
pub basis: CheckBasis,
}
impl CheckCtx {
pub fn new(ulp: u32, fname: &'static str, basis: CheckBasis) -> Self {
let canonical_fname = crate::canonical_name(fname);
Self { ulp, fname, canonical_name: canonical_fname, basis }
let base_name = crate::base_name(fname);
Self { ulp, fn_name: fname, base_name, basis }
}
}