Skip to content

Commit 1139ffd

Browse files
achuchmalaachuchmala
andauthored
Fix broken checkbounds for CuSparseMatrixCSR and tests (#545)
Fix broken checkbounds for CuSparseMatrixCSR Co-authored-by: achuchmala <[email protected]>
1 parent dc488f5 commit 1139ffd

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/cusparse/array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function Base.getindex(x::CuSparseMatrixCSC, ::Colon, j::Integer)
228228
end
229229

230230
function Base.getindex(x::CuSparseMatrixCSR, i::Integer, ::Colon)
231-
checkbounds(x, :, i)
231+
checkbounds(x, i, :)
232232
c1 = convert(Int, x.rowPtr[i])
233233
c2 = convert(Int, x.rowPtr[i+1]) - 1
234234
CuSparseVector(x.colVal[c1:c2], nonzeros(x)[c1:c2], size(x, 2))

test/cusparse.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ blockdim = 5
4949
@test d_x[div(end, 2), div(end, 2)] == x[div(end, 2), div(end, 2)]
5050
@test d_x[end, end] == x[end, end]
5151
@test Array(d_x[firstindex(d_x):end, firstindex(d_x):end]) == x[:, :]
52+
for i in 1:size(x, 2)
53+
@test Array(d_x[:, i]) == x[:, i]
54+
end
5255
end
5356
@test_throws BoundsError d_x[firstindex(d_x) - 1]
5457
@test_throws BoundsError d_x[end + 1]
@@ -73,6 +76,11 @@ blockdim = 5
7376
d_y = CuSparseMatrixCSR(d_y)
7477
d_x = CuSparseMatrixCSR(d_x)
7578
@test_throws ArgumentError copyto!(d_y,d_x)
79+
CUDA.@allowscalar begin
80+
for i in 1:size(y, 1)
81+
@test d_y[i, :] y[i, :]
82+
end
83+
end
7684
d_y = CuSparseMatrixBSR(d_y, blockdim)
7785
d_x = CuSparseMatrixBSR(d_x, blockdim)
7886
@test_throws ArgumentError copyto!(d_y,d_x)
@@ -781,4 +789,3 @@ end
781789
end
782790
end
783791
end
784-

0 commit comments

Comments
 (0)