Skip to content

Commit f972d16

Browse files
authored
Ensure full is constant propagated in svd(A,full=false) (#805)
This workaround allows the LinearAlgebra implementation of `pinv` to be inferred on julia 1.5-rc1 and 1.6-DEV. Unfortunately the extra inline annotation doesn't seem to work on lower Julia versions.
1 parent 68b10c2 commit f972d16

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/svd.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ function svd(A::StaticMatrix; full=Val(false))
3737
end
3838

3939
# Allow plain Bool in addition to Val
40-
_svd(A, full) = _svd(A, Val(convert(Bool, full)))
40+
# Required inline as of version 1.5 to ensure Bool usage like svd(A,
41+
# full=false) is constant-propagated
42+
@inline _svd(A, full) = _svd(A, Val(convert(Bool, full)))
4143

4244
function _svd(A, full::Val{false})
4345
f = svd(Matrix(A), full=false)

test/svd.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ using StaticArrays, Test, LinearAlgebra
7171
@testinf svd(m_sing2'; full=Val(true)) \ v2 svd(Matrix(m_sing2'); full=true) \ Vector(v2)
7272
@testinf svd(m_sing2; full=Val(true)) \ m23' svd(Matrix(m_sing2); full=true) \ Matrix(m23')
7373
@testinf svd(m_sing2'; full=Val(true)) \ m23 svd(Matrix(m_sing2'); full=true) \ Matrix(m23)
74+
if VERSION >= v"1.5-DEV"
75+
# Test that svd of rectangular matrix is inferred.
76+
# Note the placement of @inferred brackets is important.
77+
#
78+
# This only seems to work on >= v"1.5" due to unknown compiler improvements.
79+
svd_full_false(A) = svd(m_sing2, full=false)
80+
@test @inferred(svd_full_false(m_sing2)).S svd(Matrix(m_sing2)).S
81+
end
7482

7583
@testinf svd(mc_sing) \ v svd(Matrix(mc_sing)) \ Vector(v)
7684
@testinf svd(mc_sing) \ vc svd(Matrix(mc_sing)) \ Vector(vc)

0 commit comments

Comments
 (0)