Skip to content

Commit b26030e

Browse files
authored
Even more sparse printing and tril/triu tests (#2692)
* Even more sparse printing and tril/triu tests * Fix show method and its test
1 parent 22305bd commit b26030e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/cusparse/array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ for (gpu, cpu) in [:CuSparseMatrixCSC => :SparseMatrixCSC,
667667
end
668668
end
669669

670-
function Base.show(io::IOContext, ::MIME"text/plain", A::CuSparseArrayCSR)
670+
function Base.show(io::IO, ::MIME"text/plain", A::CuSparseArrayCSR)
671671
xnnz = nnz(A)
672672
dims = join(size(A), "×")
673673

test/libraries/cusparse.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ blockdim = 5
5454
CUDA.@allowscalar begin
5555
@test sprint(show, MIME"text/plain"(), d_x) == replace(sprint(show, MIME"text/plain"(), x), "SparseMatrixCSC{Float64, Int64}"=>"CuSparseMatrixCSC{Float64, Int32}")
5656
@test Array(d_x[:]) == x[:]
57+
@test d_x[:, :] == x[:, :]
58+
@test d_x[(1, 1)] == x[1, 1]
5759
@test d_x[firstindex(d_x)] == x[firstindex(x)]
5860
@test d_x[div(end, 2)] == x[div(end, 2)]
5961
@test d_x[end] == x[end]
@@ -130,6 +132,9 @@ blockdim = 5
130132
@test reshape(repeat(d_x, 1, 1, 3), size(d_x, 1), size(d_x, 2), 3, 1, 1) isa CuSparseArrayCSR
131133
# to hit the CuSparseArrayCSR path
132134
CUDA.unsafe_free!(repeat(d_x, 1, 1, 3))
135+
CUDA.@allowscalar begin
136+
@test startswith(sprint(show, MIME"text/plain"(), repeat(d_x, 1, 1, 2)), "$m×$n×2 CuSparseArrayCSR{Float64, Int32, 3} with $(2*nnz(d_x)) stored entries:\n")
137+
end
133138
@test length(d_x) == m*n
134139
@test_throws ArgumentError copyto!(d_y,d_x)
135140
CUDA.@allowscalar begin
@@ -173,6 +178,18 @@ blockdim = 5
173178
d_x = LowerTriangular(CuSparseMatrixCSC(x))
174179
@test !istriu(d_x)
175180
@test istril(d_x)
181+
d_x = UpperTriangular(triu(transpose(CuSparseMatrixCSC(x)), 1))
182+
@test istriu(d_x)
183+
@test !istril(d_x)
184+
d_x = UpperTriangular(triu(adjoint(CuSparseMatrixCSC(x)), 1))
185+
@test istriu(d_x)
186+
@test !istril(d_x)
187+
d_x = LowerTriangular(tril(transpose(CuSparseMatrixCSC(x)), -1))
188+
@test !istriu(d_x)
189+
@test istril(d_x)
190+
d_x = LowerTriangular(tril(adjoint(CuSparseMatrixCSC(x)), -1))
191+
@test !istriu(d_x)
192+
@test istril(d_x)
176193

177194
A = sprand(n, n, 0.2)
178195
d_A = CuSparseMatrixCSC(A)

0 commit comments

Comments
 (0)