Skip to content

Commit f00d217

Browse files
committed
Move SuiteSparse to stdlib
Remove CHOLMOD stuff from precompile.jl Move unexported SparseArrays increment and decrement APIs to SuiteSparse Update SuiteSparse tests Add license text to new files.
1 parent 80d8719 commit f00d217

16 files changed

+70
-55
lines changed

base/precompile.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
precompile(Tuple{typeof(Base.pointer), Array{UInt8, 1}, UInt64})
1212
precompile(Tuple{typeof(Base.convert), Type{Ptr{Int32}}, Ptr{UInt8}})
13-
if USE_GPL_LIBS
14-
precompile(Tuple{typeof(Base.SparseArrays.CHOLMOD.set_print_level), Array{UInt8, 1}, Int64})
15-
end
1613
precompile(Tuple{Type{Base.Multimedia.TextDisplay}, Base.TTY})
1714
precompile(Tuple{typeof(Base._start)})
1815
precompile(Tuple{typeof(Base.copy!), Array{String, 1}, Int64, Array{Any, 1}, Int64, Int64})

base/sparse/linalg.jl

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,6 @@
22

33
import Base.LinAlg: checksquare
44

5-
## Functions to switch to 0-based indexing to call external sparse solvers
6-
7-
# Convert from 1-based to 0-based indices
8-
function decrement!(A::AbstractArray{T}) where T<:Integer
9-
for i in 1:length(A); A[i] -= oneunit(T) end
10-
A
11-
end
12-
decrement(A::AbstractArray{<:Integer}) = decrement!(copy(A))
13-
14-
# Convert from 0-based to 1-based indices
15-
function increment!(A::AbstractArray{T}) where T<:Integer
16-
for i in 1:length(A); A[i] += oneunit(T) end
17-
A
18-
end
19-
increment(A::AbstractArray{<:Integer}) = increment!(copy(A))
20-
215
## sparse matrix multiplication
226

237
function (*)(A::SparseMatrixCSC{TvA,TiA}, B::SparseMatrixCSC{TvB,TiB}) where {TvA,TiA,TvB,TiB}

base/sparse/sparse.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ include("abstractsparse.jl")
3838
include("sparsematrix.jl")
3939
include("sparsevector.jl")
4040
include("higherorderfns.jl")
41-
4241
include("linalg.jl")
43-
if Base.USE_GPL_LIBS
44-
include("umfpack.jl")
45-
include("cholmod.jl")
46-
include("spqr.jl")
47-
end
4842

4943
end

base/sysimg.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ unshift!(Base._included_files, (@__MODULE__, joinpath(@__DIR__, "sysimg.jl")))
490490
Base.require(:DelimitedFiles)
491491
Base.require(:Test)
492492
Base.require(:Dates)
493+
Base.require(:SuiteSparse)
493494

494495
empty!(LOAD_PATH)
495496

