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

WIP: move csparse functions to separate package #16070

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ their own licenses:
The following components of Julia's standard library have separate licenses:

- base/fftw.jl (see [FFTW](http://fftw.org/doc/License-and-Copyright.html))
- base/sparse/csparse.jl (LGPL-2.1+)
- base/linalg/umfpack.jl (see [SUITESPARSE](http://faculty.cse.tamu.edu/davis/suitesparse.html))
- base/linalg/cholmod.jl (see [SUITESPARSE](http://faculty.cse.tamu.edu/davis/suitesparse.html))

Expand Down
53 changes: 52 additions & 1 deletion base/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export AbstractSparseArray, AbstractSparseMatrix, AbstractSparseVector,
include("sparse/abstractsparse.jl")
include("sparse/sparsematrix.jl")
include("sparse/sparsevector.jl")
include("sparse/csparse.jl")

include("sparse/linalg.jl")
if Base.USE_GPL_LIBS
Expand All @@ -45,4 +44,56 @@ if Base.USE_GPL_LIBS
include("sparse/spqr.jl")
end

# point users to SuiteSparse
const SUITESPARSE_END_STRING = string(" has been moved to the package SuiteSparse.jl.\n",
"Run Pkg.add(\"SuiteSparse\") to install SuiteSparse on Julia v0.5-")

"""
etree(A[, post])
Compute the elimination tree of a symmetric sparse matrix `A` from `triu(A)`
and, optionally, its post-ordering permutation.
Note: This function has been moved to the SuiteSparse.jl package.
"""
function etree{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, postorder::Bool)
if isdefined(Main, :SuiteSparse)
Main.SuiteSparse.etree(A, postorder)
else
error("etree(A[, post])", SUITESPARSE_END_STRING)
end
end

etree(A::SparseMatrixCSC) = etree(A, false)

function ereach{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, k::Integer, parent::Vector{Ti})
if isdefined(Main, :SuiteSparse)
Main.SuiteSparse.ereach(A, k, parent)
else
error("ereach(A, k, parent)", SUITESPARSE_END_STRING)
end
end

function csc_permute{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, pinv::Vector{Ti}, q::Vector{Ti})
if isdefined(Main, :SuiteSparse)
Main.SuiteSparse.csc_permute(A, pinv, q)
else
error("csc_permute(A, pinv, q)", SUITESPARSE_END_STRING)
end
end

"""
symperm(A, p)
Return the symmetric permutation of `A`, which is `A[p,p]`. `A` should be
symmetric, sparse, and only contain nonzeros in the upper triangular part of the
matrix is stored. This algorithm ignores the lower triangular part of the
matrix. Only the upper triangular part of the result is returned.
Note: This function has been moved to the SuiteSparse.jl package.
"""
function symperm{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, pinv::Vector{Ti})
if isdefined(Main, :SuiteSparse)
Main.SuiteSparse.symperm(A, pinv)
else
error("symperm(A, pinv)", SUITESPARSE_END_STRING)
end
end

end
178 changes: 0 additions & 178 deletions base/sparse/csparse.jl

This file was deleted.

1 change: 0 additions & 1 deletion contrib/add_license_to_files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const skipfiles = [
# files to check - already copyright
# see: https://github.com/JuliaLang/julia/pull/11073#issuecomment-98099389
"../base/special/trig.jl",
"../base/sparse/csparse.jl",
"../base/linalg/givens.jl",
#
"../src/abi_llvm.cpp",
Expand Down
4 changes: 4 additions & 0 deletions doc/stdlib/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -958,12 +958,16 @@ dense counterparts. The following functions are specific to sparse arrays.

Compute the elimination tree of a symmetric sparse matrix ``A`` from ``triu(A)`` and, optionally, its post-ordering permutation.

Note: This function has been moved to the SuiteSparse.jl package.

.. function:: symperm(A, p)

.. Docstring generated from Julia source

Return the symmetric permutation of ``A``\ , which is ``A[p,p]``\ . ``A`` should be symmetric, sparse, and only contain nonzeros in the upper triangular part of the matrix is stored. This algorithm ignores the lower triangular part of the matrix. Only the upper triangular part of the result is returned.

Note: This function has been moved to the SuiteSparse.jl package.

.. function:: nonzeros(A)

.. Docstring generated from Julia source
Expand Down
28 changes: 2 additions & 26 deletions test/sparsedir/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,20 +343,6 @@ end
@test full(spdiagm((ones(2), ones(2)), (0, -1), 3, 3)) ==
[1.0 0.0 0.0; 1.0 1.0 0.0; 0.0 1.0 0.0]

# elimination tree
## upper triangle of the pattern test matrix from Figure 4.2 of
## "Direct Methods for Sparse Linear Systems" by Tim Davis, SIAM, 2006
rowval = Int32[1,2,2,3,4,5,1,4,6,1,7,2,5,8,6,9,3,4,6,8,10,3,5,7,8,10,11]
colval = Int32[1,2,3,3,4,5,6,6,6,7,7,8,8,8,9,9,10,10,10,10,10,11,11,11,11,11,11]
A = sparse(rowval, colval, ones(length(rowval)))
p = etree(A)
P,post = etree(A, true)
@test P == p
@test P == Int32[6,3,8,6,8,7,9,10,10,11,0]
@test post == Int32[2,3,5,8,1,4,6,7,9,10,11]
@test isperm(post)


# issue #4986, reinterpret
sfe22 = speye(Float64, 2)
mfe22 = eye(Float64, 2)
Expand Down Expand Up @@ -1019,13 +1005,9 @@ A = sparse(tril(rand(5,5)))
@test istril(A)
@test !istril(sparse(ones(5,5)))

# symperm
srand(1234321)
A = triu(sprand(10,10,0.2)) # symperm operates on upper triangle
perm = randperm(10)
@test symperm(A,perm).colptr == [1,1,2,4,5,5,6,8,8,9,10]

# droptol
srand(1234321)
A = triu(sprand(10,10,0.2))
@test Base.droptol!(A,0.01).colptr == [1,1,1,2,2,3,4,6,6,7,9]
@test isequal(Base.droptol!(sparse([1], [1], [1]), 1), SparseMatrixCSC(1,1,Int[1,1],Int[],Int[]))

Expand Down Expand Up @@ -1224,12 +1206,6 @@ if Base.USE_GPL_LIBS
end
@test_throws DimensionMismatch Base.SparseArrays.normestinv(sprand(3,5,.9))

# csc_permute
A = sprand(10,10,0.2)
p = randperm(10)
q = randperm(10)
@test Base.SparseArrays.csc_permute(A, invperm(p), q) == full(A)[p, q]

# issue #13008
@test_throws ArgumentError sparse(collect(1:100), collect(1:100), fill(5,100), 5, 5)
@test_throws ArgumentError sparse(Int[], collect(1:5), collect(1:5))
Expand Down