Skip to content

Commit 176ef64

Browse files
authored
move USE_GPL_LIBS check to the solver files (#154)
* move USE_GPL_LIBS check to the solver files * include all the solvers tests in testgroups
1 parent ee38766 commit 176ef64

13 files changed

+209
-159
lines changed

test/ambiguous.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
using Test, LinearAlgebra, SparseArrays
4+
5+
@testset "detect_ambiguities" begin
6+
@test_nowarn detect_ambiguities(SparseArrays; recursive=true, ambiguous_bottom=false)
7+
end
8+
9+
## This was the older version that was disabled
10+
11+
# let ambig = detect_ambiguities(SparseArrays; recursive=true)
12+
# @test isempty(ambig)
13+
# ambig = Set{Any}(((m1.sig, m2.sig) for (m1, m2) in ambig))
14+
# expect = []
15+
# good = true
16+
# while !isempty(ambig)
17+
# sigs = pop!(ambig)
18+
# i = findfirst(==(sigs), expect)
19+
# if i === nothing
20+
# println(stderr, "push!(expect, (", sigs[1], ", ", sigs[2], "))")
21+
# good = false
22+
# continue
23+
# end
24+
# deleteat!(expect, i)
25+
# end
26+
# @test isempty(expect)
27+
# @test good
28+
# end

test/ambiguous_exec.jl.disable

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/basetests.jl

Lines changed: 0 additions & 110 deletions
This file was deleted.

test/solvers/cholmod.jl renamed to test/cholmod.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
module CHOLMODTests
4+
5+
using Test
36
using SparseArrays.CHOLMOD
47
using DelimitedFiles
5-
using Test
68
using Random
79
using Serialization
810
using LinearAlgebra:
@@ -14,6 +16,8 @@ using SparseArrays: getcolptr
1416
using SparseArrays.LibSuiteSparse
1517
using SparseArrays.LibSuiteSparse: SuiteSparse_long
1618

19+
if Base.USE_GPL_LIBS
20+
1721
# CHOLMOD tests
1822
Random.seed!(123)
1923

@@ -914,3 +918,7 @@ end
914918
@test getproperty(current_common[], name) == getproperty(default_common[], name)
915919
end
916920
end
921+
922+
end # Base.USE_GPL_LIBS
923+
924+
end # module

test/issues.jl

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ end
378378
F = lu(Tridiagonal(sparse(1.0I, 3, 3)))
379379
@test F.L == Matrix(I, 3, 3)
380380
@test startswith(sprint(show, MIME("text/plain"), F),
381-
"$(LinearAlgebra.LU){Float64, $(LinearAlgebra.Tridiagonal){Float64, SparseArrays.SparseVector")
381+
"$(LinearAlgebra.LU){Float64, $(LinearAlgebra.Tridiagonal){Float64, $(SparseArrays.SparseVector)")
382382
end
383383

384384
@testset "reverse search direction if step < 0 #21986" begin
@@ -606,4 +606,119 @@ end
606606
@test A[1,1] == 2
607607
end
608608

