Repository navigation
Fix inv_quad_logdet with a vector rhs (Chol/Dense) and CatLinearOperator.logdet() - #160
Open
flyingdoubleG wants to merge 1 commit into
Open
flyingdoubleG wants to merge 1 commit into
flyingdoubleG wants to merge 1 commit into
Conversation
CholLinearOperator.inv_quad_logdet accepts a vector right-hand side for a non-batch operator, but inv_quad then summed over dim -2 of the 1-D solve and raised an IndexError. Since small operators compute inv_quad_logdet through a CholLinearOperator, this also broke e.g. DenseLinearOperator(A).inv_quad_logdet(vec, logdet=True). CatLinearOperator.inv_quad_logdet called .to(device) on every term, including the None that is returned when no right-hand side is given, so CatLinearOperator.logdet() raised an AttributeError.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes two crashes in
inv_quad_logdet.1. Vector right-hand side through
CholLinearOperatorCholLinearOperator.inv_quad_logdetexplicitly accepts a 1-Dinv_quad_rhsfor a non-batch operator, as the default implementation does. It then callsinv_quad, which solves with the vector and sums overdim=-2. For a 1-D solve that dimension does not exist:Operators below
max_cholesky_sizecomputeinv_quad_logdetthrough aCholLinearOperator. So this also breaks the common callwhile
DenseLinearOperator(A).inv_quad(vec)(default path) works and returns a scalar.Fix. In
inv_quad, treat a 1-D right-hand side of a non-batch operator as one column. The output shapes then match the default implementation: a scalar withreduce_inv_quad=True, and(1,)otherwise.2.
CatLinearOperator.logdet()CatLinearOperator.inv_quad_logdetmoves every returned term to the output device, including theNonereturned for a term that was not requested. SoCatLinearOperator.logdet()andinv_quad_logdet(logdet=True)without a right-hand side raise:Fix. Leave
Noneterms unchanged.Tests
TestCholLinearOperator.test_inv_quad_vector: coversinv_quad(reduced and not reduced) andinv_quad_logdetwith a vector, plus theDenseLinearOperatorpath.TestCatLinearOperator.test_logdet_without_inv_quad.Both fail on main and pass with this change. The full suite gives 5049 passed and 1 failed. The failure is
test_psd_safe_cholesky_psd, which also fails on main without these changes. I ranufmtandflake8on the changed files.Related, but not covered by this PR: #139 and #147 (vector right-hand sides for
DiagLinearOperatorbatches and low-rank operators), and #144/#145 (CholLinearOperatorwith upper factors, and slicing).