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

xp assertions: explicity expect NumPy scalars #2

Closed

Conversation

lucascolley
Copy link

@lucascolley lucascolley commented Jul 29, 2024

I'm pretty sure this is preferable since it allows us to keep the 0d check enabled. x-ref scipy#21026

[skip cirrus] [skip circle]
Copy link
Author

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explanation inline!

Comment on lines -448 to +451
xp_assert_close(res1, ref1, rtol=2e-16, check_0d=False)
xp_assert_equal(res2, ref2, check_0d=False)
xp_assert_close(res1, ref1, rtol=2e-16)
xp_assert_equal(res2, ref2)
if not is_array_api_strict(xp):
xp_assert_equal(res3, ref3, check_0d=False)
xp_assert_equal(res3, ref3)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why these had check_0d=False? Tests pass for me locally without them.

xp_assert_equal(xp.array(0.), xp.array(0.))
xp_assert_equal(xp.asarray(0.), xp.asarray(0.))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course this is just cosmetic as this only runs with NumPy, but may as well use the functions that are in the standard.

Comment on lines +147 to +148
# as an alternative to `check_0d=False`, explicitly expect scalar
xp_assert_equal(xp.float64(0), xp.asarray(0.)[()])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the new check I have added

Comment on lines +92 to +93
ref = ref[()] if ref.ndim == 0 else ref
xp_assert_close(res, ref, atol=10*eps)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometimes this is nonzero-dimensional, so array-api-strict isn't happy with the 0d indexing. That's fine, guard on ndim.

@h-vetinari
Copy link
Owner

Rejected

@h-vetinari h-vetinari closed this Aug 19, 2024
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

Successfully merging this pull request may close these issues.

2 participants