Repository navigation
Return an n x 1 matrix from SparseMatrixCSC of a sparse vector view - #1113
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1113 +/- ##
==========================================
- Coverage 94.72% 94.72% -0.01%
==========================================
Files 16 16
Lines 10318 10323 +5
==========================================
+ Hits 9774 9778 +4
- Misses 544 545 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
`SparseMatrixCSC(view(A, :, j))` and `SparseMatrixCSC{Tv}(view(A, :, j))` returned a
`SparseVector`; they now return the `n x 1` matrix that `SparseMatrixCSC{Tv,Ti}` of
the same view and `SparseMatrixCSC` of a sparse vector already return.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…atrix does Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ViralBShah
force-pushed
the
vs/csc-from-vector-view
branch
from
October 26, 2026 13:58
578600d to
7535d57
Compare
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.
SparseMatrixCSC(view(A, :, j))returns aSparseVector, so a constructor ofSparseMatrixCSCreturns something that is not aSparseMatrixCSC. The same holds forSparseMatrixCSC{Tv}and for a view of a sparse vector, whileSparseMatrixCSC{Tv,Ti}of the same view, andSparseMatrixCSCof aSparseVector, return ann x 1matrix.Before
After
The wrapper constructors in
sparseconvert.jlreturn_sparsem(A)directly when the eltype matches, and_sparsemof a 1-d view is theSparseVectorthat indexing the parent gives. Two methods onSubArray{<:Any,1}now pass that vector on toSparseMatrixCSC, as the typed{Tv,Ti}constructor already does.sparse(view(A, :, j))is unchanged and still returns aSparseVector. This touches dispatch.Potential breakage: this changes the result type of code that works today. A caller relying on
SparseMatrixCSC(view(A, :, j))being aSparseVector, for example indexing it with one index as a vector or passing it where a vector is required, now gets ann x 1matrix.sparse(view(A, :, j))orA[:, j]gives the vector.Dense has no constructor from a vector:
Matrix(v)andMatrix(view(M, :, 1))throw aMethodError. A sparse vector has long converted to ann x 1matrix, throughSparseMatrixCSC(x)andconvert(SparseMatrixCSC, x), so a view of one now does the same. Matching dense exactly would break those. A view of a dense vector, which dense cannot convert either, threw aTypeErrorfrom an internalinvoke. It now throws theMethodErrorthatMatrixgives:Before
After
🤖 Generated with Claude Code