Skip to content

Commit

Permalink
Fix broken checkbounds for CuSparseMatrixCSR and tests (#545)
Browse files Browse the repository at this point in the history
Fix broken checkbounds for CuSparseMatrixCSR

Co-authored-by: achuchmala <[email protected]>
  • Loading branch information
achuchmala and achuchmala authored Nov 14, 2020
1 parent dc488f5 commit 1139ffd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/cusparse/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function Base.getindex(x::CuSparseMatrixCSC, ::Colon, j::Integer)
end

function Base.getindex(x::CuSparseMatrixCSR, i::Integer, ::Colon)
checkbounds(x, :, i)
checkbounds(x, i, :)
c1 = convert(Int, x.rowPtr[i])
c2 = convert(Int, x.rowPtr[i+1]) - 1
CuSparseVector(x.colVal[c1:c2], nonzeros(x)[c1:c2], size(x, 2))
Expand Down
9 changes: 8 additions & 1 deletion test/cusparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ blockdim = 5
@test d_x[div(end, 2), div(end, 2)] == x[div(end, 2), div(end, 2)]
@test d_x[end, end] == x[end, end]
@test Array(d_x[firstindex(d_x):end, firstindex(d_x):end]) == x[:, :]
for i in 1:size(x, 2)
@test Array(d_x[:, i]) == x[:, i]
end
end
@test_throws BoundsError d_x[firstindex(d_x) - 1]
@test_throws BoundsError d_x[end + 1]
Expand All @@ -73,6 +76,11 @@ blockdim = 5
d_y = CuSparseMatrixCSR(d_y)
d_x = CuSparseMatrixCSR(d_x)
@test_throws ArgumentError copyto!(d_y,d_x)
CUDA.@allowscalar begin
for i in 1:size(y, 1)
@test d_y[i, :] y[i, :]
end
end
d_y = CuSparseMatrixBSR(d_y, blockdim)
d_x = CuSparseMatrixBSR(d_x, blockdim)
@test_throws ArgumentError copyto!(d_y,d_x)
Expand Down Expand Up @@ -781,4 +789,3 @@ end
end
end
end

0 comments on commit 1139ffd

Please sign in to comment.