Repository navigation
Fixes and tests for COO indexing, exclude more kernels from coverage - #2668
Merged
Merged
Conversation
Contributor
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/lib/cusparse/array.jl b/lib/cusparse/array.jl
index 9afa9583e..711f76c24 100644
--- a/lib/cusparse/array.jl
+++ b/lib/cusparse/array.jl
@@ -387,13 +387,13 @@ end
function Base.getindex(x::CuSparseMatrixCOO{T}, i::Integer, ::Colon) where {T}
checkbounds(x, i, :)
- if issorted(x.rowInd)
+ return if issorted(x.rowInd)
row_start = searchsortedfirst(x.rowInd, i)
- row_end = min(searchsortedlast(x.rowInd, i), length(x.rowInd))
+ row_end = min(searchsortedlast(x.rowInd, i), length(x.rowInd))
row_start == length(x.rowInd) + 1 && return CuSparseVector(similar(x.rowInd, 0), CUDA.zeros(T, 0), size(x, 2))
CuSparseVector(x.colInd[row_start:row_end], x.nzVal[row_start:row_end], size(x, 2))
else
- row_inds = findall(ix->ix == i, x.rowInd)
+ row_inds = findall(ix -> ix == i, x.rowInd)
isnothing(row_inds) && return CuSparseVector(similar(x.rowInd, 0), CUDA.zeros(T, 0), size(x, 2))
CuSparseVector(x.colInd[row_inds], x.nzVal[row_inds], size(x, 2))
end
@@ -401,13 +401,13 @@ end
function Base.getindex(x::CuSparseMatrixCOO{T}, ::Colon, j::Integer) where {T}
checkbounds(x, :, j)
- if issorted(x.colInd)
+ return if issorted(x.colInd)
col_start = searchsortedfirst(x.colInd, j)
- col_end = min(searchsortedlast(x.colInd, j), length(x.colInd))
+ col_end = min(searchsortedlast(x.colInd, j), length(x.colInd))
col_start == length(x.colInd) + 1 && return CuSparseVector(similar(x.colInd, 0), CUDA.zeros(T, 0), size(x, 2))
CuSparseVector(x.rowInd[col_start:col_end], x.nzVal[col_start:col_end], size(x, 1))
else
- col_inds = findall(ix->ix == j, x.colInd)
+ col_inds = findall(ix -> ix == j, x.colInd)
isnothing(col_inds) && return CuSparseVector(similar(x.colInd, 0), CUDA.zeros(T, 0), size(x, 1))
CuSparseVector(x.rowInd[col_inds], x.nzVal[col_inds], size(x, 1))
end
@@ -448,7 +448,7 @@ function Base.getindex(A::CuSparseMatrixCOO{T}, i0::Integer, i1::Integer) where
@boundscheck checkbounds(A, i0, i1)
r1 = searchsortedfirst(A.rowInd, i0, Base.Order.Forward)
(r1 > length(A.rowInd) || A.rowInd[r1] > i0) && return zero(T)
- r2 = min(searchsortedfirst(A.rowInd, i0+1, Base.Order.Forward), length(A.rowInd))
+ r2 = min(searchsortedfirst(A.rowInd, i0 + 1, Base.Order.Forward), length(A.rowInd))
c1 = searchsortedfirst(A.colInd, i1, r1, r2, Base.Order.Forward)
(c1 > r2 || c1 == length(A.colInd) + 1 || A.colInd[c1] > i1) && return zero(T)
nonzeros(A)[c1]
diff --git a/test/libraries/cusparse.jl b/test/libraries/cusparse.jl
index 2d75623c7..ee6b525b8 100644
--- a/test/libraries/cusparse.jl
+++ b/test/libraries/cusparse.jl
@@ -75,27 +75,27 @@ blockdim = 5
y = sprand(k,n,0.2)
d_y = CuSparseMatrixCSC(y)
@test_throws ArgumentError copyto!(d_y,d_x)
- x = sprand(m,n,0.2)
+ x = sprand(m, n, 0.2)
d_x = CuSparseMatrixCOO(x)
@test CuSparseMatrixCOO(d_x) === d_x
- @test length(d_x) == m*n
- @test size(d_x) == (m,n)
- @test size(d_x,1) == m
- @test size(d_x,2) == n
- @test size(d_x,3) == 1
- @test ndims(d_x) == 2
+ @test length(d_x) == m * n
+ @test size(d_x) == (m, n)
+ @test size(d_x, 1) == m
+ @test size(d_x, 2) == n
+ @test size(d_x, 3) == 1
+ @test ndims(d_x) == 2
d_x2 = copy(d_x)
@test d_x2 isa CuSparseMatrixCOO
@test size(d_x2) == size(d_x)
@test length(d_x) == length(x)
CUDA.@allowscalar begin
- @test Array(d_x[:]) == x[:]
+ @test Array(d_x[:]) == x[:]
@test d_x[firstindex(d_x)] == x[firstindex(x)]
- @test d_x[div(end, 2)] == x[div(end, 2)]
- @test d_x[end] == x[end]
+ @test d_x[div(end, 2)] == x[div(end, 2)]
+ @test d_x[end] == x[end]
@test d_x[firstindex(d_x), firstindex(d_x)] == x[firstindex(x), firstindex(x)]
- @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 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]) == x[:]
for i in 1:size(x, 2)
@test Array(d_x[:, i]) == x[:, i]
@@ -104,9 +104,9 @@ blockdim = 5
@test Array(d_x[i, :]) == x[i, :]
end
end
- y = sprand(k,n,0.2)
+ y = sprand(k, n, 0.2)
d_y = CuSparseMatrixCOO(y)
- @test_throws ArgumentError copyto!(d_y,d_x)
+ @test_throws ArgumentError copyto!(d_y, d_x)
d_y = CuSparseMatrixCSR(d_y)
d_x = CuSparseMatrixCSR(d_x)
@test CuSparseMatrixCSR(d_x) === d_x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added support for
:-based indexing of COO arrays and fixed an issue - if ther2variable in the diff there isn't capped at thelengthof the underlying array, you can get an out of bounds error! Also added tests for the new stuff and excluded some more device side code from coverage