-
Notifications
You must be signed in to change notification settings - Fork 10
ENH: new function isclose
#113
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please could you read through the discussion at data-apis/array-api#170 and let me know how this PR stands in relation to that?
This is 1:1 what numpy, cupy, tensorflow, pytorch, jax and dask already implement.
The RFC is right to point out though that |
isclose
and allclose
isclose
|
||
if xp.isdtype(a.dtype, "bool") or xp.isdtype(b.dtype, "bool"): | ||
if atol >= 1 or rtol >= 1: | ||
return xp.ones_like(a == b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On eager backends, this is less performant than
return xp.ones(xp.broadcast_arrays(a, b)[0], dtype=bool, device=a.device)
but it supports backends with NaN shapes like Dask.
Both jax.jit and dask with non-NaN shape should elide the comparison away.
desired_shape = desired.compute().shape | ||
|
||
msg = f"shapes do not match: {actual_shape} != f{desired_shape}" | ||
assert actual_shape == desired_shape, msg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will have to be replicated on the scipy PR for dask support
That seems like the right choice to me for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks fantastic as usual, thanks! I'll push some tweaks now.
happy to merge once unresolved comments are addressed |
all done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
No description provided.