-
Notifications
You must be signed in to change notification settings - Fork 100
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
Fix numba implementation of cholesky not setting off-diag entries to zero #816
Conversation
tests/link/numba/test_slinalg.py
Outdated
@@ -108,6 +109,24 @@ def test_solve_triangular_raises_on_nan_inf(value): | |||
f(A_tri, b) | |||
|
|||
|
|||
@pytest.mark.parametrize("lower", [True, False], ids=["lower=True", "lower=False"]) | |||
@pytest.mark.parametrize("trans", [True, False], ids=["trans=True", "trans=False"]) | |||
def test_numba_Cholesky_scipy(lower, trans): |
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.
Any reason why not to extend/reuse the test below?
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.
No good one, fixed.
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.
Nice, good catch.
#814 was about originally about gradients, so perhaps we should test them explicitly?
I would say no, as long as someone checked the motivating example and it seems to work. The cases where bugs are found can be much more complex/expensive than the final regression tests? |
028c793
to
4d9b0a2
Compare
I checked the original example. |
tests/link/numba/test_slinalg.py
Outdated
func = pytensor.function([cov], chol, mode="NUMBA") | ||
np.testing.assert_allclose(func(val), scipy.linalg.cholesky(val, lower=lower)) |
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.
Isn't compare_numba_and_py
already checking numba and python implementations match?
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.
It should, but didn't find the problem because compare_numba_and_py
calls the functions without fast_run rewrites. That excluded Blockwise, and because that doesn't have a numba implementation it ended up calling the python code for the numba and the python version.
I included the rewrite that remove useless Blockwise ops into the set of rewrites we do in testing.
Maybe we should actually just use the default numba mode?
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.
Ahh... okay so hopefully just a temporary blind spot. Let's keep it like you did now
4d9b0a2
to
f57bb55
Compare
f57bb55
to
b766b21
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #816 +/- ##
==========================================
+ Coverage 80.84% 80.86% +0.01%
==========================================
Files 163 163
Lines 46890 46897 +7
Branches 11468 11473 +5
==========================================
+ Hits 37909 37923 +14
+ Misses 6768 6757 -11
- Partials 2213 2217 +4
|
Description
The cholesky blas function returns an array with values stored in the triagonal part of the array that is zero by definition.
This is the equivalent of the scipy code here: https://github.com/scipy/scipy/blob/d5e1e03ac12fb5ad7fa4949e7ffea2137e780b15/scipy/linalg/flapack_pos_def.pyf.src#L132
fixes #814
Checklist
Type of change