Repository navigation
Conversation
`LinearOperator.mul` passes a `*batch`-shaped tensor of constants to `_mul_constant` when multiplying by a `*batch x 1 x 1` tensor. - `MulLinearOperator._mul_constant` used `if other > 0`, which raises "Boolean value of Tensor with more than one value is ambiguous" for more than one constant. It now uses `(other > 0).all()`, as `RootLinearOperator._mul_constant` does. - `TriangularLinearOperator._mul_constant` multiplied its `*batch x N x N` tensor by `other.unsqueeze(-1)`, which scales the rows instead of the batch members (a wrong result if the batch size equals N, an error otherwise). It is reached from the fixed branch above through the Cholesky roots of the `RootLinearOperator`s. It now uses `other.unsqueeze(-1).unsqueeze(-1)`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Multiplying a batched
MulLinearOperatorby a batch of constants (a*batch x 1 x 1tensor) fails, becauseLinearOperator.mulpasses the*batch-shaped constants to_mul_constant, andMulLinearOperator._mul_constanttests them withif other > 0:In BoTorch, this happens for a multi-output
SingleTaskMultiFidelityGPwith two data fidelities at ab x 1 x dbatch of points:With this PR, the posterior equals the posteriors computed point by point.
Found by the equivalence tests of botorch-rust.
Fix
MulLinearOperator._mul_constantuses(other > 0).all(), asRootLinearOperator._mul_constantdoes. If all constants are positive, they are still pushed into the left root decomposition; otherwise the existingConstantMulLinearOperatorfallback is used.TriangularLinearOperator._mul_constantmultiplied its*batch x N x Ntensor byother.unsqueeze(-1), which scales the rows rather than the batch members. The result is wrong if the batch size equalsNand an error otherwise. It is reached from the first change throughRootLinearOperator._mul_constantwhen the roots are Cholesky factors (the default root decomposition of small dense matrices). It now usesother.unsqueeze(-1).unsqueeze(-1).Scalar constants behave as before.
Not changed here: #148 makes the same change to
LowRankRootAddedDiagLinearOperator._mul_constant, and #136 fixes batches of constants for the block operators.ConstantDiagLinearOperator._mul_constantmultiplies its*batch x 1values by the*batchconstants without unsqueezing them, soAddedDiagLinearOperator(MulLinearOperator(...), ConstantDiagLinearOperator(...)) * cstill fails for a batch of constants.Tests
test_constant_mul_batchintest/operators/test_mul_linear_operator.py(batch and multi-batch classes): positive and mixed-sign batches of constants, forMulLinearOperators ofRootLinearOperators and of dense matrices with Cholesky roots. Positive constants keep theMulLinearOperator; the dense results match.test_constant_mul_batchintest/operators/test_triangular_linear_operator.py(lower and upper): batch shapes(5,)(equal toN) and(2, 3).All four fail on
mainand pass with this PR.ufmt check(black 22.3.0, usort 1.0.3) andflake8pass on the changed files.🤖 Generated with Claude Code