Skip to content

Commit dd94814

Browse files
committed
Add error
1 parent 998d4db commit dd94814

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

ext/SparseMatrixColoringsCUDAExt.jl

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,36 @@ end
100100
for R in (:ColumnColoringResult, :RowColoringResult, :StarSetColoringResult)
101101
# loop to avoid method ambiguity
102102
@eval function SMC.decompress!(
103-
A::CuSparseMatrixCSC, B::CuMatrix, result::SMC.$R{<:CuSparseMatrixCSC}
103+
A::CuSparseMatrixCSC,
104+
B::CuMatrix,
105+
result::SMC.$R{<:CuSparseMatrixCSC},
106+
uplo::Symbol=:F,
104107
)
108+
if uplo != :F
109+
throw(
110+
SMC.UnsupportedDecompressionError(
111+
"Single-triangle decompression is not supported on GPU matrices"
112+
),
113+
)
114+
end
105115
compressed_indices = result.additional_info.compressed_indices_gpu_csc
106116
copyto!(A.nzVal, view(B, compressed_indices))
107117
return A
108118
end
109119

110120
@eval function SMC.decompress!(
111-
A::CuSparseMatrixCSR, B::CuMatrix, result::SMC.$R{<:CuSparseMatrixCSR}
121+
A::CuSparseMatrixCSR,
122+
B::CuMatrix,
123+
result::SMC.$R{<:CuSparseMatrixCSR},
124+
uplo::Symbol=:F,
112125
)
126+
if uplo != :F
127+
throw(
128+
SMC.UnsupportedDecompressionError(
129+
"Single-triangle decompression is not supported on GPU matrices"
130+
),
131+
)
132+
end
113133
compressed_indices = result.additional_info.compressed_indices_gpu_csr
114134
copyto!(A.nzVal, view(B, compressed_indices))
115135
return A

src/decompression.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ function compress(
106106
return Br, Bc
107107
end
108108

109+
struct UnsupportedDecompressionError
110+
msg::String
111+
end
112+
113+
function Base.showerror(io::IO, err::UnsupportedDecompressionError)
114+
return print(io, "UnsupportedDecompressionError: $(err.msg)")
115+
end
116+
109117
"""
110118
decompress(B::AbstractMatrix, result::AbstractColoringResult{_,:column/:row})
111119
decompress(Br::AbstractMatrix, Bc::AbstractMatrix, result::AbstractColoringResult{_,:bidirectional})

test/cuda.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using CUDA.CUSPARSE: CuSparseMatrixCSC, CuSparseMatrixCSR
22
using LinearAlgebra
33
using SparseArrays
44
using SparseMatrixColorings
5+
import SparseMatrixColorings as SMC
56
using StableRNGs
67
using Test
78

@@ -51,5 +52,11 @@ end;
5152
A0 = T(sparse(Symmetric(sprand(rng, n, n, p))))
5253
test_coloring_decompression(A0, problem, algo; gpu=true)
5354
end
55+
A0 = T(sparse(Diagonal(ones(10))))
56+
result = coloring(A0, problem, algo)
57+
B = compress(A0, result)
58+
@test_throws SMC.UnsupportedDecompressionError decompress!(
59+
similar(A0), B, result, :U
60+
)
5461
end
5562
end;

test/result.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using SparseMatrixColorings: group_by_color
1+
using SparseMatrixColorings: group_by_color, UnsupportedDecompressionError
22
using Test
33

44
@testset "Group by color" begin
@@ -31,3 +31,8 @@ end
3131
B = compress(A, coloring(A, problem, algo))
3232
@test size(B, 1) == 0
3333
end
34+
35+
@testset "Errors" begin
36+
e = SparseMatrixColorings.UnsupportedDecompressionError("hello")
37+
@test sprint(showerror, e) == "UnsupportedDecompressionError: hello"
38+
end

0 commit comments

Comments
 (0)