Skip to content

Commit

Permalink
alg -> method; :divid -> :divideandconquer
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenbauer committed Feb 15, 2019
1 parent 7bac471 commit 539ba37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Standard library changes
* Eigenvalues λ of general matrices are now sorted lexicographically by (Re λ, Im λ) ([#21598]).
* `one` for structured matrices (`Diagonal`, `Bidiagonal`, `Tridiagonal`, `Symtridiagonal`) now preserves
structure and type. ([#29777])
* Added keyword argument `alg` to `svd` and `svd!` that allows one to switch between different SVD algorithms ([#31057]).
* Added keyword argument `method` to `svd` and `svd!` that allows one to switch between different SVD algorithms ([#31057]).

#### SparseArrays

Expand Down
34 changes: 17 additions & 17 deletions stdlib/LinearAlgebra/src/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Base.iterate(S::SVD, ::Val{:V}) = (S.V, Val(:done))
Base.iterate(S::SVD, ::Val{:done}) = nothing

"""
svd!(A; full::Bool = false, alg::Symbol = :divide) -> SVD
svd!(A; full::Bool = false, method::Symbol = :divideandconquer) -> SVD
`svd!` is the same as [`svd`](@ref), but saves space by
overwriting the input `A`, instead of creating a copy.
Expand Down Expand Up @@ -55,25 +55,25 @@ julia> A
0.0 0.0 -2.0 0.0 0.0
```
"""
function svd!(A::StridedMatrix{T}; full::Bool = false, alg::Symbol=:divide) where T<:BlasFloat
function svd!(A::StridedMatrix{T}; full::Bool = false, method::Symbol=:divideandconquer) where T<:BlasFloat
m,n = size(A)
if m == 0 || n == 0
u,s,vt = (Matrix{T}(I, m, full ? m : n), real(zeros(T,0)), Matrix{T}(I, n, n))
else
if alg == :divide
if method == :divideandconquer
u,s,vt = LAPACK.gesdd!(full ? 'A' : 'S', A)
elseif alg == :simple
elseif method == :simple
c = full ? 'A' : 'S'
u,s,vt = LAPACK.gesvd!(c, c, A)
else
throw(ArgumentError("Unsupported value for `alg` keyword. Only `:divide` and `:simple` are supported."))
throw(ArgumentError("Unsupported value for `method` keyword. Only `:divideandconquer` and `:simple` are supported."))
end
end
SVD(u,s,vt)
end

"""
svd(A; full::Bool = false, alg::Symbol = :divide) -> SVD
svd(A; full::Bool = false, method::Symbol = :divideandconquer) -> SVD
Compute the singular value decomposition (SVD) of `A` and return an `SVD` object.
Expand All @@ -90,8 +90,8 @@ and `V` is `N \\times N`, while in the thin factorization `U` is `M
\\times K` and `V` is `N \\times K`, where `K = \\min(M,N)` is the
number of singular values.
If `alg = :divide` (default) a divide-and-conquer algorithm is used to calculate the SVD.
One can set `alg = :simple` to use a simple (typically slower) driver instead.
If `method = :divideandconquer` (default) a divide-and-conquer algorithm is used to calculate the SVD.
One can set `method = :simple` to use a simple (typically slower) method instead.
# Examples
```jldoctest
Expand All @@ -112,21 +112,21 @@ julia> F.U * Diagonal(F.S) * F.Vt
0.0 2.0 0.0 0.0 0.0
```
"""
function svd(A::StridedVecOrMat{T}; full::Bool = false, alg::Symbol = :divide) where T
svd!(copy_oftype(A, eigtype(T)), full = full, alg = alg)
function svd(A::StridedVecOrMat{T}; full::Bool = false, method::Symbol = :divideandconquer) where T
svd!(copy_oftype(A, eigtype(T)), full = full, method = method)
end
function svd(x::Number; full::Bool = false, alg::Symbol = :divide)
function svd(x::Number; full::Bool = false, method::Symbol = :divideandconquer)
SVD(x == 0 ? fill(one(x), 1, 1) : fill(x/abs(x), 1, 1), [abs(x)], fill(one(x), 1, 1))
end
function svd(x::Integer; full::Bool = false, alg::Symbol = :divide)
svd(float(x), full = full, alg = alg)
function svd(x::Integer; full::Bool = false, method::Symbol = :divideandconquer)
svd(float(x), full = full, method = method)
end
function svd(A::Adjoint; full::Bool = false, alg::Symbol = :divide)
s = svd(A.parent, full = full, alg = alg)
function svd(A::Adjoint; full::Bool = false, method::Symbol = :divideandconquer)
s = svd(A.parent, full = full, method = method)
return SVD(s.Vt', s.S, s.U')
end
function svd(A::Transpose; full::Bool = false, alg::Symbol = :divide)
s = svd(A.parent, full = full, alg = alg)
function svd(A::Transpose; full::Bool = false, method::Symbol = :divideandconquer)
s = svd(A.parent, full = full, method = method)
return SVD(transpose(s.Vt), s.S, transpose(s.U))
end

Expand Down

0 comments on commit 539ba37

Please sign in to comment.