Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Deprecate svdfact to svd.
  • Loading branch information
Sacha0 committed May 21, 2018
commit 45b4926739f18ec4ab16047df14446cd433735cd
7 changes: 5 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ This section lists changes that do not have deprecation warnings.
`CholeskyPivoted`, and `SuiteSparse.CHOLMOD.Factor` rather than
tuples of arrays or tuples of numbers or numbers ([#27159]).

* `svd` methods now return decomposition objects such as `SVD` and
`GeneralizedSVD` rather than tuples of arrays or tuples of numbers ([#27159]).

* `countlines` now always counts the last non-empty line even if it does not
end with EOL, matching the behavior of `eachline` and `readlines` ([#25845]).

Expand Down Expand Up @@ -695,8 +698,8 @@ Deprecated or removed
`type` is fully deprecated to `mutable struct` ([#19157], [#20418]).

* `lufact`, `eigfact`, `schurfact`, `lqfact`, `qrfact`, `bkfact`, `cholfact`,
`ldltfact`, and `hessfact` have respectively been deprecated to `lu`, `eig`,
`schur`, `lq`, `qr`, `bk`, `chol`, `ldlt`, and `hess` ([#27159]).
`ldltfact`, `hessfact`, and `svdfact` have respectively been deprecated to
`lu`, `eig`, `schur`, `lq`, `qr`, `bk`, `chol`, `ldlt`, `hess`, and `svd` ([#27159]).

* `lufact!`, `eigfact!`, `schurfact!`, `lqfact!`, `qrfact!`, `cholfact!`,
`bkfact!`, `ldltfact!`, `hessfact!`, and `svdfact!` have respectively been
Expand Down
4 changes: 2 additions & 2 deletions doc/src/manual/parallel-computing.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ we could compute the singular values of several large random matrices in paralle
```julia-repl
julia> M = Matrix{Float64}[rand(1000,1000) for i = 1:10];

julia> pmap(svd, M);
julia> pmap(svdvals, M);
```

Julia's [`pmap`](@ref) is designed for the case where each function call does a large amount
Expand Down Expand Up @@ -486,7 +486,7 @@ As an example, consider computing the singular values of matrices of different s
```julia-repl
julia> M = Matrix{Float64}[rand(800,800), rand(600,600), rand(800,800), rand(600,600)];

julia> pmap(svd, M);
julia> pmap(svdvals, M);
```

If one process handles both 800×800 matrices and another handles both 600×600 matrices, we will
Expand Down
4 changes: 2 additions & 2 deletions doc/src/manual/performance-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ function norm(A)
if isa(A, Vector)
return sqrt(real(dot(A,A)))
elseif isa(A, Matrix)
return maximum(svd(A)[2])
return maximum(svdvals(A))
else
error("norm: invalid argument")
end
Expand All @@ -555,7 +555,7 @@ This can be written more concisely and efficiently as:

```julia
norm(x::Vector) = sqrt(real(dot(x,x)))
norm(A::Matrix) = maximum(svd(A)[2])
norm(A::Matrix) = maximum(svdvals(A))
```

## Write "type-stable" functions
Expand Down
4 changes: 2 additions & 2 deletions stdlib/Distributed/test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ end
n = 10
as = [rand(4,4) for i in 1:n]
bs = deepcopy(as)
cs = collect(Distributed.pgenerate(x->(sleep(rand()*0.1); svdfact(x)), bs))
svdas = map(svdfact, as)
cs = collect(Distributed.pgenerate(x->(sleep(rand()*0.1); svd(x)), bs))
svdas = map(svd, as)
for i in 1:n
@test cs[i].U ≈ svdas[i].U
@test cs[i].S ≈ svdas[i].S
Expand Down
16 changes: 8 additions & 8 deletions stdlib/IterativeEigensolvers/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ end
S2 = svd(Array(A))

## singular values match:
@test S1[1].S ≈ S2[2][1:2]
@test S1[1].S ≈ S2.S[1:2]
@testset "singular vectors" begin
## 1st left singular vector
s1_left = sign(S1[1].U[3,1]) * S1[1].U[:,1]
s2_left = sign(S2[1][3,1]) * S2[1][:,1]
s2_left = sign(S2.U[3,1]) * S2.U[:,1]
@test s1_left ≈ s2_left

## 1st right singular vector
s1_right = sign(S1[1].V[3,1]) * S1[1].V[:,1]
s2_right = sign(S2[3][3,1]) * S2[3][:,1]
s2_right = sign(S2.V[3,1]) * S2.V[:,1]
@test s1_right ≈ s2_right
end
# Issue number 10329
Expand All @@ -213,7 +213,7 @@ end
end
@testset "passing guess for Krylov vectors" begin
S1 = svds(A, nsv = 2, v0=rand(eltype(A),size(A,2)))
@test S1[1].S ≈ S2[2][1:2]
@test S1[1].S ≈ S2.S[1:2]
end

@test_throws ArgumentError svds(A,nsv=0)
Expand Down Expand Up @@ -251,21 +251,21 @@ end
S2 = svd(Array(A))

## singular values match:
@test S1[1].S ≈ S2[2][1:2]
@test S1[1].S ≈ S2.S[1:2]
@testset "singular vectors" begin
## left singular vectors
s1_left = abs.(S1[1].U[:,1:2])
s2_left = abs.(S2[1][:,1:2])
s2_left = abs.(S2.U[:,1:2])
@test s1_left ≈ s2_left

## right singular vectors
s1_right = abs.(S1[1].V[:,1:2])
s2_right = abs.(S2[3][:,1:2])
s2_right = abs.(S2.V[:,1:2])
@test s1_right ≈ s2_right
end
@testset "passing guess for Krylov vectors" begin
S1 = svds(A, nsv = 2, v0=rand(eltype(A),size(A,2)))
@test S1[1].S ≈ S2[2][1:2]
@test S1[1].S ≈ S2.S[1:2]
end

@test_throws ArgumentError svds(A,nsv=0)
Expand Down
3 changes: 1 addition & 2 deletions stdlib/LinearAlgebra/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,8 @@ LinearAlgebra.schur!
LinearAlgebra.schur
LinearAlgebra.ordschur
LinearAlgebra.ordschur!
LinearAlgebra.svdfact
LinearAlgebra.svd!
LinearAlgebra.svd
LinearAlgebra.svd!
LinearAlgebra.svdvals
LinearAlgebra.svdvals!
LinearAlgebra.Givens
Expand Down
1 change: 0 additions & 1 deletion stdlib/LinearAlgebra/src/LinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export
schur!,
svd,
svd!,
svdfact,
svdvals!,
svdvals,
sylvester,
Expand Down
6 changes: 3 additions & 3 deletions stdlib/LinearAlgebra/src/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ function svd!(M::Bidiagonal{<:BlasReal}; full::Bool = false, thin::Union{Bool,No
d, e, U, Vt, Q, iQ = LAPACK.bdsdc!(M.uplo, 'I', M.dv, M.ev)
SVD(U, d, Vt)
end
function svdfact(M::Bidiagonal; full::Bool = false, thin::Union{Bool,Nothing} = nothing)
function svd(M::Bidiagonal; full::Bool = false, thin::Union{Bool,Nothing} = nothing)
# DEPRECATION TODO: remove deprecated thin argument and associated logic after 0.7
if thin != nothing
Base.depwarn(string("the `thin` keyword argument in `svdfact(A; thin = $(thin))` has ",
Base.depwarn(string("the `thin` keyword argument in `svd(A; thin = $(thin))` has ",
"been deprecated in favor of `full`, which has the opposite meaning, ",
"e.g. `svdfact(A; full = $(!thin))`."), :svdfact)
"e.g. `svd(A; full = $(!thin))`."), :svd)
full::Bool = !thin
end
return svd!(copy(M), full = full)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ function pinv(A::StridedMatrix{T}, tol::Real) where T
return B
end
end
SVD = svdfact(A, full = false)
SVD = svd(A, full = false)
Stype = eltype(SVD.S)
Sinv = zeros(Stype, length(SVD.S))
index = SVD.S .> tol*maximum(SVD.S)
Expand Down Expand Up @@ -1344,7 +1344,7 @@ julia> nullspace(M, 2)
function nullspace(A::StridedMatrix, tol::Real = min(size(A)...)*eps(real(float(one(eltype(A))))))
m, n = size(A)
(m == 0 || n == 0) && return Matrix{T}(I, n, n)
SVD = svdfact(A, full=true)
SVD = svd(A, full=true)
indstart = sum(SVD.S .> SVD.S[1]*tol) + 1
return copy(SVD.Vt[indstart:end,:]')
end
Expand Down
12 changes: 12 additions & 0 deletions stdlib/LinearAlgebra/src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1397,3 +1397,15 @@ export svdfact!
@deprecate(svdfact!(A::StridedMatrix{T}; full::Bool = false, thin::Union{Bool,Nothing} = nothing) where T<:BlasFloat, svd!(A; full=full, thin=thin))
@deprecate(svdfact!(A::StridedMatrix{T}, B::StridedMatrix{T}) where T<:BlasFloat, svd!(A, B))
@deprecate(svdfact!(A::AbstractTriangular), svd!(A))

# deprecate svdfact to svd
export svdfact
@deprecate(svdfact(D::Diagonal), svd(D))
@deprecate(svdfact(A::StridedVecOrMat{T}; full::Bool = false, thin::Union{Bool,Nothing} = nothing) where T, svd(A; full=full, thin=thin))
@deprecate(svdfact(x::Number; full::Bool = false, thin::Union{Bool,Nothing} = nothing), svd(x; full=full, thin=thin))
@deprecate(svdfact(x::Integer; full::Bool = false, thin::Union{Bool,Nothing} = nothing), svd(x; full=full, thin=thin))
@deprecate(svdfact(A::StridedMatrix{T}, B::StridedMatrix{T}) where {T<:BlasFloat}, svd(A, B))
@deprecate(svdfact(A::StridedMatrix{TA}, B::StridedMatrix{TB}) where {TA,TB}, svd(A, B))
@deprecate(svdfact(x::Number, y::Number), svd(x, y))
@deprecate(svdfact(M::Bidiagonal; full::Bool = false, thin::Union{Bool,Nothing} = nothing), svd(M; full=full, thin=thin))
@deprecate(svdfact(A::AbstractTriangular), svd(A))
6 changes: 1 addition & 5 deletions stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,7 @@ function svd(D::Diagonal{<:Number})
Up = hcat([U[:,i] for i = 1:length(D.diag)][piv]...)
V = Diagonal(fill!(similar(D.diag), one(eltype(D.diag))))
Vp = hcat([V[:,i] for i = 1:length(D.diag)][piv]...)
return (Up, S[piv], Vp)
end
function svdfact(D::Diagonal)
U, s, V = svd(D)
SVD(U, s, copy(V'))
return SVD(Up, S[piv], copy(Vp'))
end

# dismabiguation methods: * of Diagonal and Adj/Trans AbsVec
Expand Down
Loading