gh-1076: Use array comparison functions from array-api-extra#1083
gh-1076: Use array comparison functions from array-api-extra#1083paddyroddy wants to merge 24 commits into
array-api-extra#1083Conversation
| from tests.fixtures.helper_classes import Compare | ||
|
|
There was a problem hiding this comment.
Here and everywhere else, we can call xp_assert... inside the class itself, so compare.assert_allclose works but internally calls xp_assert_close. This would help avoid changing lines everywhere.
There was a problem hiding this comment.
Yes but the Compare class was always a hack so I'd rather to the big changes once
| old = healpix.ang2pix(healpix_inputs.nside, thetas, phis, lonlat=lonlat) | ||
| new = hp.ang2pix(healpix_inputs.nside, thetas, phis, lonlat=lonlat, xp=xp) | ||
| compare.assert_array_equal(old, new) | ||
| xp_assert_equal(xp.asarray(old), new) |
There was a problem hiding this comment.
Here and everywhere else, instead of changing it everywhere, you can modify the compare class functions first to convert a Python scalar or list into an array, then call the array api extra function with these inputs. See here for example (done in this SciPy PR):
def _convert_scalar_to_array(x, xp):
if isinstance(x, (list, tuple)) or type(x) in (
int,
float,
complex,
bool,
):
return xp.asarray(x)
return x
def xp_assert_close(actual, desired, *, rtol=None, atol=0, check_dtype=True,
check_shape=True, check_0d=False, err_msg='', xp=None):There was a problem hiding this comment.
I feel if we did this then we could have just stuck with our initial implementation
There was a problem hiding this comment.
the advantage of converting array-likes to arrays is that you gain the strictness of checking that the return namespace is what you expect
| assert j is None | ||
| assert a.shape == (0,) | ||
| compare.assert_allclose(xpb.asarray(s), 1.0) | ||
| xp_assert_close(s, xpb.ones_like(s)) |
There was a problem hiding this comment.
the check_shape=False parameter should be an alternative here
| old = healpix.ang2pix(healpix_inputs.nside, thetas, phis, lonlat=lonlat) | ||
| new = hp.ang2pix(healpix_inputs.nside, thetas, phis, lonlat=lonlat, xp=xp) | ||
| compare.assert_array_equal(old, new) | ||
| xp_assert_equal(xp.asarray(old), new) |
There was a problem hiding this comment.
the advantage of converting array-likes to arrays is that you gain the strictness of checking that the return namespace is what you expect
|
public API is now available on array-api-extra |
Description
As can be seen in scipy/scipy#25143 and scikit-learn/scikit-learn#34019,
array-api-extranow provides array comparison methods. This means we should be able to remove our customComparehelper class.Closes: #1076
Checks