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

Type promotion rules for comparison operations #890

Open
crusaderky opened this issue Jan 29, 2025 · 1 comment
Open

Type promotion rules for comparison operations #890

crusaderky opened this issue Jan 29, 2025 · 1 comment

Comments

@crusaderky
Copy link

crusaderky commented Jan 29, 2025

The page on type promotion rules extensively discusses how arithmetic operations must work. However, it is not clear on how comparisons should behave.

xp.asarray(x, dtype=xp.int64) + xp.asarray(x, dtype=float64) is explicitly disallowed for evident reasons of ambiguity about the output precision. However, I can't think of any cases where __eq__, __gt__, etc. between the two can be ambiguous? Just need to state that inf and nan use the same rules as if both arguments were float.

The latest version of array-api-strict disallows these operations, resulting in unnecessarily cumbersome code.

@rgommers
Copy link
Member

However, I can't think of any cases where __eq__, __gt__, etc. between the two can be ambiguous?

That's not the only problem - it's simply not supported by all libraries. And if you look under the hood, these operators are still implemented as kernels with two operands of the same type only - and to get them to be the same type, one has to apply type promotion rules (which don't exist for mixed integer and floating-point arrays).

It is also technically possible for there to be integers that aren't exactly representable as floating-point numbers of a given precision, yielding questions about corner cases.

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

2 participants