Skip to content

checked_mean returns a rounding residue for deltas that cancel on Python < 3.12 because it uses plain sum() #772

Open

Description

@antonwolfy

dokimi/eval/finite_delta.py:68 checked_mean computes sum(values) / len(values). Before Python 3.12 sum() adds left to right without compensation, so for large values the partial sums round and a set that cancels exactly gives a residue: [1e307] * 6 + [-1e307] * 6 gives -2.079e290 on Python 3.11 (the value in the CI log of #770) and 0.0 on 3.12+ (compensated). The repo compare summary mean (sign_flip_summary) therefore differs by Python version, while the interval uses math.fsum. Reproduced here by running checked_mean with sum replaced by a left-to-right loop (no 3.11 interpreter on the host). Fix: use math.fsum for the finite case (after check_sum_range) and check the tests that compare against sum(...) / n.

Follow-up from the review of #770: https://github.com/intel/dokimi/actions/runs/43636172087/job/132577195767

Activity

  1. self-assigned this
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions