Skip to content

Commit 4df814c

Browse files
authored
Even more sparse tests (#2695)
* Even more sparse tests * Yet more show tests
1 parent b26030e commit 4df814c

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

lib/cusparse/array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ for (gpu, cpu) in [:CuSparseMatrixCSC => :SparseMatrixCSC,
646646
:CuSparseMatrixCSR => :SparseMatrixCSC,
647647
:CuSparseMatrixBSR => :SparseMatrixCSC,
648648
:CuSparseMatrixCOO => :SparseMatrixCSC]
649-
@eval Base.show(io::IOContext, x::$gpu) =
649+
@eval Base.show(io::IO, x::$gpu) =
650650
show(io, $cpu(x))
651651

652652
@eval function Base.show(io::IO, mime::MIME"text/plain", S::$gpu)

test/libraries/cusparse.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ blockdim = 5
2323
dense_d_x = CuVector(x)
2424
CUDA.@allowscalar begin
2525
@test sprint(show, d_x) == replace(sprint(show, x), "SparseVector{Float64, Int64}"=>"CUDA.CUSPARSE.CuSparseVector{Float64, Int32}", "sparsevec(["=>"sparsevec(Int32[")
26+
@test sprint(show, MIME"text/plain"(), d_x) == replace(sprint(show, MIME"text/plain"(), x), "SparseVector{Float64, Int64}"=>"CuSparseVector{Float64, Int32}", "sparsevec(["=>"sparsevec(Int32[")
2627
@test Array(d_x[:]) == x[:]
2728
@test d_x[firstindex(d_x)] == x[firstindex(x)]
2829
@test d_x[div(end, 2)] == x[div(end, 2)]
@@ -44,6 +45,10 @@ blockdim = 5
4445
@test size(d_x) == (m, 1)
4546
x = sprand(m,n,0.2)
4647
d_x = CuSparseMatrixCSC(x)
48+
d_tx = CuSparseMatrixCSC(transpose(x))
49+
d_ax = CuSparseMatrixCSC(adjoint(x))
50+
@test size(d_tx) == (n,m)
51+
@test size(d_ax) == (n,m)
4752
@test CuSparseMatrixCSC(d_x) === d_x
4853
@test length(d_x) == m*n
4954
@test size(d_x) == (m,n)
@@ -52,9 +57,12 @@ blockdim = 5
5257
@test size(d_x,3) == 1
5358
@test ndims(d_x) == 2
5459
CUDA.@allowscalar begin
60+
@test sprint(show, d_x) == sprint(show, SparseMatrixCSC(d_x))
5561
@test sprint(show, MIME"text/plain"(), d_x) == replace(sprint(show, MIME"text/plain"(), x), "SparseMatrixCSC{Float64, Int64}"=>"CuSparseMatrixCSC{Float64, Int32}")
5662
@test Array(d_x[:]) == x[:]
5763
@test d_x[:, :] == x[:, :]
64+
@test d_tx[:, :] == transpose(x)[:, :]
65+
@test d_ax[:, :] == adjoint(x)[:, :]
5866
@test d_x[(1, 1)] == x[1, 1]
5967
@test d_x[firstindex(d_x)] == x[firstindex(x)]
6068
@test d_x[div(end, 2)] == x[div(end, 2)]
@@ -91,6 +99,8 @@ blockdim = 5
9199
@test_throws ArgumentError copyto!(d_y,d_x)
92100
x = sprand(m,n,0.2)
93101
d_x = CuSparseMatrixCOO(x)
102+
d_tx = CuSparseMatrixCOO(transpose(x))
103+
d_ax = CuSparseMatrixCOO(adjoint(x))
94104
@test CuSparseMatrixCOO(d_x) === d_x
95105
@test length(d_x) == m*n
96106
@test size(d_x) == (m,n)
@@ -107,6 +117,8 @@ blockdim = 5
107117
@test d_x[firstindex(d_x)] == x[firstindex(x)]
108118
@test d_x[div(end, 2)] == x[div(end, 2)]
109119
@test d_x[end] == x[end]
120+
@test d_tx[:, 1] == transpose(x)[:, 1]
121+
@test d_ax[1, :] == adjoint(x)[1, :]
110122
@test d_x[firstindex(d_x), firstindex(d_x)] == x[firstindex(x), firstindex(x)]
111123
@test d_x[div(end, 2), div(end, 2)] == x[div(end, 2), div(end, 2)]
112124
@test d_x[end, end] == x[end, end]

test/libraries/cusparse/reduce.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using CUDA.CUSPARSE, SparseArrays
22

3-
# XXX: these tests cause GC corruption (see JuliaGPU/CUDA.jl#2027)
4-
if false
5-
63
m,n = 5,6
74
p = 0.5
85

@@ -25,7 +22,10 @@ for elty in [Int32, Int64, Float32, Float64]
2522
y = sum(x, dims=2)
2623
dy = sum(dx, dims=2)
2724
@test y Array(dy)
25+
if elty in (Float32, Float64)
26+
dy = mapreduce(abs, +, dx; init=zero(elty))
27+
y = mapreduce(abs, +, x; init=zero(elty))
28+
@test y dy
29+
end
2830
end
2931
end
30-
31-
end

0 commit comments

Comments
 (0)