← Back to Pull requests

Specialize eps(::IEEEFloat) #52087

Closed
unknown closed this pull request without merging on Dec 07, 2023 21:02 UTC
View on GitHub
unknown unknown commented on Nov 08, 2023 18:08 UTC
Author

eps(::IEEEFloat) can be made notably faster. I doubt this function appears in performance-critical places, but better is better and this new version is branch-free.

``julia-repl
julia> using BenchmarkTools

julia> x = randn(2^10);

julia> @btime map(eps,$x); # v1.9.1
2.067 μs (1 allocation: 8.12 KiB)

julia> @btime map(eps,$x); # this PR
613.095 ns (1 allocation: 8.12 KiB)
`

A couple probably-negligible caveats that arise from the use of floating point arithmetic in this implementation:

  • The previous version always returned Julia's canonical NaN when the result would be NaN. In this PR, the NaN payload depends on the payload behavior of the hardware and the input.

  • The result is vulnerable to flush-to-zero floating point environments, in which case subnormal results will be flushed to zero(T). The usability of a subnormal result amidst flushing mode is questionable, as is the well-posed-ness of eps's semantics in such a situation. Note that the existing implementation has this same vulnerability (due to ldexp), though only when the input to eps is normal and the result would be subnormal (only with an input of zero or a subnormal is a correct subnormal output produced, assuming the flushing occurs during arithmetic but not storage).
  • Canonicalizing NaN would require a simple ifelse` switch on the result, though I can't imagine we care. Guaranteeing a proper subnormal result in flush-to-zero mode may be more challenging (and may warrant a branch) and is only handled slightly more correctly by the preexisting implementation. I imagine that flushing breaks a lot more functions than just this one, anyway.

    Diff: 209 lines (+156 / -53) across 2 files Reviewer: mikmoore Review duration: 41934m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 209 lines diff across 2 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.320
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #52087"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.4% (MEDIUM) · Higher = larger blast radius
    36.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.4% · Safe to merge
    14.4%