Skip to content

Commit 1882d61

Browse files
authored
1.10: Fixed tests for builds without GPL SuiteSparse (#698)
GPL-dependent test imports are gated on Base.USE_GPL_LIBS so the test suite no longer references solver bindings that are unavailable in non-GPL builds. The non-GPL factorization tests fall back to ordinary sparse LU and QR paths, which need mutable SparseMatrixCSC inputs rather than fixed-structure matrices. FixedSparseCSC therefore gains the copy and conversion behavior needed for sparse(a) to produce a normal SparseMatrixCSC and keep those fallback test paths working.
1 parent 08b8168 commit 1882d61

5 files changed

Lines changed: 53 additions & 12 deletions

File tree

src/sparsematrix.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,14 @@ copy(S::AbstractSparseMatrixCSC) =
555555
SparseMatrixCSC(size(S, 1), size(S, 2), copy(getcolptr(S)), copy(rowvals(S)), copy(nonzeros(S)))
556556
copy(S::FixedSparseCSC) =
557557
FixedSparseCSC(size(S, 1), size(S, 2), getcolptr(S), rowvals(S), copy(nonzeros(S)))
558+
function copyto!(A::FixedSparseCSC, B::FixedSparseCSC)
559+
size(A) == size(B) || throw(DimensionMismatch("cannot copy sparse matrix with different dimensions into FixedSparseCSC"))
560+
nnz(A) == nnz(B) || throw(ArgumentError("cannot change fixed sparse structure via copyto!"))
561+
copyto!(parent(getcolptr(A)), getcolptr(B))
562+
copyto!(parent(rowvals(A)), rowvals(B))
563+
copyto!(nonzeros(A), nonzeros(B))
564+
return A
565+
end
558566
function copyto!(A::AbstractSparseMatrixCSC, B::AbstractSparseMatrixCSC)
559567
# If the two matrices have the same length then all the
560568
# elements in A will be overwritten.
@@ -712,6 +720,10 @@ uninitialized values for the nonzero locations.
712720
similar(S::AbstractSparseMatrixCSC{<:Any,Ti}, ::Type{TvNew}) where {Ti,TvNew} =
713721
@if_move_fixed S _sparsesimilar(S, TvNew, Ti)
714722

723+
similar(S::FixedSparseCSC{<:Any,Ti}, ::Type{TvNew}, dims::Dims{2}) where {Ti,TvNew} =
724+
dims == size(S) ? move_fixed(_sparsesimilar(S, TvNew, Ti)) :
725+
move_fixed(_sparsesimilar(S, TvNew, Ti, dims))
726+
715727
similar(S::AbstractSparseMatrixCSC{<:Any,Ti}, ::Type{TvNew}, dims::Union{Dims{1},Dims{2}}) where {Ti,TvNew} =
716728
@if_move_fixed S _sparsesimilar(S, TvNew, Ti, dims)
717729

@@ -1008,6 +1020,7 @@ julia> sparse(A)
10081020
sparse(A::AbstractMatrix{Tv}) where {Tv} = convert(SparseMatrixCSC{Tv}, A)
10091021

10101022
sparse(S::AbstractSparseMatrixCSC) = copy(S)
1023+
sparse(S::FixedSparseCSC) = SparseMatrixCSC(S)
10111024

10121025
sparse(Q::AbstractQ) = SparseMatrixCSC(Q)
10131026

test/cholmod.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
module CHOLMODTests
44

55
using Test
6-
using SparseArrays.CHOLMOD
7-
using SparseArrays.CHOLMOD: getcommon
86
using Random
97
using Serialization
108
using LinearAlgebra:
@@ -13,10 +11,12 @@ using LinearAlgebra:
1311
PosDefException, ZeroPivotException
1412
using SparseArrays
1513
using SparseArrays: getcolptr
16-
using SparseArrays.LibSuiteSparse
17-
using SparseArrays.LibSuiteSparse: cholmod_l_allocate_sparse, cholmod_allocate_sparse
1814

1915
if Base.USE_GPL_LIBS
16+
using SparseArrays.CHOLMOD
17+
using SparseArrays.CHOLMOD: getcommon
18+
using SparseArrays.LibSuiteSparse
19+
using SparseArrays.LibSuiteSparse: cholmod_l_allocate_sparse, cholmod_allocate_sparse
2020

2121
# CHOLMOD tests
2222
itypes = sizeof(Int) == 4 ? (Int32,) : (Int32, Int64)

test/fixed.jl

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,26 @@ struct_eq(A::AbstractSparseVector, B::AbstractSparseVector) =
8989
B = similar(F)
9090
@test typeof(B) == typeof(F)
9191
@test struct_eq(B, F)
92+
93+
C = fixed(copy(A))
94+
copyto!(C, F)
95+
@test C == F
96+
@test struct_eq(C, F)
97+
98+
G = fixed(sparse([1.0 0.0; 0.0 2.0]))
99+
H = fixed(sparse([1.0 3.0; 0.0 2.0]))
100+
@test_throws DimensionMismatch copyto!(fixed(sprandn(9, 10, 0.3)), F)
101+
@test_throws ArgumentError copyto!(G, H)
102+
103+
Bsame = similar(F, Float32, size(F))
104+
@test Bsame isa FixedSparseCSC{Float32, eltype(rowvals(F))}
105+
@test _is_fixed(Bsame)
106+
@test struct_eq(Bsame, F)
107+
108+
Bdiff = similar(F, Float32, (size(F, 1) + 1, size(F, 2)))
109+
@test typeof(Bdiff) == typeof(Bsame)
110+
@test _is_fixed(Bdiff)
111+
@test size(Bdiff) == (size(F, 1) + 1, size(F, 2))
92112
end
93113
@testset "SparseMatrixCSC conversions" begin
94114
A = sprandn(10, 10, 0.3)
@@ -152,11 +172,18 @@ end
152172
@testset "Test factorization" begin
153173
b = sprandn(10, 10, 0.99) + I
154174
a = fixed(b)
155-
156-
@test (lu(a) \ randn(10); true)
157-
@test b == a
158-
@test (qr(a + a') \ randn(10); true)
159-
@test b == a
175+
@test sparse(a) isa SparseMatrixCSC
176+
177+
if Base.USE_GPL_LIBS
178+
@test (lu(a) \ randn(10); true)
179+
@test b == a
180+
@test (qr(a + a') \ randn(10); true)
181+
@test b == a
182+
else
183+
@test (lu(sparse(a)) \ randn(10); true)
184+
@test (qr(sparse(a + a')) \ randn(10); true)
185+
@test b == a
186+
end
160187
end
161188

162189
always_false(x...) = false

test/spqr.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
module SPQRTests
44

55
using Test
6-
using SparseArrays.SPQR
7-
using SparseArrays.CHOLMOD
86
using LinearAlgebra: I, istriu, norm, qr, rank, rmul!, lmul!, Adjoint, Transpose, ColumnNorm, RowMaximum, NoPivot
97
using SparseArrays: SparseArrays, sparse, sprandn, spzeros, SparseMatrixCSC
108
using Random: seed!
119

1210
# TODO REMOVE SECOND PREDICATE WITH SS7.1
1311
if Base.USE_GPL_LIBS
12+
using SparseArrays.SPQR
13+
using SparseArrays.CHOLMOD
1414
@testset "Sparse QR" begin
1515
m, n = 100, 10
1616
nn = 100

test/umfpack.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ using SparseArrays
88
using Serialization
99
using LinearAlgebra:
1010
LinearAlgebra, I, det, issuccess, ldiv!, lu, lu!, Transpose, SingularException, Diagonal, logabsdet
11-
using SparseArrays: nnz, sparse, sprand, sprandn, SparseMatrixCSC, UMFPACK, increment!
11+
using SparseArrays: nnz, sparse, sprand, sprandn, SparseMatrixCSC, increment!
1212
if Base.USE_GPL_LIBS
13+
using SparseArrays: UMFPACK
1314
function umfpack_report(l::UMFPACK.UmfpackLU)
1415
UMFPACK.umfpack_report_numeric(l, 0)
1516
UMFPACK.umfpack_report_symbolic(l, 0)

0 commit comments

Comments
 (0)