Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with test_clip #276

Open
asmeurer opened this issue Jun 26, 2024 · 2 comments
Open

Issues with test_clip #276

asmeurer opened this issue Jun 26, 2024 · 2 comments

Comments

@asmeurer
Copy link
Member

  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/Users/aaronmeurer/Documents/array-api-tests/array_api_tests/test_operators_and_elementwise_functions.py", line 1043, in test_clip
    |     assert out_val == expected, (
    | AssertionError: out[()]=0.0 but should be 4.0311033624323596e-209 [clip()]
    |   x[()]=0.0, min[()]=4.0311033624323596e-209, max[()]=1.0
    | assert 0.0 == 4.0311033624323596e-209
    | Falsifying example: test_clip(
    |     x=Array(0., dtype=array_api_strict.float32),
    |     data=data(...),
    | )
    | Draw 1 (min.shape, max.shape): ((), ())
    | Draw 2 (min): Array(4.03110336e-209, dtype=array_api_strict.float64)
    | Draw 3 (max): Array(1., dtype=array_api_strict.float32)
    | Draw 4 (kwargs): {'min': Array(4.03110336e-209, dtype=array_api_strict.float64),
    |  'max': Array(1., dtype=array_api_strict.float32)}
    | Explanation:
    |     These lines were always and only run by failing examples:
    |         /Users/aaronmeurer/Documents/array-api-strict/array_api_strict/_array_object.py:113
    |         /Users/aaronmeurer/Documents/array-api-tests/array_api_tests/test_operators_and_elementwise_functions.py:1046
    |         /Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.12/site-packages/numpy/core/arrayprint.py:1590
    +---------------- 2 ----------------
    | Traceback (most recent call last):
    |   File "/Users/aaronmeurer/Documents/array-api-tests/array_api_tests/test_operators_and_elementwise_functions.py", line 952, in test_clip
    |     assume(min is None or max is None or not xp.any(xp.asarray(min) > xp.asarray(max)))
    |                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/aaronmeurer/Documents/array-api-strict/array_api_strict/_array_object.py", line 641, in __gt__
    |     other = self._check_allowed_dtypes(other, "real numeric", "__gt__")
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/aaronmeurer/Documents/array-api-strict/array_api_strict/_array_object.py", line 179, in _check_allowed_dtypes
    |     res_dtype = _result_type(self.dtype, other.dtype)
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/aaronmeurer/Documents/array-api-strict/array_api_strict/_dtypes.py", line 217, in _result_type
    |     raise TypeError(f"{type1} and {type2} cannot be type promoted together")
    | TypeError: array_api_strict.int64 and array_api_strict.uint64 cannot be type promoted together
    | Falsifying example: test_clip(
    |     x=Array(0, dtype=array_api_strict.uint64),
    |     data=data(...),
    | )
    | Draw 1 (min.shape, max.shape): ((), ())
    | Draw 2 (min): 0
    | Draw 3 (max): 9223372036854775808
    | Explanation:
    |     These lines were always and only run by failing examples:
    |         /Users/aaronmeurer/Documents/array-api-strict/array_api_strict/_dtypes.py:217
    +------------------------------------
@asmeurer
Copy link
Member Author

The first thing is kind of a flaw in the standard decision to make x not promote. It means you don't actually have min <= x <= max when min or max are float64 and x is float32. The example here is an underflow but it can happen with virtually any sort of rounding. See numpy/numpy#24976

The second is an annoying corner case in the standard, where apparently you can't compare uint64 and int64 (or at least the strict library doesn't allow it). I wonder if there's a helper function already somewhere in the test suite that makes this easier.

@asmeurer
Copy link
Member Author

Actually for the comparison, we should avoid using Python integers that are larger than the bounds of x.dtype as the input. We should also probably avoid allowing int64 and uint64, even though there technically isn't a promotion, since libraries won't be able to do the proper comparisons we need for the test (it looks like the standard might be changed to not require this data-apis/array-api#819).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant