Skip to content

move USE_GPL_LIBS check to the solver files #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions test/ambiguous.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Test, LinearAlgebra, SparseArrays

@testset "detect_ambiguities" begin
@test_nowarn detect_ambiguities(SparseArrays; recursive=true, ambiguous_bottom=false)
end

## This was the older version that was disabled

# let ambig = detect_ambiguities(SparseArrays; recursive=true)
# @test isempty(ambig)
# ambig = Set{Any}(((m1.sig, m2.sig) for (m1, m2) in ambig))
# expect = []
# good = true
# while !isempty(ambig)
# sigs = pop!(ambig)
# i = findfirst(==(sigs), expect)
# if i === nothing
# println(stderr, "push!(expect, (", sigs[1], ", ", sigs[2], "))")
# good = false
# continue
# end
# deleteat!(expect, i)
# end
# @test isempty(expect)
# @test good
# end
21 changes: 0 additions & 21 deletions test/ambiguous_exec.jl.disable

This file was deleted.

110 changes: 0 additions & 110 deletions test/basetests.jl

This file was deleted.

10 changes: 9 additions & 1 deletion test/solvers/cholmod.jl → test/cholmod.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module CHOLMODTests

using Test
using SparseArrays.CHOLMOD
using DelimitedFiles
using Test
using Random
using Serialization
using LinearAlgebra:
Expand All @@ -14,6 +16,8 @@ using SparseArrays: getcolptr
using SparseArrays.LibSuiteSparse
using SparseArrays.LibSuiteSparse: SuiteSparse_long

if Base.USE_GPL_LIBS

# CHOLMOD tests
Random.seed!(123)

Expand Down Expand Up @@ -914,3 +918,7 @@ end
@test getproperty(current_common[], name) == getproperty(default_common[], name)
end
end

end # Base.USE_GPL_LIBS

end # module
119 changes: 117 additions & 2 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ end
F = lu(Tridiagonal(sparse(1.0I, 3, 3)))
@test F.L == Matrix(I, 3, 3)
@test startswith(sprint(show, MIME("text/plain"), F),
"$(LinearAlgebra.LU){Float64, $(LinearAlgebra.Tridiagonal){Float64, SparseArrays.SparseVector")
"$(LinearAlgebra.LU){Float64, $(LinearAlgebra.Tridiagonal){Float64, $(SparseArrays.SparseVector)")
end

@testset "reverse search direction if step < 0 #21986" begin
Expand Down Expand Up @@ -606,4 +606,119 @@ end
@test A[1,1] == 2
end

end
# As part of the migration of SparseArrays.jl into its own repo,
# these tests have been moved from other files in julia tests to
# the SparseArrays.jl repo

module SparseTestsBase

using Test
using Random, LinearAlgebra, SparseArrays

# From arrayops.jl

@testset "copy!" begin
@testset "AbstractVector" begin
s = Vector([1, 2])
for a = ([1], UInt[1], [3, 4, 5], UInt[3, 4, 5])
@test s === copy!(s, SparseVector(a)) == Vector(a)
end
end
end

@testset "CartesianIndex" begin
a = spzeros(2,3)
@test CartesianIndices(size(a)) == eachindex(a)
a[CartesianIndex{2}(2,3)] = 5
@test a[2,3] == 5
b = view(a, 1:2, 2:3)
b[CartesianIndex{2}(1,1)] = 7
@test a[1,2] == 7
end

@testset "Assignment of singleton array to sparse array (julia #43644)" begin
K = spzeros(3,3)
b = zeros(3,3)
b[3,:] = [1,2,3]
K[3,1:3] += [1.0 2.0 3.0]'
@test K == b
K[3:3,1:3] += zeros(1, 3)
@test K == b
K[3,1:3] += zeros(3)
@test K == b
K[3,:] += zeros(3,1)
@test K == b
@test_throws DimensionMismatch K[3,1:2] += [1.0 2.0 3.0]'
end

# From abstractarray.jl

