Skip to content
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

Move suitesparse to stdlib #24648

Merged
merged 1 commit into from
Nov 24, 2017
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
3 changes: 0 additions & 3 deletions base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

precompile(Tuple{typeof(Base.pointer), Array{UInt8, 1}, UInt64})
precompile(Tuple{typeof(Base.convert), Type{Ptr{Int32}}, Ptr{UInt8}})
if USE_GPL_LIBS
precompile(Tuple{typeof(Base.SparseArrays.CHOLMOD.set_print_level), Array{UInt8, 1}, Int64})
end
precompile(Tuple{Type{Base.Multimedia.TextDisplay}, Base.TTY})
precompile(Tuple{typeof(Base._start)})
precompile(Tuple{typeof(Base.copy!), Array{String, 1}, Int64, Array{Any, 1}, Int64, Int64})
Expand Down
16 changes: 0 additions & 16 deletions base/sparse/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@

import Base.LinAlg: checksquare

## Functions to switch to 0-based indexing to call external sparse solvers

# Convert from 1-based to 0-based indices
function decrement!(A::AbstractArray{T}) where T<:Integer
for i in 1:length(A); A[i] -= oneunit(T) end
A
end
decrement(A::AbstractArray{<:Integer}) = decrement!(copy(A))

# Convert from 0-based to 1-based indices
function increment!(A::AbstractArray{T}) where T<:Integer
for i in 1:length(A); A[i] += oneunit(T) end
A
end
increment(A::AbstractArray{<:Integer}) = increment!(copy(A))

## sparse matrix multiplication

function (*)(A::SparseMatrixCSC{TvA,TiA}, B::SparseMatrixCSC{TvB,TiB}) where {TvA,TiA,TvB,TiB}
Expand Down
6 changes: 0 additions & 6 deletions base/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ include("abstractsparse.jl")
include("sparsematrix.jl")
include("sparsevector.jl")
include("higherorderfns.jl")

include("linalg.jl")
if Base.USE_GPL_LIBS
include("umfpack.jl")
include("cholmod.jl")
include("spqr.jl")
end

end
1 change: 1 addition & 0 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ unshift!(Base._included_files, (@__MODULE__, joinpath(@__DIR__, "sysimg.jl")))
Base.require(:DelimitedFiles)
Base.require(:Test)
Base.require(:Dates)
Base.require(:SuiteSparse)

empty!(LOAD_PATH)

