-
Notifications
You must be signed in to change notification settings - Fork 89
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
det, logdet, and logabsdet rrules for SparseMatrixCSC #730
Conversation
CI is broken for this new feature on julia 1.6: (It's also broken on nightly for other reasons that we are going to have to look into. |
Yes, please put them in this file: |
The logs do not say exactly what broke in the tests for 1.6, but I suspect it is because prior to Julia 1.7 there was no method implemented for If that's the problem, what's the best solution? A conditional statement that defines the missing method if |
This method is required for the sparse logabsdet rrules, but was not included in Julia prior to v1.7.
Went ahead and added a conditional definition of the method for |
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.
LGTM, thanks!
This PR implements determinant rrules for unstructured sparse matrices. The equivalent rules for
AbstractMatrices
didn't work, since they require calculating a matrix inverse, which errors by default for sparse matrices to avoid unintentionally creating huge dense matrices. Fortunately, the adjoint for the determinant functions does not depend on all the values of the inverse matrix (see here, section 4.1 and Equation 8). Using the "inverse subset" algorithm, you can efficiently calculate just the sparse subset of the inverse matrix which you need. I just implemented that algorithm in this small package, which enabled me to write the rrules here.I put these rules and their tests in with the "structured" matrix rule sets. Would be happy to move them to new "sparse" src and test files if that fits the organizational structure better. I am also pretty new to writing chain rules, so any feedback or corrections are more than welcome!
This PR will fix #719, and should also help fix TuringLang/DistributionsAD.jl#89.