Skip to content

Commit dfa334d

Browse files
authored
Handle empty matrices in svd_full and add tests (#37)
* Special case svd_full on empty matrices * Also add tests * Bump v0.2.4
1 parent 00d6e79 commit dfa334d

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MatrixAlgebraKit"
22
uuid = "6c742aac-3347-4629-af66-fc926824e5e4"
33
authors = ["Jutho <jutho.haegeman@ugent.be> and contributors"]
4-
version = "0.2.3"
4+
version = "0.2.4"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/implementations/svd.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ function svd_full!(A::AbstractMatrix, USVᴴ, alg::LAPACK_SVDAlgorithm)
7474
fill!(S, zero(eltype(S)))
7575
m, n = size(A)
7676
minmn = min(m, n)
77+
if minmn == 0
78+
one!(U)
79+
zero!(S)
80+
one!(Vᴴ)
81+
return USVᴴ
82+
end
7783
if alg isa LAPACK_QRIteration
7884
isempty(alg.kwargs) ||
7985
throw(ArgumentError("LAPACK_QRIteration does not accept any keyword arguments"))

test/svd.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using MatrixAlgebraKit: TruncatedAlgorithm, TruncationKeepAbove, diagview
88
@testset "svd_compact! for T = $T" for T in (Float32, Float64, ComplexF32, ComplexF64)
99
rng = StableRNG(123)
1010
m = 54
11-
@testset "size ($m, $n)" for n in (37, m, 63)
11+
@testset "size ($m, $n)" for n in (37, m, 63, 0)
1212
k = min(m, n)
1313
if LinearAlgebra.LAPACK.version() < v"3.12.0"
1414
algs = (LAPACK_DivideAndConquer(), LAPACK_QRIteration(), LAPACK_Bisection(),
@@ -57,7 +57,7 @@ end
5757
@testset "svd_full! for T = $T" for T in (Float32, Float64, ComplexF32, ComplexF64)
5858
rng = StableRNG(123)
5959
m = 54
60-
@testset "size ($m, $n)" for n in (37, m, 63)
60+
@testset "size ($m, $n)" for n in (37, m, 63, 0)
6161
@testset "algorithm $alg" for alg in
6262
(LAPACK_DivideAndConquer(), LAPACK_QRIteration())
6363
A = randn(rng, T, m, n)

0 commit comments

Comments
 (0)