Skip to content

Commit

Permalink
Move Arnoldi iteration to the stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Nov 23, 2017
1 parent 80d8719 commit 1f2e5cd
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 24 deletions.
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,9 @@ export conv, conv2, deconv, filt, filt!, xcorr
@eval @deprecate_moved $(Symbol("@dateformat_str")) "Dates" true true
@deprecate_moved now "Dates" true true

@deprecate_moved eigs "Arnoldi" true true
@deprecate_moved svds "Arnoldi" true true

# PR #21709
@deprecate cov(x::AbstractVector, corrected::Bool) cov(x, corrected=corrected)
@deprecate cov(x::AbstractMatrix, vardim::Int, corrected::Bool) cov(x, vardim, corrected=corrected)
Expand Down
2 changes: 0 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ export
eigfact,
eigmax,
eigmin,
eigs,
eigvals,
eigvals!,
eigvecs,
Expand Down Expand Up @@ -602,7 +601,6 @@ export
svd,
svdfact!,
svdfact,
svds,
svdvals!,
svdvals,
sylvester,
Expand Down
5 changes: 0 additions & 5 deletions base/linalg/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export
eigfact!,
eigmax,
eigmin,
eigs,
eigvals,
eigvals!,
eigvecs,
Expand Down Expand Up @@ -131,7 +130,6 @@ export
svd,
svdfact!,
svdfact,
svds,
svdvals!,
svdvals,
sylvester,
Expand Down Expand Up @@ -277,9 +275,6 @@ include("ldlt.jl")
include("schur.jl")


include("arpack.jl")
include("arnoldi.jl")

function __init__()
try
BLAS.check()
Expand Down
2 changes: 1 addition & 1 deletion base/sparse/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ end

chol(A::SparseMatrixCSC) = error("Use cholfact() instead of chol() for sparse matrices.")
lu(A::SparseMatrixCSC) = error("Use lufact() instead of lu() for sparse matrices.")
eig(A::SparseMatrixCSC) = error("Use eigs() instead of eig() for sparse matrices.")
eig(A::SparseMatrixCSC) = error("Use Arnoldi.eigs() instead of eig() for sparse matrices.")

function Base.cov(X::SparseMatrixCSC, vardim::Int=1; corrected::Bool=true)
a, b = size(X)
Expand Down
9 changes: 7 additions & 2 deletions doc/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if Sys.iswindows()
cp_q("../stdlib/FileWatching/docs/src/index.md", "src/stdlib/filewatching.md")
cp_q("../stdlib/CRC32c/docs/src/index.md", "src/stdlib/crc32c.md")
cp_q("../stdlib/Dates/docs/src/index.md", "src/stdlib/dates.md")
cp_q("../stdlib/Arnoldi/docs/src/index.md", "src/stdlib/arnoldi.md")
else
symlink_q("../../../stdlib/DelimitedFiles/docs/src/index.md", "src/stdlib/delimitedfiles.md")
symlink_q("../../../stdlib/Test/docs/src/index.md", "src/stdlib/test.md")
Expand All @@ -40,6 +41,7 @@ else
symlink_q("../../../stdlib/FileWatching/docs/src/index.md", "src/stdlib/filewatching.md")
symlink_q("../../../stdlib/CRC32c/docs/src/index.md", "src/stdlib/crc32c.md")
symlink_q("../../../stdlib/Dates/docs/src/index.md", "src/stdlib/dates.md")
symlink_q("../../../stdlib/Arnoldi/docs/src/index.md", "src/stdlib/arnoldi.md")
end