doc/src/manual/linear-algebra.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ of the standard library documentation.
275275
| `CholeskyPivoted` | [Pivoted](https://en.wikipedia.org/wiki/Pivot_element) Cholesky factorization |
276276
| `LU` | [LU factorization](https://en.wikipedia.org/wiki/LU_decomposition) |
277277
| `LUTridiagonal` | LU factorization for [`Tridiagonal`](@ref) matrices |
278-
| `UmfpackLU` | LU factorization for sparse matrices (computed by UMFPack) |
279278
| `QR` | [QR factorization](https://en.wikipedia.org/wiki/QR_decomposition) |
280279
| `QRCompactWY` | Compact WY form of the QR factorization |
281280
| `QRPivoted` | Pivoted [QR factorization](https://en.wikipedia.org/wiki/QR_decomposition) |

stdlib/SuiteSparse/src/SuiteSparse.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
module SuiteSparse
4+
5+
import Base: At_ldiv_B, Ac_ldiv_B, A_ldiv_B!
6+
import Base.LinAlg: At_ldiv_B!, Ac_ldiv_B!, A_rdiv_B!, A_rdiv_Bc!
7+
8+
## Functions to switch to 0-based indexing to call external sparse solvers
9+
10+
# Convert from 1-based to 0-based indices
11+
function decrement!(A::AbstractArray{T}) where T<:Integer
12+
for i in 1:length(A); A[i] -= oneunit(T) end
13+
A
14+
end
15+
decrement(A::AbstractArray{<:Integer}) = decrement!(copy(A))
16+
17+
# Convert from 0-based to 1-based indices
18+
function increment!(A::AbstractArray{T}) where T<:Integer
19+
for i in 1:length(A); A[i] += oneunit(T) end
20+
A
21+
end
22+
increment(A::AbstractArray{<:Integer}) = increment!(copy(A))
23+
24+
if Base.USE_GPL_LIBS
25+
include("umfpack.jl")
26+
include("cholmod.jl")
27+
include("spqr.jl")
28+
end
29+
30+
end # module SuiteSparse

base/sparse/cholmod.jl renamed to stdlib/SuiteSparse/src/cholmod.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ export
1616
Factor,
1717
Sparse
1818

19-
import ..SparseArrays: AbstractSparseMatrix, SparseMatrixCSC, increment, indtype, sparse,
20-
spzeros, nnz
19+
import ..SparseArrays: AbstractSparseMatrix, SparseMatrixCSC, indtype, sparse, spzeros, nnz
20+
21+
import ..increment, ..increment!, ..decrement, ..decrement!
2122

2223
#########
2324
# Setup #
File renamed without changes.

base/sparse/spqr.jl renamed to stdlib/SuiteSparse/src/spqr.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const ORDERING_BESTAMD = Int32(9) # try COLAMD and AMD; pick best#
2222
# the best of AMD and METIS. METIS is not tried if it isn't installed.
2323

2424
using ..SparseArrays: SparseMatrixCSC
25-
using ..SparseArrays.CHOLMOD
26-
using ..SparseArrays.CHOLMOD: change_stype!, free!
25+
using ..SuiteSparse.CHOLMOD
26+
using ..SuiteSparse.CHOLMOD: change_stype!, free!
2727

2828
function _qr!(ordering::Integer, tol::Real, econ::Integer, getCTX::Integer,
2929
A::Sparse{Tv},

base/sparse/umfpack.jl renamed to stdlib/SuiteSparse/src/umfpack.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import Base: (\), Ac_ldiv_B, At_ldiv_B, findnz, getindex, show, size
88
import Base.LinAlg: A_ldiv_B!, Ac_ldiv_B!, At_ldiv_B!, Factorization, det, lufact
99

1010
using ..SparseArrays
11-
import ..SparseArrays: increment, increment!, decrement, decrement!, nnz
11+
import ..SparseArrays: nnz
12+
13+
import ..increment, ..increment!, ..decrement, ..decrement!
1214

1315
include("umfpack_h.jl")
1416
struct MatrixIllConditionedException <: Exception
File renamed without changes.

test/sparse/cholmod.jl renamed to stdlib/SuiteSparse/test/cholmod.jl

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

3-
using Base.SparseArrays.CHOLMOD
3+
using SuiteSparse.CHOLMOD
44
using DelimitedFiles
55
using Test
66

@@ -328,8 +328,8 @@ end
328328
A1pdSparse = CHOLMOD.Sparse(
329329
A1pd.m,
330330
A1pd.n,
331-
Base.SparseArrays.decrement(A1pd.colptr),
332-
Base.SparseArrays.decrement(A1pd.rowval),
331+
SuiteSparse.decrement(A1pd.colptr),
332+
SuiteSparse.decrement(A1pd.rowval),
333333
A1pd.nzval)
334334

335335
## High level interface
@@ -584,7 +584,7 @@ end
584584
Asp = As[p,p]
585585
LDp = sparse(ldltfact(Asp, perm=[1,2,3])[:LD])
586586
# LDp = sparse(Fs[:LD])
587-
Lp, dp = Base.SparseArrays.CHOLMOD.getLd!(copy(LDp))
587+
Lp, dp = SuiteSparse.CHOLMOD.getLd!(copy(LDp))
588588
Dp = sparse(Diagonal(dp))
589589
@test Fs\b Af\b
590590
@test Fs[:UP]\(Fs[:PtLD]\b) Af\b
@@ -634,7 +634,7 @@ end
634634
end
635635

636636
@testset "Issue 14134" begin
637-
A = SparseArrays.CHOLMOD.Sparse(sprandn(10,5,0.1) + I |> t -> t't)
637+
A = CHOLMOD.Sparse(sprandn(10,5,0.1) + I |> t -> t't)
638638
b = IOBuffer()
639639
serialize(b, A)
640640
seekstart(b)
@@ -655,9 +655,9 @@ end
655655
end
656656

657657
@testset "Issue with promotion during conversion to CHOLMOD.Dense" begin
658-
@test SparseArrays.CHOLMOD.Dense(ones(Float32, 5)) == ones(5, 1)
659-
@test SparseArrays.CHOLMOD.Dense(ones(Int, 5)) == ones(5, 1)
660-
@test SparseArrays.CHOLMOD.Dense(ones(Complex{Float32}, 5, 2)) == ones(5, 2)
658+
@test CHOLMOD.Dense(ones(Float32, 5)) == ones(5, 1)
659+
@test CHOLMOD.Dense(ones(Int, 5)) == ones(5, 1)
660+
@test CHOLMOD.Dense(ones(Complex{Float32}, 5, 2)) == ones(5, 2)
661661
end
662662

663663
@testset "Further issue with promotion #14894" begin
@@ -719,7 +719,7 @@ end
719719

720720
@testset "Check that Symmetric{SparseMatrixCSC} can be constructed from CHOLMOD.Sparse" begin
721721
A = sprandn(10, 10, 0.1)
722-
B = SparseArrays.CHOLMOD.Sparse(A)
722+
B = CHOLMOD.Sparse(A)
723723
C = B'B
724724
# Change internal representation to symmetric (upper/lower)
725725
o = fieldoffset(CHOLMOD.C_Sparse{eltype(C)}, find(fieldnames(CHOLMOD.C_Sparse{eltype(C)}) .== :stype)[1])

stdlib/SuiteSparse/test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
using Test
4+
using SuiteSparse
5+
6+
if Base.USE_GPL_LIBS
7+
include("umfpack.jl")
8+
include("cholmod.jl")
9+
include("spqr.jl")
10+
end

test/sparse/spqr.jl renamed to stdlib/SuiteSparse/test/spqr.jl

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

3-
using Base.SparseArrays.SPQR
4-
using Base.SparseArrays.CHOLMOD
3+
using SuiteSparse.SPQR
4+
using SuiteSparse.CHOLMOD
55

66
@testset "Sparse QR" begin
77
m, n = 100, 10

test/sparse/umfpack.jl renamed to stdlib/SuiteSparse/test/umfpack.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
# based on deps/Suitesparse-4.0.2/UMFPACK/Demo/umfpack_di_demo.c
99

10-
using Base.SparseArrays.UMFPACK.increment!
10+
using SuiteSparse.increment!
1111

1212
A0 = sparse(increment!([0,4,1,1,2,2,0,1,2,3,4,4]),
1313
increment!([0,4,0,2,1,2,1,4,3,2,1,2]),
1414
[2.,1.,3.,4.,-1.,-3.,3.,6.,2.,1.,4.,2.], 5, 5)
1515

1616
@testset "Core functionality for $Tv elements" for Tv in (Float64, Complex128)
1717
# We might be able to support two index sizes one day
18-
for Ti in Base.uniontypes(Base.SparseArrays.UMFPACK.UMFITypes)
18+
for Ti in Base.uniontypes(SuiteSparse.UMFPACK.UMFITypes)
1919
A = convert(SparseMatrixCSC{Tv,Ti}, A0)
2020
lua = lufact(A)
2121
@test nnz(lua) == 18
@@ -31,7 +31,7 @@
3131

3232
@test A*x b
3333
z = complex.(b)
34-
x = Base.SparseArrays.A_ldiv_B!(lua, z)
34+
x = SuiteSparse.A_ldiv_B!(lua, z)
3535
@test x float([1:5;])
3636
@test z === x
3737
y = similar(z)
@@ -46,22 +46,22 @@
4646

4747
@test A'*x b
4848
z = complex.(b)
49-
x = Base.SparseArrays.Ac_ldiv_B!(lua, z)
49+
x = SuiteSparse.Ac_ldiv_B!(lua, z)
5050
@test x float([1:5;])
5151
@test x === z
5252
y = similar(x)
53-
Base.SparseArrays.Ac_ldiv_B!(y, lua, complex.(b))
53+
SuiteSparse.Ac_ldiv_B!(y, lua, complex.(b))
5454
@test y x
5555

5656
@test A'*x b
5757
x = lua.'\b
5858
@test x float([1:5;])
5959

6060
@test A.'*x b
61-
x = Base.SparseArrays.At_ldiv_B!(lua,complex.(b))
61+
x = SuiteSparse.At_ldiv_B!(lua,complex.(b))
6262
@test x float([1:5;])
6363
y = similar(x)
64-
Base.SparseArrays.At_ldiv_B!(y, lua,complex.(b))
64+
SuiteSparse.At_ldiv_B!(y, lua,complex.(b))
6565
@test y x
6666

6767
@test A.'*x b
@@ -73,7 +73,7 @@
7373

7474
@testset "More tests for complex cases" begin
7575
Ac0 = complex.(A0,A0)
76-
for Ti in Base.uniontypes(Base.SparseArrays.UMFPACK.UMFITypes)
76+
for Ti in Base.uniontypes(SuiteSparse.UMFPACK.UMFITypes)
7777
Ac = convert(SparseMatrixCSC{Complex128,Ti}, Ac0)
7878
x = complex.(ones(size(Ac, 1)), ones(size(Ac,1)))
7979
lua = lufact(Ac)
@@ -142,9 +142,9 @@
142142

143143
@testset "Test aliasing" begin
144144
a = rand(5)
145-
@test_throws ArgumentError Base.SparseArrays.UMFPACK.solve!(a, lufact(sparse(1.0I, 5, 5)), a, Base.SparseArrays.UMFPACK.UMFPACK_A)
145+
@test_throws ArgumentError SuiteSparse.UMFPACK.solve!(a, lufact(sparse(1.0I, 5, 5)), a, SuiteSparse.UMFPACK.UMFPACK_A)
146146
aa = complex(a)
147-
@test_throws ArgumentError Base.SparseArrays.UMFPACK.solve!(aa, lufact(sparse((1.0im)I, 5, 5)), aa, Base.SparseArrays.UMFPACK.UMFPACK_A)
147+
@test_throws ArgumentError SuiteSparse.UMFPACK.solve!(aa, lufact(sparse((1.0im)I, 5, 5)), aa, SuiteSparse.UMFPACK.UMFPACK_A)
148148
end
149149

150150
@testset "Issues #18246,18244 - lufact sparse pivot" begin

test/choosetests.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ function choosetests(choices = [])
9999
end
100100

101101
sparsetests = ["sparse/sparse", "sparse/sparsevector", "sparse/higherorderfns"]
102-
if Base.USE_GPL_LIBS
103-
append!(sparsetests, ["sparse/umfpack", "sparse/cholmod", "sparse/spqr"])
104-
end
105102
if "sparse" in skip_tests
106103
filter!(x -> (x != "sparse" && !(x in sparsetests)), tests)
107104
elseif "sparse" in tests

0 commit comments

Comments
 (0)