From faa72ef5993694ce52eab18e9befa28324f81b5c Mon Sep 17 00:00:00 2001 From: Mohamed Tarek Date: Sun, 5 Aug 2018 08:32:18 +0200 Subject: [PATCH] Define `size` for SVD (#28439) * Define `size` for SVD Closes https://github.com/JuliaLang/julia/issues/28438. And first PR! * add test to 3-arg `ldiv!` on `SVD` which calls `size` * github pampering --- stdlib/LinearAlgebra/src/svd.jl | 3 +++ stdlib/LinearAlgebra/test/svd.jl | 2 ++ 2 files changed, 5 insertions(+) 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