Skip to content
Merged
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
8 changes: 8 additions & 0 deletions stdlib/LinearAlgebra/src/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ function svd(x::Integer; full::Bool = false, thin::Union{Bool,Nothing} = nothing
end
return svd(float(x), full = full)
end
function svd(A::Adjoint; full::Bool = false)
s = svd(A.parent, full = full)
return SVD(s.Vt', s.S, s.U')
end
function svd(A::Transpose; full::Bool = false)
s = svd(A.parent, full = full)
return SVD(transpose(s.Vt), s.S, transpose(s.U))
end

function getproperty(F::SVD, d::Symbol)
if d == :V
Expand Down
20 changes: 20 additions & 0 deletions stdlib/LinearAlgebra/test/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ a2img = randn(n,n)/2
@test svdz.Vt ≈ Matrix{eltya}(I, 0, 0)
end
end
usv = svd(a')
@testset "singular value decomposition of adjoint" begin
@test usv.S === svdvals(usv)
@test usv.U * (Diagonal(usv.S) * usv.Vt) ≈ a'
@test convert(Array, usv) ≈ a'
@test usv.Vt' ≈ usv.V
@test_throws ErrorException usv.Z
b = rand(eltya,n)
@test usv\b ≈ a'\b
end
usv = svd(transpose(a))
@testset "singular value decomposition of transpose" begin
@test usv.S === svdvals(usv)
@test usv.U * (Diagonal(usv.S) * usv.Vt) ≈ transpose(a)
@test convert(Array, usv) ≈ transpose(a)
@test usv.Vt' ≈ usv.V
@test_throws ErrorException usv.Z
b = rand(eltya,n)
@test usv\b ≈ transpose(a)\b
end
Copy link
Member

@StefanKarpinski StefanKarpinski Jul 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think that the most obvious tests here would be these:

svd(a').U == svd(a).V
svd(a').S == svd(a).S
svd(a').V == svd(a).U

Is there some reason not to test this directly? I realize that the precise U and V matrices are not well defined in many cases but it seems unlikely that this will ever break in this case, no?

@testset "Generalized svd" begin
a_svd = a[1:n1, :]
gsvd = svd(a,a_svd)
Expand Down