You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow testing methods to compare arrays of different backends #1005
could you link to the use-case? We used to have this in the versions that were in SciPy, but when taking a second look while switching to xpx.testing we decided it was cleaner to just always avoid this pattern.
I'd be happy to add this if the use-case is compelling.
So for our specific use case we are wanting to compare the outputs of an inverse spherical harmonic transform. Our current code has a wrapper around https://pypi.org/project/healpy and https://pypi.org/project/healpix, so that they can handle any array backend by internally converting to NumPy.
We would like to use https://pypi.org/project/s2fft to compute out spherical harmonic transforms natively in JAX, so that we never leave the GPU. So we can't do this in the classic Array API way, and would have to do an if xp.__name__ == "jax.numpy" pattern.
Regardless, it would be nice to use array-api-extra.testing.assert_equal to compare the output of the NumPy and JAX transform. I guess we could just use numpy.testing.assert_array_equal for that bit.
Do you have xp available at assertion time? The thinking is that check_backends=False is no more concise than wrapping the desired array with xp.asarray.
what I meant was having the test parametrised by xp, then you have alm_actual as the first param, and xp.asarray(alm_desired) as the second param.
I'm not sure I follow. How would that test specifically a NumPy mechanism Vs JAX? glass.harmonics.inverse_transform does something different depending on input
You always compute the reference value with NumPy arrays and the actual value with xp arrays.
Then, for the assertion, the reference value is coerced with xp.asarray, being explicit about the expected namespace without changing the reference values.
Activity
lucascolley commentedon Sep 30, 2026
could you link to the use-case? We used to have this in the versions that were in SciPy, but when taking a second look while switching to
xpx.testingwe decided it was cleaner to just always avoid this pattern.I'd be happy to add this if the use-case is compelling.
paddyroddy commentedon Sep 30, 2026
So for our specific use case we are wanting to compare the outputs of an inverse spherical harmonic transform. Our current code has a wrapper around https://pypi.org/project/healpy and https://pypi.org/project/healpix, so that they can handle any array backend by internally converting to NumPy.
We would like to use https://pypi.org/project/s2fft to compute out spherical harmonic transforms natively in JAX, so that we never leave the GPU. So we can't do this in the classic Array API way, and would have to do an
if xp.__name__ == "jax.numpy"pattern.Regardless, it would be nice to use
array-api-extra.testing.assert_equalto compare the output of the NumPy and JAX transform. I guess we could just usenumpy.testing.assert_array_equalfor that bit.lucascolley commentedon Sep 30, 2026
Do you have
xpavailable at assertion time? The thinking is thatcheck_backends=Falseis no more concise than wrapping the desired array withxp.asarray.paddyroddy commentedon Oct 1, 2026
Yeah this is what I'm currently doing, just looks a bit ugly!
lucascolley commentedon Oct 1, 2026
what I meant was having the test parametrised by
xp, then you havealm_actualas the first param, andxp.asarray(alm_desired)as the second param.prady0t commentedon Oct 1, 2026
If I'm not wrong, this was the
check_namespacemechanism in SciPy that we removed in the process of adaptingxpx.testing, right?lucascolley commentedon Oct 1, 2026
yep
prady0t commentedon Oct 1, 2026
It might then just make sense to add it in extra. SciPy used to have it, and GLASS also seems to have a use case.
lucascolley commentedon Oct 1, 2026
yeah but see my messages above, I'm still not convinced that it is cleaner than calling
xp.asarraypaddyroddy commentedon Oct 1, 2026
I'm not sure I follow. How would that test specifically a NumPy mechanism Vs JAX?
glass.harmonics.inverse_transformdoes something different depending on inputlucascolley commentedon Oct 1, 2026
You always compute the reference value with NumPy arrays and the actual value with
xparrays.Then, for the assertion, the reference value is coerced with
xp.asarray, being explicit about the expected namespace without changing the reference values.Does that make sense?
paddyroddy commentedon Oct 2, 2026
I think so, so something like this?
lucascolley commentedon Oct 2, 2026
yeah, that's the idea. Do you think that would be significantly cleaner with
check_backends=False?paddyroddy commentedon Oct 2, 2026
Well not significantly of course. Just feels a bit similar to me.
lucascolley commentedon Oct 2, 2026
I'd err on keeping this as-is for now then, but do let me know if a more compelling use-case appears