Skip to content

Commit 8c02b43

Browse files
authored
Fix and test opnorm for sparse (#650)
* Fix and test opnorm for sparse * Use sprandn * Don't use linalg tests with complex int * Fix subtype check * Just don't do Ints for linalg tests
1 parent a5b0bbd commit 8c02b43

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/host/sparse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function LinearAlgebra.opnorm(A::AbstractGPUSparseMatrixCSR, p::Real=2)
7575
end
7676
end
7777

78-
LinearAlgebra.opnorm(A::AbstractGPUSparseMatrixCSC, p::Real=2) = opnorm(_csr_type(A)(A), p)
78+
LinearAlgebra.opnorm(A::AbstractGPUSparseMatrixCSC, p::Real=2) = opnorm(csr_type(A)(A), p)
7979

8080
function LinearAlgebra.norm(A::AbstractGPUSparseMatrix{T}, p::Real=2) where T
8181
if p == Inf

test/testsuite/sparse.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
matrix_construction(sparse_AT, eltypes)
1111
broadcasting_matrix(sparse_AT, eltypes)
1212
mapreduce_matrix(sparse_AT, eltypes)
13+
linalg(sparse_AT, eltypes)
1314
end
1415
end
1516
end
@@ -336,3 +337,27 @@ function mapreduce_matrix(AT, eltypes)
336337
end
337338
end
338339
end
340+
341+
function linalg(AT, eltypes)
342+
dense_AT = GPUArrays.dense_array_type(AT)
343+
for ET in eltypes
344+
# sprandn doesn't work nicely with these...
345+
if !(ET <: Union{Int16, Int32, Int64, Complex{Int16}, Complex{Int32}, Complex{Int64}})
346+
@testset "Sparse matrix($ET) linear algebra" begin
347+
m = 10
348+
A = sprandn(ET, m, m, 0.2)
349+
B = sprandn(ET, m, m, 0.3)
350+
ZA = spzeros(ET, m, m)
351+
C = I(div(m, 2))
352+
dA = AT(A)
353+
dB = AT(B)
354+
dZA = AT(ZA)
355+
@testset "opnorm and norm" begin
356+
@test opnorm(A, Inf) opnorm(dA, Inf)
357+
@test opnorm(A, 1) opnorm(dA, 1)
358+
@test_throws ArgumentError opnorm(dA, 2)
359+
end
360+
end
361+
end
362+
end
363+
end

0 commit comments

Comments
 (0)