609-
end
609+
# As part of the migration of SparseArrays.jl into its own repo,
610+
# these tests have been moved from other files in julia tests to
611+
# the SparseArrays.jl repo
612+
613+
module SparseTestsBase
614+
615+
using Test
616+
using Random, LinearAlgebra, SparseArrays
617+
618+
# From arrayops.jl
619+
620+
@testset "copy!" begin
621+
@testset "AbstractVector" begin
622+
s = Vector([1, 2])
623+
for a = ([1], UInt[1], [3, 4, 5], UInt[3, 4, 5])
624+
@test s === copy!(s, SparseVector(a)) == Vector(a)
625+
end
626+
end
627+
end
628+
629+
@testset "CartesianIndex" begin
630+
a = spzeros(2,3)
631+
@test CartesianIndices(size(a)) == eachindex(a)
632+
a[CartesianIndex{2}(2,3)] = 5
633+
@test a[2,3] == 5
634+
b = view(a, 1:2, 2:3)
635+
b[CartesianIndex{2}(1,1)] = 7
636+
@test a[1,2] == 7
637+
end
638+
639+
@testset "Assignment of singleton array to sparse array (julia #43644)" begin
640+
K = spzeros(3,3)
641+
b = zeros(3,3)
642+
b[3,:] = [1,2,3]
643+
K[3,1:3] += [1.0 2.0 3.0]'
644+
@test K == b
645+
K[3:3,1:3] += zeros(1, 3)
646+
@test K == b
647+
K[3,1:3] += zeros(3)
648+
@test K == b
649+
K[3,:] += zeros(3,1)
650+
@test K == b
651+
@test_throws DimensionMismatch K[3,1:2] += [1.0 2.0 3.0]'
652+
end
653+
654+
# From abstractarray.jl
655+
656+
@testset "julia #17088" begin
657+
n = 10
658+
M = rand(n, n)
659+
@testset "vector of vectors" begin
660+
v = [[M]; [M]] # using vcat
661+
@test size(v) == (2,)
662+
@test !issparse(v)
663+
end
664+
@testset "matrix of vectors" begin
665+
m1 = [[M] [M]] # using hcat
666+
m2 = [[M] [M];] # using hvcat
667+
@test m1 == m2
668+
@test size(m1) == (1,2)
669+
@test !issparse(m1)
670+
@test !issparse(m2)
671+
end
672+
end
673+
674+
@testset "mapslices julia #21123" begin
675+
@test mapslices(nnz, sparse(1.0I, 3, 3), dims=1) == [1 1 1]
676+
end
677+
678+
@testset "itr, iterate" begin
679+
r = sparse(2:3:8)
680+
itr = eachindex(r)
681+
y = iterate(itr)
682+
@test y !== nothing
683+
y = iterate(itr, y[2])
684+
y = iterate(itr, y[2])
685+
@test y !== nothing
686+
val, state = y
687+
@test r[val] == 8
688+
@test iterate(itr, state) == nothing
689+
end
690+
691+
# From core.jl
692+
693+
# issue #12960
694+
mutable struct T12960 end
695+
import Base.zero
696+
Base.zero(::Type{T12960}) = T12960()
697+
Base.zero(x::T12960) = T12960()
698+
let
699+
A = sparse(1.0I, 3, 3)
700+
B = similar(A, T12960)
701+
@test repr(B) == "sparse([1, 2, 3], [1, 2, 3], $T12960[#undef, #undef, #undef], 3, 3)"
702+
@test occursin(
703+
"\n #undef ⋅ ⋅ \n ⋅ #undef ⋅ \n ⋅ ⋅ #undef",
704+
repr(MIME("text/plain"), B),
705+
)
706+
707+
B[1,2] = T12960()
708+
@test repr(B) == "sparse([1, 1, 2, 3], [1, 2, 2, 3], $T12960[#undef, $T12960(), #undef, #undef], 3, 3)"
709+
@test occursin(
710+
"\n #undef T12960() ⋅ \n ⋅ #undef ⋅ \n ⋅ ⋅ #undef",
711+
repr(MIME("text/plain"), B),
712+
)
713+
end
714+
715+
# julia issue #12063
716+
# NOTE: should have > MAX_TUPLETYPE_LEN arguments
717+
f12063(tt, g, p, c, b, v, cu::T, d::AbstractArray{T, 2}, ve) where {T} = 1
718+
f12063(args...) = 2
719+
g12063() = f12063(0, 0, 0, 0, 0, 0, 0.0, spzeros(0,0), Int[])
720+
@test g12063() == 1
721+
722+
end
723+
724+
end # module

test/solvers/linalg_tests.jl renamed to test/linalg_solvers.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
module SparseLinalgSolversTests
4+
5+
using Test
6+
using SparseArrays
7+
using Random
8+
using LinearAlgebra
9+
10+
if Base.USE_GPL_LIBS
11+
112
@testset "explicit zeros" begin
213
a = SparseMatrixCSC(2, 2, [1, 3, 5], [1, 2, 1, 2], [1.0, 0.0, 0.0, 1.0])
314
@test lu(a)\[2.0, 3.0] [2.0, 3.0]
@@ -171,3 +182,7 @@ end
171182
@test_throws ErrorException eigen(A)
172183
@test_throws ErrorException inv(A)
173184
end
185+
186+
end # Base.USE_GPL_LIBS
187+
188+
end # module

test/runtests.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,19 @@
33
for file in readlines(joinpath(@__DIR__, "testgroups"))
44
include(file * ".jl")
55
end
6-
include("basetests.jl")
6+
77
if Base.USE_GPL_LIBS
8-
include("solvers/ambiguous.jl")
9-
include("solvers/umfpack.jl")
10-
include("solvers/cholmod.jl")
11-
include("solvers/spqr.jl")
12-
include("solvers/linalg_tests.jl")
138

149
# Test multithreaded execution
1510
@testset "threaded SuiteSparse tests" verbose = true begin
1611
@testset "threads = $(Threads.nthreads())" begin
17-
include("solvers/threads.jl")
12+
include("threads.jl")
1813
end
1914
# test both nthreads==1 and nthreads>1. spawn a process to test whichever
2015
# case we are not running currently.
2116
other_nthreads = Threads.nthreads() == 1 ? 4 : 1
2217
@testset "threads = $other_nthreads" begin
23-
let p, cmd = `$(Base.julia_cmd()) --depwarn=error --startup-file=no solvers/threads.jl`
18+
let p, cmd = `$(Base.julia_cmd()) --depwarn=error --startup-file=no threads.jl`
2419
p = run(
2520
pipeline(
2621
setenv(
@@ -38,4 +33,5 @@ if Base.USE_GPL_LIBS
3833
end
3934
end
4035
end
36+
4137
end

test/solvers/ambiguous.jl

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)