Repository navigation
Avoid reshape when materialising DualLayout views of matrices - #291
Merged
Merged
Conversation
`_dual_adjoint`/`_dual_transpose` assumed the parent of a `DualLayout` view is an adjoint/transpose of a vector. When it is a 1×n matrix with `DualLayout` (e.g. a `BlockedMatrix` wrapping an adjoint vector), the adjoint is an n×1 matrix and linear indexing into it reshapes, which fails for infinite arrays. Take a column view instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #291 +/- ##
==========================================
+ Coverage 90.66% 90.81% +0.15%
==========================================
Files 12 12
Lines 2068 2102 +34
==========================================
+ Hits 1875 1909 +34
Misses 193 193 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
sub_materialize(::DualLayout, V)for a viewV = view(A, :, jr)calls_dual_adjoint/_dual_transpose, which doview(parent(V)', jr). This assumesparent(V)is an adjoint/transpose of a vector. ButDualLayoutis also reported by 1×n matrices that wrap one, e.g.BlockedMatrix(v', ...)orMyMatrix(v'). In that caseparent(V)'is an n×1 matrix, soview(·, jr)is linear indexing, and Base reshapes. For infinite arrays this throws:Here the reshape's
ind2subcallsdivrem(i, ℵ₀). This came up indexing aBandedBlockBandedMatrixwhosedatais such aBlockedMatrix.The fix adds a
_dual_viewhelper: for a vector it'sview(v, jr)as before, and for a matrix it'sview(A, jr, only(axes(A,2))). The behaviour for genuine adjoint/transpose vectors doesn't change.The new tests check that
_dual_adjoint/_dual_transposeof a wrapped adjoint/transpose (real and complex) don't produce aReshapedArray. They also cover the infinite caseMyMatrix(InfVec()')[:, 1:3]. Both fail without the fix. The version is bumped to 1.16.1.🤖 Generated with Claude Code