Skip to content

Commit

Permalink
Define size for SVD (#28439)
Browse files Browse the repository at this point in the history
* Define `size` for SVD

Closes #28438. And first PR!

* add test to 3-arg `ldiv!` on `SVD` which calls `size`

* github pampering

(cherry picked from commit e0876d2)
  • Loading branch information
mohamed82008 authored and ararslan committed Aug 5, 2018
1 parent 773cd21 commit 023290b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions stdlib/LinearAlgebra/src/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/test/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 023290b

Please sign in to comment.