Skip to content

Commit ea8b4af

Browse files
authored
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 ```
1 parent aea4627 commit ea8b4af

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
@@ -3701,7 +3701,7 @@ for (trcon, trevc, trrfs, elty) in
37013701
# LOGICAL SELECT( * )
37023702
# DOUBLE PRECISION T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
37033703
#$ WORK( * )
3704-
function trevc!(side::AbstractChar, howmny::AbstractChar, select::AbstractVector{BlasInt}, T::AbstractMatrix{$elty},
3704+
Base.@constprop :aggressive function trevc!(side::AbstractChar, howmny::AbstractChar, select::AbstractVector{BlasInt}, T::AbstractMatrix{$elty},
37053705
VL::AbstractMatrix{$elty} = similar(T),
37063706
VR::AbstractMatrix{$elty} = similar(T))
37073707
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
@@ -1105,4 +1105,10 @@ end
11051105
end
11061106
end
11071107

1108+
@testset "type-stable eigvecs" begin
1109+
D = Float64[1 0; 0 2]
1110+
V = @inferred eigvecs(UpperTriangular(D))
1111+
@test V == Diagonal([1, 1])
1112+
end
1113+
11081114
end # module TestTriangular

0 commit comments

Comments
 (0)