|
| 1 | +//! Configuration for skipping individual test cases (inputs) rather than ignoring entire tests. |
| 2 | +//! |
| 3 | +//! One common case here is that our NaNs usually have the sign bit set (platform dependent), |
| 4 | +//! while MPFR seems to put meaning on the signedness of NaNs and zeros. |
| 5 | +
|
| 6 | +#![allow(unused)] |
| 7 | +use crate::{CheckBasis, CheckCtx, Float, Int}; |
| 8 | + |
| 9 | +/// Type implementing [`IgnoreCase`]. |
| 10 | +pub struct XFail; |
| 11 | + |
| 12 | +/// If the relevant function returns true, the input has a mismatch but should still be skipped. |
| 13 | +/// |
| 14 | +/// This gets implemented once per input type, then the functions provide further filtering |
| 15 | +/// based on function name and values. |
| 16 | +pub trait IgnoreCase<Input> { |
| 17 | + fn xfail_float<F: Float>(_input: Input, _actual: F, _expected: F, _ctx: &CheckCtx) -> bool { |
| 18 | + false |
| 19 | + } |
| 20 | + |
| 21 | + fn xfail_int<I: Int>(_input: Input, _actual: I, _expected: I, _ctx: &CheckCtx) -> bool { |
| 22 | + false |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +impl IgnoreCase<(f32,)> for XFail { |
| 27 | + fn xfail_float<F: Float>(input: (f32,), actual: F, expected: F, ctx: &CheckCtx) -> bool { |
| 28 | + match &ctx.basis { |
| 29 | + CheckBasis::Musl => match ctx.fname { |
| 30 | + // We return +NaN, Musl returns -NaN |
| 31 | + "tgammaf" => input.0 < 0.0, |
| 32 | + _ => false, |
| 33 | + }, |
| 34 | + CheckBasis::MultiPrecision => match ctx.fname { |
| 35 | + // For almost everything we return -NaN but MPFR does +NaN |
| 36 | + _ if input.0.is_nan() && all_nan(&[actual, expected]) => true, |
| 37 | + // Out of domain we return +NaN, MPFR returns -NaN |
| 38 | + "atanhf" => input.0 < -1.0 && all_nan(&[actual, expected]), |
| 39 | + // We return -NaN, MPFR says +NaN |
| 40 | + "tgammaf" => input.0 < 0.0 && all_nan(&[actual, expected]), |
| 41 | + _ => false, |
| 42 | + }, |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + fn xfail_int<I: Int>(input: (f32,), actual: I, expected: I, ctx: &CheckCtx) -> bool { |
| 47 | + match &ctx.basis { |
| 48 | + CheckBasis::Musl => false, |
| 49 | + CheckBasis::MultiPrecision => match ctx.fname { |
| 50 | + // We set -1, MPFR sets +1 |
| 51 | + "lgammaf_r" => input.0 == f32::NEG_INFINITY && actual.abs() == expected.abs(), |
| 52 | + _ => false, |
| 53 | + }, |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +impl IgnoreCase<(f64,)> for XFail { |
| 59 | + fn xfail_float<F: Float>(input: (f64,), actual: F, expected: F, ctx: &CheckCtx) -> bool { |
| 60 | + // See the `f32` version for notes about what is skipped |
| 61 | + match &ctx.basis { |
| 62 | + CheckBasis::Musl => match ctx.fname { |
| 63 | + "tgamma" => input.0 < 0.0, |
| 64 | + _ => false, |
| 65 | + }, |
| 66 | + CheckBasis::MultiPrecision => match ctx.fname { |
| 67 | + _ if input.0.is_nan() && all_nan(&[actual, expected]) => true, |
| 68 | + "atanh" => input.0 < -1.0 && all_nan(&[actual, expected]), |
| 69 | + "tgamma" => input.0 < 0.0 && all_nan(&[actual, expected]), |
| 70 | + _ => false, |
| 71 | + }, |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + fn xfail_int<I: Int>(input: (f64,), actual: I, expected: I, ctx: &CheckCtx) -> bool { |
| 76 | + // See the `f32` version for notes about what is skipped |
| 77 | + match &ctx.basis { |
| 78 | + CheckBasis::Musl => false, |
| 79 | + CheckBasis::MultiPrecision => match ctx.fname { |
| 80 | + "lgamma_r" => input.0 == f64::NEG_INFINITY && actual.abs() == expected.abs(), |
| 81 | + _ => false, |
| 82 | + }, |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +impl IgnoreCase<(f32, f32)> for XFail { |
| 88 | + fn xfail_float<F: Float>(input: (f32, f32), actual: F, expected: F, ctx: &CheckCtx) -> bool { |
| 89 | + match &ctx.basis { |
| 90 | + CheckBasis::Musl => false, |
| 91 | + CheckBasis::MultiPrecision => { |
| 92 | + all_nan(&[input.0, input.1]) && all_nan(&[actual, expected]) |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +impl IgnoreCase<(f64, f64)> for XFail { |
| 99 | + fn xfail_float<F: Float>(input: (f64, f64), actual: F, expected: F, ctx: &CheckCtx) -> bool { |
| 100 | + match &ctx.basis { |
| 101 | + CheckBasis::Musl => false, |
| 102 | + CheckBasis::MultiPrecision => { |
| 103 | + all_nan(&[input.0, input.1]) && all_nan(&[actual, expected]) |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +impl IgnoreCase<(f32, f32, f32)> for XFail { |
| 110 | + fn xfail_float<F: Float>( |
| 111 | + input: (f32, f32, f32), |
| 112 | + actual: F, |
| 113 | + expected: F, |
| 114 | + ctx: &CheckCtx, |
| 115 | + ) -> bool { |
| 116 | + match &ctx.basis { |
| 117 | + CheckBasis::Musl => false, |
| 118 | + CheckBasis::MultiPrecision => { |
| 119 | + all_nan(&[input.0, input.1, input.2]) && all_nan(&[actual, expected]) |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | +} |
| 124 | +impl IgnoreCase<(f64, f64, f64)> for XFail { |
| 125 | + fn xfail_float<F: Float>( |
| 126 | + input: (f64, f64, f64), |
| 127 | + actual: F, |
| 128 | + expected: F, |
| 129 | + ctx: &CheckCtx, |
| 130 | + ) -> bool { |
| 131 | + match &ctx.basis { |
| 132 | + CheckBasis::Musl => false, |
| 133 | + CheckBasis::MultiPrecision => { |
| 134 | + all_nan(&[input.0, input.1, input.2]) && all_nan(&[actual, expected]) |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | +} |
| 139 | + |
| 140 | +impl IgnoreCase<(i32, f32)> for XFail { |
| 141 | + fn xfail_float<F: Float>(input: (i32, f32), actual: F, expected: F, ctx: &CheckCtx) -> bool { |
| 142 | + match &ctx.basis { |
| 143 | + CheckBasis::Musl => false, |
| 144 | + CheckBasis::MultiPrecision => match ctx.fname { |
| 145 | + _ if input.1.is_nan() && all_nan(&[actual, expected]) => true, |
| 146 | + // We return +0.0, MPFR returns -0.0 |
| 147 | + "jnf" => input.1 == f32::NEG_INFINITY && actual == F::ZERO && expected == F::ZERO, |
| 148 | + _ => false, |
| 149 | + }, |
| 150 | + } |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +impl IgnoreCase<(i32, f64)> for XFail { |
| 155 | + fn xfail_float<F: Float>(input: (i32, f64), actual: F, expected: F, ctx: &CheckCtx) -> bool { |
| 156 | + match &ctx.basis { |
| 157 | + CheckBasis::Musl => false, |
| 158 | + CheckBasis::MultiPrecision => match ctx.fname { |
| 159 | + _ if input.1.is_nan() && all_nan(&[actual, expected]) => true, |
| 160 | + "jn" => input.1 == f64::NEG_INFINITY && actual == F::ZERO && expected == F::ZERO, |
| 161 | + _ => false, |
| 162 | + }, |
| 163 | + } |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | +impl IgnoreCase<(f32, i32)> for XFail {} |
| 168 | +impl IgnoreCase<(f64, i32)> for XFail {} |
| 169 | + |
| 170 | +/// Convenience to check if all values are NaN |
| 171 | +fn all_nan<F: Float>(v1: &[F]) -> bool { |
| 172 | + v1.iter().all(|v| v.is_nan()) |
| 173 | +} |
0 commit comments