@testset "julia #17088" begin
n = 10
M = rand(n, n)
@testset "vector of vectors" begin
v = [[M]; [M]] # using vcat
@test size(v) == (2,)
@test !issparse(v)
end
@testset "matrix of vectors" begin
m1 = [[M] [M]] # using hcat
m2 = [[M] [M];] # using hvcat
@test m1 == m2
@test size(m1) == (1,2)
@test !issparse(m1)
@test !issparse(m2)
end
end

@testset "mapslices julia #21123" begin
@test mapslices(nnz, sparse(1.0I, 3, 3), dims=1) == [1 1 1]
end

@testset "itr, iterate" begin
r = sparse(2:3:8)
itr = eachindex(r)
y = iterate(itr)
@test y !== nothing
y = iterate(itr, y[2])
y = iterate(itr, y[2])
@test y !== nothing
val, state = y
@test r[val] == 8
@test iterate(itr, state) == nothing
end

# From core.jl

# issue #12960
mutable struct T12960 end
import Base.zero
Base.zero(::Type{T12960}) = T12960()
Base.zero(x::T12960) = T12960()
let
A = sparse(1.0I, 3, 3)
B = similar(A, T12960)
@test repr(B) == "sparse([1, 2, 3], [1, 2, 3], $T12960[#undef, #undef, #undef], 3, 3)"
@test occursin(
"\n #undef ⋅ ⋅ \n ⋅ #undef ⋅ \n ⋅ ⋅ #undef",
repr(MIME("text/plain"), B),
)

B[1,2] = T12960()
@test repr(B) == "sparse([1, 1, 2, 3], [1, 2, 2, 3], $T12960[#undef, $T12960(), #undef, #undef], 3, 3)"
@test occursin(
"\n #undef T12960() ⋅ \n ⋅ #undef ⋅ \n ⋅ ⋅ #undef",
repr(MIME("text/plain"), B),
)
end

# julia issue #12063
# NOTE: should have > MAX_TUPLETYPE_LEN arguments
f12063(tt, g, p, c, b, v, cu::T, d::AbstractArray{T, 2}, ve) where {T} = 1
f12063(args...) = 2
g12063() = f12063(0, 0, 0, 0, 0, 0, 0.0, spzeros(0,0), Int[])
@test g12063() == 1

end

end # module
15 changes: 15 additions & 0 deletions test/solvers/linalg_tests.jl → test/linalg_solvers.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module SparseLinalgSolversTests

using Test
using SparseArrays
using Random
using LinearAlgebra

if Base.USE_GPL_LIBS

@testset "explicit zeros" begin
a = SparseMatrixCSC(2, 2, [1, 3, 5], [1, 2, 1, 2], [1.0, 0.0, 0.0, 1.0])
@test lu(a)\[2.0, 3.0] ≈ [2.0, 3.0]
Expand Down Expand Up @@ -171,3 +182,7 @@ end
@test_throws ErrorException eigen(A)
@test_throws ErrorException inv(A)
end

end # Base.USE_GPL_LIBS

end # module
12 changes: 4 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@
for file in readlines(joinpath(@__DIR__, "testgroups"))
include(file * ".jl")
end
include("basetests.jl")

if Base.USE_GPL_LIBS
include("solvers/ambiguous.jl")
include("solvers/umfpack.jl")
include("solvers/cholmod.jl")
include("solvers/spqr.jl")
include("solvers/linalg_tests.jl")

# Test multithreaded execution
@testset "threaded SuiteSparse tests" verbose = true begin
@testset "threads = $(Threads.nthreads())" begin
include("solvers/threads.jl")
include("threads.jl")
end
# test both nthreads==1 and nthreads>1. spawn a process to test whichever
# case we are not running currently.
other_nthreads = Threads.nthreads() == 1 ? 4 : 1
@testset "threads = $other_nthreads" begin
let p, cmd = `$(Base.julia_cmd()) --depwarn=error --startup-file=no solvers/threads.jl`
let p, cmd = `$(Base.julia_cmd()) --depwarn=error --startup-file=no threads.jl`
p = run(
pipeline(
setenv(
Expand All @@ -38,4 +33,5 @@ if Base.USE_GPL_LIBS
end
end
end

end
6 changes: 0 additions & 6 deletions test/solvers/ambiguous.jl

This file was deleted.

Loading