const PAGES = [
Expand Down Expand Up @@ -114,6 +116,7 @@ const PAGES = [
"stdlib/sharedarrays.md",
"stdlib/filewatching.md",
"stdlib/crc32c.md",
"stdlib/arnoldi.md",
],
"Developer Documentation" => [
"devdocs/reflection.md",
Expand Down Expand Up @@ -148,11 +151,13 @@ const PAGES = [
],
]

using DelimitedFiles, Test, Mmap, SharedArrays, Profile, Base64, FileWatching, CRC32c, Dates
using DelimitedFiles, Test, Mmap, SharedArrays, Profile, Base64, FileWatching, CRC32c,
Dates, Arnoldi

makedocs(
build = joinpath(pwd(), "_build/html/en"),
modules = [Base, Core, BuildSysImg, DelimitedFiles, Test, Mmap, SharedArrays, Profile, Base64, FileWatching, Dates],
modules = [Base, Core, BuildSysImg, DelimitedFiles, Test, Mmap, SharedArrays, Profile,
Base64, FileWatching, Dates, Arnoldi],
clean = false,
doctest = "doctest" in ARGS,
linkcheck = "linkcheck" in ARGS,
Expand Down
1 change: 1 addition & 0 deletions doc/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
* [Shared Arrays](@ref)
* [Base64](@ref)
* [File Events](@ref lib-filewatching)
* [Arnoldi Iteration](@ref lib-arnoldi)

## Developer Documentation

Expand Down
1 change: 1 addition & 0 deletions doc/src/stdlib/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
* [Shared Arrays](@ref)
* [Base64](@ref)
* [File Events](@ref lib-filewatching)
* [Arnoldi Iteration](@ref lib-arnoldi)
3 changes: 0 additions & 3 deletions doc/src/stdlib/linalg.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ Base.transpose
Base.transpose!
Base.adjoint
Base.adjoint!
Base.LinAlg.eigs(::Any)
Base.LinAlg.eigs(::Any, ::Any)
Base.LinAlg.svds
Base.LinAlg.peakflops
Base.LinAlg.stride1
```
Expand Down
7 changes: 7 additions & 0 deletions stdlib/Arnoldi/docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# [Arnoldi Iteration](@id lib-arnoldi)

```@docs
Arnoldi.eigs(::Any)
Arnoldi.eigs(::Any, ::Any)
Arnoldi.svds
```
25 changes: 19 additions & 6 deletions base/linalg/arnoldi.jl → stdlib/Arnoldi/src/Arnoldi.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

"""
Arnoldi and Lanczos iteration for computing eigenvalues
"""
module Arnoldi

using Base.LinAlg: BlasFloat, BlasInt, SVD, checksquare

export eigs, svds

include("arpack.jl")

using .ARPACK

## eigs
Expand Down Expand Up @@ -308,14 +319,14 @@ function SVDAugmented(A::AbstractMatrix{T}) where T
SVDAugmented{Tnew,typeof(Anew)}(Anew)
end

function A_mul_B!(y::StridedVector{T}, A::SVDAugmented{T}, x::StridedVector{T}) where T
function Base.A_mul_B!(y::StridedVector{T}, A::SVDAugmented{T}, x::StridedVector{T}) where T
m, mn = size(A.X, 1), length(x)
A_mul_B!( view(y, 1:m), A.X, view(x, m + 1:mn)) # left singular vector
Ac_mul_B!(view(y, m + 1:mn), A.X, view(x, 1:m)) # right singular vector
return y
end
size(A::SVDAugmented) = ((+)(size(A.X)...), (+)(size(A.X)...))
ishermitian(A::SVDAugmented) = true
Base.size(A::SVDAugmented) = ((+)(size(A.X)...), (+)(size(A.X)...))
Base.ishermitian(A::SVDAugmented) = true

struct AtA_or_AAt{T,S} <: AbstractArray{T, 2}
A::S
Expand All @@ -328,7 +339,7 @@ function AtA_or_AAt(A::AbstractMatrix{T}) where T
AtA_or_AAt{Tnew,typeof(Anew)}(Anew, Vector{Tnew}(max(size(A)...)))
end

function A_mul_B!(y::StridedVector{T}, A::AtA_or_AAt{T}, x::StridedVector{T}) where T
function Base.A_mul_B!(y::StridedVector{T}, A::AtA_or_AAt{T}, x::StridedVector{T}) where T
if size(A.A, 1) >= size(A.A, 2)
A_mul_B!(A.buffer, A.A, x)
return Ac_mul_B!(y, A.A, A.buffer)
Expand All @@ -337,8 +348,8 @@ function A_mul_B!(y::StridedVector{T}, A::AtA_or_AAt{T}, x::StridedVector{T}) wh
return A_mul_B!(y, A.A, A.buffer)
end
end
size(A::AtA_or_AAt) = ntuple(i -> min(size(A.A)...), Val(2))
ishermitian(s::AtA_or_AAt) = true
Base.size(A::AtA_or_AAt) = ntuple(i -> min(size(A.A)...), Val(2))
Base.ishermitian(s::AtA_or_AAt) = true


svds(A::AbstractMatrix{<:BlasFloat}; kwargs...) = _svds(A; kwargs...)
Expand Down Expand Up @@ -433,3 +444,5 @@ function _svds(X; nsv::Int = 6, ritzvec::Bool = true, tol::Float64 = 0.0, maxite
ex[2], ex[3], ex[4], ex[5])
end
end

end # module
File renamed without changes.
1 change: 1 addition & 0 deletions test/linalg/arnoldi.jl → stdlib/Arnoldi/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Arnoldi
using Test

@testset "eigs" begin
Expand Down
3 changes: 0 additions & 3 deletions test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ function choosetests(choices = [])
"linalg/generic", "linalg/uniformscaling", "linalg/lq",
"linalg/hessenberg", "linalg/rowvector", "linalg/conjarray",
"linalg/blas"]
if Base.USE_GPL_LIBS
push!(linalgtests, "linalg/arnoldi")
end

if "linalg" in skip_tests
filter!(x -> (x != "linalg" && !(x in linalgtests)), tests)
Expand Down
4 changes: 2 additions & 2 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,9 @@ let repr = sprint(show, "text/html", methods(f16580))
end

if isempty(Base.GIT_VERSION_INFO.commit)
@test contains(Base.url(first(methods(eigs))),"https://github.com/JuliaLang/julia/tree/v$VERSION/base/linalg/arnoldi.jl#L")
@test contains(Base.url(first(methods(sin))),"https://github.com/JuliaLang/julia/tree/v$VERSION/base/mpfr.jl#L")
else
@test contains(Base.url(first(methods(eigs))),"https://github.com/JuliaLang/julia/tree/$(Base.GIT_VERSION_INFO.commit)/base/linalg/arnoldi.jl#L")
@test contains(Base.url(first(methods(sin))),"https://github.com/JuliaLang/julia/tree/$(Base.GIT_VERSION_INFO.commit)/base/mpfr.jl#L")
end

# print_matrix should be able to handle small and large objects easily, test by
Expand Down
1 change: 1 addition & 0 deletions test/stdlib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ cd(joinpath(JULIA_HOME,"..","share","julia","site","v$(VERSION.major).$(VERSION.
warn("Skipping Profile tests")
filter!(x -> (x != "Profile"), pkgs)
end
Base.USE_GPL_LIBS || filter!(x->x != "Arnoldi", pkgs)
Pkg.Entry.test(convert(Vector{AbstractString}, pkgs))
end

0 comments on commit 1f2e5cd

Please sign in to comment.