forked from JuliaGPU/CUDA.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement SparseArrays.sparse, with a format kwarg. (JuliaGPU#1093)
- Loading branch information
1 parent
99dea19
commit 54fdb33
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using CUDA.CUSPARSE, SparseArrays | ||
|
||
@testset "sparse" begin | ||
n, m = 4, 4 | ||
I = [1,2,3] |> cu | ||
J = [2,3,4] |> cu | ||
V = Float32[1,2,3] |> cu | ||
|
||
dense = rand(3,3) |> cu | ||
|
||
# check defaults | ||
@test sparse(I, J, V) isa CuSparseMatrixCSC | ||
@test sparse(dense) isa CuSparseMatrixCSC | ||
|
||
for (fmt, T) in [(:coo, CuSparseMatrixCOO), | ||
(:csc, CuSparseMatrixCSC), | ||
(:csr, CuSparseMatrixCSR), | ||
(:bsr, CuSparseMatrixBSR) | ||
] | ||
if fmt != :bsr # bsr not supported | ||
x = sparse(I, J, V; fmt=fmt) | ||
@test x isa T{Float32} | ||
@test size(x) == (3, 4) | ||
|
||
x = sparse(I, J, V, m, n; fmt=fmt) | ||
@test x isa T{Float32} | ||
@test size(x) == (4, 4) | ||
end | ||
|
||
if fmt != :coo # dense to COO not implemented | ||
x = sparse(dense; fmt=fmt) | ||
@test x isa T{Float32} | ||
@test collect(x) == collect(dense) | ||
end | ||
end | ||
end |