Choose the scale operand
The reference is 1. The candidate returns 2. Their absolute difference is 1. With relative tolerance 1/2 and absolute tolerance 0, a check scaled by the reference allows only 1/2, so it rejects. Scale the same error by the candidate instead, and the threshold becomes 1. The check now accepts at equality.[5][6]
The error did not change. The rule did. Our declared contract is abs(candidate − reference) ≤ atol + rtol × abs(reference). The comparison on the right uses the magnitude of the chosen reference. Replacing that magnitude with abs(candidate) changes which values qualify.[5][6]
- Same error, different scale: For reference 1 and candidate 2, error 1 exceeds the reference threshold 1/2 but meets the candidate threshold 1.
Use the documented contract
NumPy documents this direction explicitly for isclose and allclose: the second argument supplies the relative scale. PyTorch documents the same role for other in isclose and allclose. Under our declared contract, the argument order is therefore candidate first, reference second. The documented rule is directional; directionality alone is not a library bug.[1][2][3][4]
We wrote ten finite scalar cases and their expected values before one standard-library execution. The program uses Fraction, so the displayed errors and thresholds are exact rational values. It imports neither NumPy nor PyTorch and does not test how a particular floating implementation rounds near a boundary.[5][7]
Read both directions
The reverse example matters too. With reference 2 and candidate 1, the reference threshold is 1 and accepts, while the candidate threshold is 1/2 and rejects. Candidate scaling does not always make a check looser. For nonnegative rtol, the difference between the two thresholds is rtol × (abs(candidate) − abs(reference)).[5][6]
The remaining cases show the limits of the claim. Nearby values can pass both checks, and farther values can fail both. Both zero values pass at a zero threshold. A nonzero candidate against a zero reference fails in our relative-only case. Absolute tolerance permits the separate 1/4 boundary case; setting relative tolerance to zero makes the two thresholds identical. Negative values still use magnitudes.[5][6]
Three of the ten designed cases change verdict; seven do not. These counts describe the fixture, not how often an existing benchmark gets this wrong. All ten expected-case checks and six separate selected parser refusals passed. The full output retains every case and control, including rejected negative tolerances, a float, a boolean, NaN text and a duplicate ID.[5][6]
- Direction can tighten too: For reference 2 and candidate 1, swapping the scale changes pass to fail.
All ten authored finite scalar cases. Both predicates compare the same error with an inclusive ≤ boundary.
| Authored case | Reference → candidate | rtol; atol | Absolute error | Reference threshold; verdict | Candidate threshold; verdict |
|---|---|---|---|---|---|
| Larger candidate | 1 → 2 | 1/2; 0 | 1 | 1/2; fail | 1; pass |
| Smaller candidate | 2 → 1 | 1/2; 0 | 1 | 1; pass | 1/2; fail |
| Nearby values | 4 → 5 | 1/2; 0 | 1 | 2; pass | 5/2; pass |
| Farther values | 1 → 4 | 1/2; 0 | 3 | 1/2; fail | 2; fail |
| Reference boundary | 2 → 3 | 1/2; 0 | 1 | 1; pass | 3/2; pass |
| Both zero | 0 → 0 | 1/2; 0 | 0 | 0; pass | 0; pass |
| Zero reference | 0 → 1 | 1/2; 0 | 1 | 0; fail | 1/2; fail |
| Absolute boundary | 0 → 1/4 | 1/2; 1/4 | 1/4 | 1/4; pass | 3/8; pass |
| Absolute only | 1 → 3/2 | 0; 1/2 | 1/2 | 1/2; pass | 1/2; pass |
| Negative values | -1 → -2 | 1/2; 0 | 1 | 1/2; fail | 1; pass |
- Exact fractions; rtol=1/2 is deliberately illustrative, not a recommended tolerance.
- The last two columns use different scale operands. They are two acceptance contracts, not two independent correctness oracles.
Keep the acceptance rule explicit
For a benchmark reward, write down the reference, operand order, tolerance values and inclusive boundary before evaluating a candidate. A symmetric or candidate-scaled rule can be a different intentional contract; it should not silently replace the chosen one. This small demonstration recommends no universal tolerance and makes no claim about an existing grader, GPU result, training improvement or performance.[5][1][3]
The original saved CPU execution completed on November 26, 2026 (UTC). This article reuses that exact result and its complete recorded outcomes; no new experiment was run for this release.[5][7]
Original technical credit belongs to the NumPy and PyTorch documentation contributors for the finite relative-tolerance definitions. Nodus authored the ten-case fixture and the standard-library Fraction demonstration.[1][2][3][4][5]
- Keep the reference and tolerance formula explicit alongside each benchmark verdict.
Sources
- NumPy isclose numpy.org
- NumPy allclose numpy.org
- PyTorch isclose docs.pytorch.org
- PyTorch allclose docs.pytorch.org
- MIT runnable proof and complete saved output data.nodus-compute.ai
- Complete result JSON data.nodus-compute.ai
- Original execution and saved-result provenance data.nodus-compute.ai
- Vector figure data.nodus-compute.ai
