Skip to content

Commit

Permalink
Move SuiteSparse to stdlib
Browse files Browse the repository at this point in the history
Remove CHOLMOD stuff from precompile.jl
Move unexported SparseArrays increment and decrement APIs to SuiteSparse
Update SuiteSparse tests
Add license text to new files.
  • Loading branch information
ViralBShah committed Nov 22, 2017
1 parent 80d8719 commit e8a5775
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 46 deletions.
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 @@ -490,6 +490,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
File renamed without changes.
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 @@ -719,7 +719,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
6 changes: 3 additions & 3 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 Down Expand Up @@ -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
3 changes: 0 additions & 3 deletions test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,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

0 comments on commit e8a5775

Please sign in to comment.