diff --git a/stdlib/LinearAlgebra/src/svd.jl b/stdlib/LinearAlgebra/src/svd.jl index b41c2ab9e4aeed..b463d71989273c 100644 --- a/stdlib/LinearAlgebra/src/svd.jl +++ b/stdlib/LinearAlgebra/src/svd.jl @@ -224,6 +224,9 @@ function ldiv!(A::SVD{T}, B::StridedVecOrMat) where T view(A.Vt,1:k,:)' * (view(A.S,1:k) .\ (view(A.U,:,1:k)' * B)) end +size(A::SVD, dim::Integer) = dim == 1 ? size(A.U, dim) : size(A.Vt, dim) +size(A::SVD) = (size(A, 1), size(A, 2)) + # Generalized svd struct GeneralizedSVD{T,S} <: Factorization{T} U::S diff --git a/stdlib/LinearAlgebra/test/svd.jl b/stdlib/LinearAlgebra/test/svd.jl index e253f6eb2b8d79..59830c46b0d3af 100644 --- a/stdlib/LinearAlgebra/test/svd.jl +++ b/stdlib/LinearAlgebra/test/svd.jl @@ -29,6 +29,8 @@ using LinearAlgebra: BlasComplex, BlasFloat, BlasReal, QRPivoted # matrices from the factorization as expected. @test sf1.U*Diagonal(sf1.S)*sf1.Vt' ≊ m1 @test sf2.U*Diagonal(sf2.S)*sf2.Vt' ≊ m2 + + @test ldiv!([0., 0.], svd(Matrix(I, 2, 2)), [1., 1.]) ≊ [1., 1.] end n = 10