Skip to content

Commit

Permalink
generalize sparse matrix slicing to integer types (#30319)
Browse files Browse the repository at this point in the history
(cherry picked from commit 072ad7d)
  • Loading branch information
dpo authored and KristofferC committed Dec 20, 2018
1 parent 235bdc7 commit 5125952
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stdlib/SparseArrays/src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1974,8 +1974,8 @@ function getindex_cols(A::SparseMatrixCSC{Tv,Ti}, J::AbstractVector) where {Tv,T
return SparseMatrixCSC(m, nJ, colptrS, rowvalS, nzvalS)
end

getindex_traverse_col(::AbstractUnitRange, lo::Int, hi::Int) = lo:hi
getindex_traverse_col(I::StepRange, lo::Int, hi::Int) = step(I) > 0 ? (lo:1:hi) : (hi:-1:lo)
getindex_traverse_col(::AbstractUnitRange, lo::Integer, hi::Integer) = lo:hi
getindex_traverse_col(I::StepRange, lo::Integer, hi::Integer) = step(I) > 0 ? (lo:1:hi) : (hi:-1:lo)

function getindex(A::SparseMatrixCSC{Tv,Ti}, I::AbstractRange, J::AbstractVector) where {Tv,Ti<:Integer}
@assert !has_offset_axes(A, I, J)
Expand Down
2 changes: 2 additions & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,8 @@ end

@test ss116[:,:] == copy(ss116)

@test convert(SparseMatrixCSC{Float32,Int32}, sd116)[2:5,:] == convert(SparseMatrixCSC{Float32,Int32}, sd116[2:5,:])

# range indexing
@test Array(ss116[i,:]) == aa116[i,:]
@test Array(ss116[:,j]) == aa116[:,j]
Expand Down

0 comments on commit 5125952

Please sign in to comment.