-
Notifications
You must be signed in to change notification settings - Fork 129
Deprecate redefinition of np.testing.assert_allclose
#784
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
base: main
Are you sure you want to change the base?
Deprecate redefinition of np.testing.assert_allclose
#784
Conversation
94bdd55
to
ba18c65
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #784 +/- ##
==========================================
- Coverage 80.97% 80.96% -0.02%
==========================================
Files 169 169
Lines 47015 47011 -4
Branches 11497 11497
==========================================
- Hits 38072 38061 -11
- Misses 6728 6729 +1
- Partials 2215 2221 +6
|
135ff93
to
87c6ee6
Compare
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.
Asking whether we can remove one more helper from the non-test codebase
atol_, rtol_ = pytensor.tensor.math._get_atol_rtol(a, b) | ||
if rtol is not None: | ||
rtol_ = rtol | ||
if atol is not None: | ||
atol_ = atol |
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.
Coverage says this is not being used, can we just remove?
@@ -85,7 +85,15 @@ def test_variable_only(self): | |||
z = dot(x, y) | |||
assert hasattr(z.tag, "test_value") | |||
f = pytensor.function([x, y], z) | |||
assert _allclose(f(x.tag.test_value, y.tag.test_value), z.tag.test_value) | |||
atol_, rtol_ = _get_atol_rtol( |
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.
If this ends up only being used in the tests here, we can remove from math and include only in the test file?
So what is to be done here. Here's what is changing. So originally in |
81a97df
to
26782d2
Compare
Hi @ricardoV94 |
26782d2
to
035139e
Compare
abc44ab
to
6824a20
Compare
@@ -607,7 +607,7 @@ def test_mul_div_cases(self): | |||
f = function(list(sym_inputs), g, mode=mode) | |||
out = f(*val_inputs) | |||
assert out_dtype == out.dtype | |||
utt.assert_allclose(out, val_inputs[1]) | |||
np.allclose(out, val_inputs[1]) |
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.
These should be np.testing.assert_allclose
@@ -627,7 +627,7 @@ def test_mul_div_cases(self): | |||
): | |||
f = function(list(sym_inputs), g, mode=mode) | |||
out = f(*val_inputs) | |||
utt.assert_allclose(out, (1 / val_inputs[1])) | |||
np.allclose(out, (1 / val_inputs[1])) |
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 also
out, expected_out, atol=1e-6 if config.floatX == "float32" else 0 | ||
out, | ||
expected_out, | ||
atol=1e-08 if config.floatX == "float32" else 0, |
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.
Why did this change?
atol_, rtol_ = _get_atol_rtol(np.asarray(t_binv), n_binv) | ||
assert np.allclose(t_binv, n_binv, atol=atol_, rtol=rtol_) | ||
atol_, rtol_ = _get_atol_rtol(np.asarray(t_binv1), n_binv1) | ||
assert np.allclose(t_binv1, n_binv1, atol=atol_, rtol=rtol_) |
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 is too much code to recreate every time it's used. The question is whether we really need the inner logic. Seems like it has some special way of deciding tolerances for float16/32 complex64. If the tests are covering these types we can hardcode the tolerances, the same way we usually do atol = x if config.floatX else y
. But I suspect many of these tests don't even make use of these specific types (I could be wrong).
Otherwise we should keep the original function and not repeat the code so many times in the tests. These functions that are only used in tests should be moved to the tests package, out of the main pytensor package (if we end up keeping it).
Also always use np.testing.assert_allclose
and not np.allclose
, as it has a nicer output when it fails.
@Dhruvanshu-Joshi This PR is already a pretty good improvement, so I don't want to block it much longer. The main question is what to do with that If this is too laborious let's revert and address |
Yep what you mentioned makes complete sense. I try hardcoding the tolerances wherever possible to reduce this unwanted repetitiveness and update whether it is better to go with it or revert this. |
Description
Replaced all instances of
assert_allclose
with correspondingnp.testing.assert_allclose
.Related Issue
np.testing.assert_allclose
#551Checklist
Type of change