SparseArrays.jl
SparseArrays.jl copied to clipboard
`nonzeros` for SubArray returns values of parent array
nonzeros appears to be giving the wrong answer for this case. See example:
julia> a = sparse([1 0 2; 0 3 0]) 2×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ 2 ⋅ 3 ⋅
julia> b = view(a, :, 2:3) 2×2 view(::SparseMatrixCSC{Int64, Int64}, :, 2:3) with eltype Int64: 0 2 3 0
julia> nonzeros(b) 3-element Vector{Int64}: 1 3 2
It looks like there is a problem where the call is on the parent array, not the subarray. If I only look at a single column it seems to work
julia> c = view(a, :, 2) 2-element view(::SparseMatrixCSC{Int64, Int64}, :, 2) with eltype Int64: 0 3
julia> nonzeros(c) 1-element view(::Vector{Int64}, 2:2) with eltype Int64: 3
A few other observations:
rowvalsseems to have the same problem asnonzerosnnzandnzrangeappear to work- tested in 1.8.5 and 1.9-rc1