TST: use xpx.testing assertions#25143
Conversation
Signed-off-by: Pradyot Ranjan <[email protected]>
Signed-off-by: Pradyot Ranjan <[email protected]>
Signed-off-by: Pradyot Ranjan <[email protected]>
|
We have 8 total failures. All of them are expected namespace mismatch failures, as |
Signed-off-by: Pradyot Ranjan <[email protected]>
Co-authored-by: Lucas Colley <[email protected]>
Signed-off-by: Pradyot Ranjan <[email protected]>
xpx.testing assertions
Signed-off-by: Pradyot Ranjan <[email protected]>
|
The GPU failures demonstrate something we need to address — The 'install into venv' failure I think can be addressed when we make the assertions public by ensuring that their module does not depend on
That's probably something we want to fix over in array-api-extra. |
I think we should try explicitly accepting 0-D arrays in array-api-extra for these parameters, but rejecting higher-dimensional arrays. If there are a bunch of failures for 1-D arrays with a single element then maybe it makes sense to accept that also. |
I don't know much about pytorch tensors, but can we do float(4e-16 * ref.integral)In the tests to make this work? |
|
But ofc this won't be a proper fix as we need to address these inputs in the extra module. |
Yeah, part of the motivation for avoiding use of native assertions is for this kind of stability (or at least consistency) — we don't want to have to deal with bugs or nuances of various different I think you have a good argument if the question was "should we put in a bunch of thought to re-write these now?" But really, that work has already been done by Guido and Matt, so I think we are right to make use of it (presuming, fairly, that that work is of good quality).
Let's check what changes would be required before we finalise the public API! Would you be willing to try these out in scikit-image and report any difficulties? I already have my eyes on wilsonrljr/sysidentpy#232 and glass-dev/glass#1076 too.
I think this may be the key remaining area of work. |
Signed-off-by: Pradyot Ranjan <[email protected]>
Signed-off-by: Pradyot Ranjan <[email protected]>
I think these are useful points. Numpy also has a |
I would wait until it is explicitly requested, the finer grained parameters we have already are better IMO. |
True. |
|
All checks are passing now! |
|
nice, I think #25143 (comment) is the next step |
Signed-off-by: Pradyot Ranjan <[email protected]>
|
Only |
Let's leave it for now, but yes let's return to it when we bring this PR out of draft. |
[skip circle]
92416b6 to
4e0a864
Compare
Co-authored-by: Lucas Colley <[email protected]>
Co-authored-by: Lucas Colley <[email protected]>
|
I think data-apis/array-api-extra#755 is the next step here |
|
|
||
|
|
||
| def xp_assert_equal(actual, desired, *, check_dtype=True, | ||
| check_shape=True, check_0d=False, err_msg='', xp=None): |
There was a problem hiding this comment.
| check_shape=True, check_0d=False, err_msg='', xp=None): | |
| check_shape=True, check_0d=True, err_msg='', xp=None): |
There was a problem hiding this comment.
Actually, I kept it False on purpose.
Before scipy did
actual = xp.asarray(actual)
desired = xp.asarray(desired)
To all arrays, but we now do:
if isinstance(x, (list, tuple)) or type(x) in (
int,
float,
complex,
bool,
):
return xp.asarray(x)
(only use asarrya for Python scalar and lists.)
This leads to many a place where a scalar input becomes a 0D array, and hence check_0d fails (where it was being compared to numpy scalars).
In scipy, for this reason, we first check_scalar before converting to xp.asarray, see
scipy/scipy/_lib/_array_api.py
Line 238 in 9f253f9
. We can't do that in array_api_extra.
If we want to keep it True, I can give check_0d=False as parameters for tests that currently fail with this change.
There was a problem hiding this comment.
This leads to many a place where a scalar input becomes a 0D array, and hence check_0d fails (where it was being compared to numpy scalars).
can you give a concrete example? I thought the type(x) in (int, float, complex, bool) would fail for NumPy scalars.
There was a problem hiding this comment.
It doesn't actually. Only works for Python scalars.See here for example:
w here is an np scalar, this raises
E AssertionError: array-ness does not match:
E Actual: <class 'numpy.float64'>
E Desired: <class 'numpy.ndarray'>
There was a problem hiding this comment.
are there cases where we hit this via the xp_... assertions, or only those with the same names as the ones from np.testing?
There was a problem hiding this comment.
This line also produces a similar error:
scipy/scipy/signal/tests/test_waveforms.py
Line 113 in 9f253f9
E AssertionError: array-ness does not match:
E Actual: <class 'numpy.complex128'>
E Desired: <class 'numpy.ndarray'>
There was a problem hiding this comment.
thanks, I pushed a commit which aims to address this.
Co-authored-by: Lucas Colley <[email protected]>
Co-authored-by: Lucas Colley <[email protected]>
[skip circle]
5947421 to
bce12e6
Compare
|
time to use |
Signed-off-by: Pradyot Ranjan <[email protected]>
Reference issue
What does this implement/fix?
This is a draft PR to check how much we have progressed with
xp_assertfunctions in thearray_api_extralibrary. We are checking how easy it is for other libraries to implement these testing functions in their existing test suite.Additional information
This is to remain a draft PR for reference. In case we want to merge it, I can put some effort into cleaning it and making some necessary changes in the
test_array_api.pyfile. There are 2 things different in thearray_api_extraversion of tests from scipy:array_api_extraversion. SeeI've made some efforts to take these into account and reduce the number of failing tests by checking for Python scalars and lists, and converting them with
xp.asarraybefore feeding them toarray_api_extra.Most test failures are due to our inability to disable namespace checks; they originate from
test_array_api.py.See:
AI Generation Disclosure
No AI tools used