Skip to content

Commit e52719b

Browse files
jishnubKristofferC
authored and
KristofferC
committed
Aggressive constprop in trevc! to stabilize triangular eigvec (#54635)
We may use aggressive constprop in `trevc!` to eliminate branches, which makes the return type of `eigvec(::UpperTriangular)` concretely inferred. ```julia julia> @inferred eigvecs(UpperTriangular([1 0; 0 1])) 2×2 Matrix{Float32}: 1.0 -0.0 0.0 1.0 ``` (cherry picked from commit ea8b4af)
1 parent 3f35094 commit e52719b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

stdlib/LinearAlgebra/src/lapack.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3633,7 +3633,7 @@ for (trcon, trevc, trrfs, elty) in
36333633
# LOGICAL SELECT( * )
36343634
# DOUBLE PRECISION T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
36353635
#$ WORK( * )
3636-
function trevc!(side::AbstractChar, howmny::AbstractChar, select::AbstractVector{BlasInt}, T::AbstractMatrix{$elty},
3636+
Base.@constprop :aggressive function trevc!(side::AbstractChar, howmny::AbstractChar, select::AbstractVector{BlasInt}, T::AbstractMatrix{$elty},
36373637
VL::AbstractMatrix{$elty} = similar(T),
36383638
VR::AbstractMatrix{$elty} = similar(T))
36393639
require_one_based_indexing(select, T, VL, VR)

stdlib/LinearAlgebra/test/triangular.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,4 +879,10 @@ end
879879
@test transpose!(U) == Ut
880880
end
881881

882+
@testset "type-stable eigvecs" begin
883+
D = Float64[1 0; 0 2]
884+
V = @inferred eigvecs(UpperTriangular(D))
885+
@test V == Diagonal([1, 1])
886+
end
887+
882888
end # module TestTriangular

0 commit comments

Comments
 (0)