Skip to content

Commit ee73648

Browse files
authored
Enable full keyword for svd. (#73)
This is the only piece of functionality from GenericSVD that is currently missing.
1 parent 74e8183 commit ee73648

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/svd.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,15 @@ function LinearAlgebra.svd!(A::StridedMatrix{T};
552552

553553
# Form the matrices U and Vᴴ by combining the singular vector matrices of the bidiagonal SVD with the Householder reflectors from the bidiagonal factorization.
554554
if istriu(_B)
555-
U = BF.leftQ*F.U
555+
U = Matrix{T}(I, m, full ? m : n)
556+
U[1:n,1:n] = F.U
557+
lmul!(BF.leftQ, U)
556558
Vᴴ = F.Vt*BF.rightQ'
557559
else
558560
U = BF.leftQ*F.V
559-
Vᴴ = (BF.rightQ*F.U)'
561+
Vᴴ = Matrix{T}(I, full ? n : m, n)
562+
Vᴴ[1:m,1:m] = F.U'
563+
rmul!(Vᴴ, BF.rightQ')
560564
end
561565

562566
s = F.S

test/svd.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ using Test, GenericLinearAlgebra, LinearAlgebra, Quaternions
4444
Fbig = svd(Abig)
4545
@test abs.(F.U'Float64.(Fbig.U)) I
4646
@test abs.(F.V'Float64.(Fbig.V)) I
47+
48+
F = svd(A, full=true)
49+
Fbig = svd(Abig, full=true)
50+
@test abs.(F.U'Float64.(Fbig.U)) I
51+
@test abs.(F.V'Float64.(Fbig.V)) I
4752
end
4853

4954
@testset "Issue 54" begin
@@ -53,4 +58,5 @@ using Test, GenericLinearAlgebra, LinearAlgebra, Quaternions
5358
U, S, V = svd(A)
5459
@test A U*Diagonal(S)*V'
5560
end
61+
5662
end

0 commit comments

Comments
 (0)