From 09c41697b146824f0402d17dc430bd4c24fa7718 Mon Sep 17 00:00:00 2001 From: Dominique Orban Date: Sat, 8 Dec 2018 14:12:40 -0500 Subject: [PATCH] generalize sparse matrix slicing to integer types --- stdlib/SparseArrays/src/sparsematrix.jl | 4 ++-- stdlib/SparseArrays/test/sparse.jl | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/SparseArrays/src/sparsematrix.jl b/stdlib/SparseArrays/src/sparsematrix.jl index c4b335701400d..46e76b6f95e37 100644 --- a/stdlib/SparseArrays/src/sparsematrix.jl +++ b/stdlib/SparseArrays/src/sparsematrix.jl @@ -1973,8 +1973,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) diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index 60bd97f23da87..bb2eacc42d3df 100644 --- a/stdlib/SparseArrays/test/sparse.jl +++ b/stdlib/SparseArrays/test/sparse.jl @@ -709,6 +709,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]