Expand Down
1 change: 0 additions & 1 deletion doc/src/manual/linear-algebra.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ of the standard library documentation.
| `CholeskyPivoted` | [Pivoted](https://en.wikipedia.org/wiki/Pivot_element) Cholesky factorization |
| `LU` | [LU factorization](https://en.wikipedia.org/wiki/LU_decomposition) |
| `LUTridiagonal` | LU factorization for [`Tridiagonal`](@ref) matrices |
| `UmfpackLU` | LU factorization for sparse matrices (computed by UMFPack) |
| `QR` | [QR factorization](https://en.wikipedia.org/wiki/QR_decomposition) |
| `QRCompactWY` | Compact WY form of the QR factorization |
| `QRPivoted` | Pivoted [QR factorization](https://en.wikipedia.org/wiki/QR_decomposition) |
Expand Down
30 changes: 30 additions & 0 deletions stdlib/SuiteSparse/src/SuiteSparse.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module SuiteSparse

import Base: At_ldiv_B, Ac_ldiv_B, A_ldiv_B!
import Base.LinAlg: At_ldiv_B!, Ac_ldiv_B!, A_rdiv_B!, A_rdiv_Bc!

## Functions to switch to 0-based indexing to call external sparse solvers

# Convert from 1-based to 0-based indices
function decrement!(A::AbstractArray{T}) where T<:Integer
for i in 1:length(A); A[i] -= oneunit(T) end
A
end
decrement(A::AbstractArray{<:Integer}) = decrement!(copy(A))

# Convert from 0-based to 1-based indices
function increment!(A::AbstractArray{T}) where T<:Integer
for i in 1:length(A); A[i] += oneunit(T) end
A
end
increment(A::AbstractArray{<:Integer}) = increment!(copy(A))

if Base.USE_GPL_LIBS
include("umfpack.jl")
include("cholmod.jl")
include("spqr.jl")
end

end # module SuiteSparse
5 changes: 3 additions & 2 deletions base/sparse/cholmod.jl → stdlib/SuiteSparse/src/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export
Factor,
Sparse

import ..SparseArrays: AbstractSparseMatrix, SparseMatrixCSC, increment, indtype, sparse,
spzeros, nnz
import ..SparseArrays: AbstractSparseMatrix, SparseMatrixCSC, indtype, sparse, spzeros, nnz

import ..increment, ..increment!, ..decrement, ..decrement!

#########
# Setup #
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions base/sparse/spqr.jl → stdlib/SuiteSparse/src/spqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const ORDERING_BESTAMD = Int32(9) # try COLAMD and AMD; pick best#
# the best of AMD and METIS. METIS is not tried if it isn't installed.

using ..SparseArrays: SparseMatrixCSC
using ..SparseArrays.CHOLMOD
using ..SparseArrays.CHOLMOD: change_stype!, free!
using ..SuiteSparse.CHOLMOD
using ..SuiteSparse.CHOLMOD: change_stype!, free!

function _qr!(ordering::Integer, tol::Real, econ::Integer, getCTX::Integer,
A::Sparse{Tv},
Expand Down
4 changes: 3 additions & 1 deletion base/sparse/umfpack.jl → stdlib/SuiteSparse/src/umfpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import Base: (\), Ac_ldiv_B, At_ldiv_B, findnz, getindex, show, size
import Base.LinAlg: A_ldiv_B!, Ac_ldiv_B!, At_ldiv_B!, Factorization, det, lufact

using ..SparseArrays
import ..SparseArrays: increment, increment!, decrement, decrement!, nnz
import ..SparseArrays: nnz

import ..increment, ..increment!, ..decrement, ..decrement!

include("umfpack_h.jl")
struct MatrixIllConditionedException <: Exception
Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions test/sparse/cholmod.jl → stdlib/SuiteSparse/test/cholmod.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Base.SparseArrays.CHOLMOD
using SuiteSparse.CHOLMOD
using DelimitedFiles
using Test

Expand Down Expand Up @@ -328,8 +328,8 @@ end
A1pdSparse = CHOLMOD.Sparse(
A1pd.m,
A1pd.n,
Base.SparseArrays.decrement(A1pd.colptr),
Base.SparseArrays.decrement(A1pd.rowval),
SuiteSparse.decrement(A1pd.colptr),
SuiteSparse.decrement(A1pd.rowval),
A1pd.nzval)

## High level interface
Expand Down Expand Up @@ -584,7 +584,7 @@ end
Asp = As[p,p]
LDp = sparse(ldltfact(Asp, perm=[1,2,3])[:LD])
# LDp = sparse(Fs[:LD])
Lp, dp = Base.SparseArrays.CHOLMOD.getLd!(copy(LDp))
Lp, dp = SuiteSparse.CHOLMOD.getLd!(copy(LDp))
Dp = sparse(Diagonal(dp))
@test Fs\b ≈ Af\b
@test Fs[:UP]\(Fs[:PtLD]\b) ≈ Af\b
Expand Down Expand Up @@ -634,7 +634,7 @@ end
end

@testset "Issue 14134" begin
A = SparseArrays.CHOLMOD.Sparse(sprandn(10,5,0.1) + I |> t -> t't)
A = CHOLMOD.Sparse(sprandn(10,5,0.1) + I |> t -> t't)
b = IOBuffer()
serialize(b, A)
seekstart(b)
Expand All @@ -655,9 +655,9 @@ end
end

@testset "Issue with promotion during conversion to CHOLMOD.Dense" begin
@test SparseArrays.CHOLMOD.Dense(ones(Float32, 5)) == ones(5, 1)
@test SparseArrays.CHOLMOD.Dense(ones(Int, 5)) == ones(5, 1)
@test SparseArrays.CHOLMOD.Dense(ones(Complex{Float32}, 5, 2)) == ones(5, 2)
@test CHOLMOD.Dense(ones(Float32, 5)) == ones(5, 1)
@test CHOLMOD.Dense(ones(Int, 5)) == ones(5, 1)
@test CHOLMOD.Dense(ones(Complex{Float32}, 5, 2)) == ones(5, 2)
end

@testset "Further issue with promotion #14894" begin
Expand Down Expand Up @@ -724,7 +724,7 @@ end

@testset "Check that Symmetric{SparseMatrixCSC} can be constructed from CHOLMOD.Sparse" begin
A = sprandn(10, 10, 0.1)
B = SparseArrays.CHOLMOD.Sparse(A)
B = CHOLMOD.Sparse(A)
C = B'B
# Change internal representation to symmetric (upper/lower)
o = fieldoffset(CHOLMOD.C_Sparse{eltype(C)}, find(fieldnames(CHOLMOD.C_Sparse{eltype(C)}) .== :stype)[1])
Expand Down
10 changes: 10 additions & 0 deletions stdlib/SuiteSparse/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Test
using SuiteSparse

if Base.USE_GPL_LIBS
include("umfpack.jl")
include("cholmod.jl")
include("spqr.jl")
end
4 changes: 2 additions & 2 deletions test/sparse/spqr.jl → stdlib/SuiteSparse/test/spqr.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Base.SparseArrays.SPQR
using Base.SparseArrays.CHOLMOD
using SuiteSparse.SPQR
using SuiteSparse.CHOLMOD

@testset "Sparse QR" begin
m, n = 100, 10
Expand Down
20 changes: 10 additions & 10 deletions test/sparse/umfpack.jl → stdlib/SuiteSparse/test/umfpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

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

using Base.SparseArrays.UMFPACK.increment!
using SuiteSparse.increment!

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

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

@test A*x ≈ b
z = complex.(b)
x = Base.SparseArrays.A_ldiv_B!(lua, z)
x = SuiteSparse.A_ldiv_B!(lua, z)
@test x ≈ float([1:5;])
@test z === x
y = similar(z)
Expand All @@ -46,22 +46,22 @@

@test A'*x ≈ b
z = complex.(b)
x = Base.SparseArrays.Ac_ldiv_B!(lua, z)
x = SuiteSparse.Ac_ldiv_B!(lua, z)
@test x ≈ float([1:5;])
@test x === z
y = similar(x)
Base.SparseArrays.Ac_ldiv_B!(y, lua, complex.(b))
SuiteSparse.Ac_ldiv_B!(y, lua, complex.(b))
@test y ≈ x

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

@test A.'*x ≈ b
x = Base.SparseArrays.At_ldiv_B!(lua,complex.(b))
x = SuiteSparse.At_ldiv_B!(lua,complex.(b))
@test x ≈ float([1:5;])
y = similar(x)
Base.SparseArrays.At_ldiv_B!(y, lua,complex.(b))
SuiteSparse.At_ldiv_B!(y, lua,complex.(b))
@test y ≈ x

@test A.'*x ≈ b
Expand All @@ -73,7 +73,7 @@

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

@testset "Test aliasing" begin
a = rand(5)
@test_throws ArgumentError Base.SparseArrays.UMFPACK.solve!(a, lufact(sparse(1.0I, 5, 5)), a, Base.SparseArrays.UMFPACK.UMFPACK_A)
@test_throws ArgumentError SuiteSparse.UMFPACK.solve!(a, lufact(sparse(1.0I, 5, 5)), a, SuiteSparse.UMFPACK.UMFPACK_A)
aa = complex(a)
@test_throws ArgumentError Base.SparseArrays.UMFPACK.solve!(aa, lufact(sparse((1.0im)I, 5, 5)), aa, Base.SparseArrays.UMFPACK.UMFPACK_A)
@test_throws ArgumentError SuiteSparse.UMFPACK.solve!(aa, lufact(sparse((1.0im)I, 5, 5)), aa, SuiteSparse.UMFPACK.UMFPACK_A)
end

@testset "Issues #18246,18244 - lufact sparse pivot" begin
Expand Down
3 changes: 0 additions & 3 deletions test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ function choosetests(choices = [])
end

sparsetests = ["sparse/sparse", "sparse/sparsevector", "sparse/higherorderfns"]
if Base.USE_GPL_LIBS
append!(sparsetests, ["sparse/umfpack", "sparse/cholmod", "sparse/spqr"])
end
if "sparse" in skip_tests
filter!(x -> (x != "sparse" && !(x in sparsetests)), tests)
elseif "sparse" in tests
Expand Down
2 changes: 1 addition & 1 deletion test/compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ try
[:Base, :Core, Foo2_module, FooBase_module, :Main, :Test]),
# plus modules included in the system image
Dict(s => Base.module_uuid(Base.root_module(s)) for s in
[:DelimitedFiles, :Mmap, :Base64, :Dates]))
[:DelimitedFiles, :Mmap, :Base64, :Dates, :SuiteSparse]))
@test discard_module.(deps) == deps1

@test current_task()(0x01, 0x4000, 0x30031234) == 2
Expand Down