From 1139ffdcf77d5981357787dc69bf54bc62965c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Chuchma=C5=82a?= Date: Sat, 14 Nov 2020 08:27:58 +0100 Subject: [PATCH] Fix broken checkbounds for CuSparseMatrixCSR and tests (#545) Fix broken checkbounds for CuSparseMatrixCSR Co-authored-by: achuchmala --- lib/cusparse/array.jl | 2 +- test/cusparse.jl | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/cusparse/array.jl b/lib/cusparse/array.jl index 5e289e4f17..864b86c9dd 100644 --- a/lib/cusparse/array.jl +++ b/lib/cusparse/array.jl @@ -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)) diff --git a/test/cusparse.jl b/test/cusparse.jl index f052f63cdc..84484dc856 100644 --- a/test/cusparse.jl +++ b/test/cusparse.jl @@ -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] @@ -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) @@ -781,4 +789,3 @@ end end end end -