Skip to content

Integer isclose can disagree with the tolerance equation #1002

Description

@Boulea7

On current main, the array-agnostic path gives two results that disagree with the displayed tolerance equation when using array_api_strict:

import array_api_extra as xpx
import array_api_strict as xp

def check(a, b, atol, rtol):
    return bool(xpx.isclose(xp.asarray(a, dtype=xp.int8),
                            xp.asarray(b, dtype=xp.int8),
                            atol=atol, rtol=rtol))

print(check(0, 100, 30, 1.0))  # False; 100 <= 30 + 100
print(check(15, 10, 0, 0.4))   # True; 5 > 0.4 * 10

The first result appears to come from integer overflow in the tolerance sum; the second from truncating 1/rtol to an integer. The Notes currently introduce the tolerance equation for floating-point values. For integer inputs, should the agnostic path compare exact integer differences against the supplied scalar tolerances, or follow NumPy-like floating evaluation (including rounding large int64/uint64 values)? That choice affects a fix that also preserves large-integer comparisons.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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