Skip to content

Commit

Permalink
Aggressive constprop in trevc! to stabilize triangular eigvec (#54635)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
jishnub authored May 31, 2024
1 parent aea4627 commit ea8b4af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3701,7 +3701,7 @@ for (trcon, trevc, trrfs, elty) in
# LOGICAL SELECT( * )
# DOUBLE PRECISION T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
#$ WORK( * )
function trevc!(side::AbstractChar, howmny::AbstractChar, select::AbstractVector{BlasInt}, T::AbstractMatrix{$elty},
Base.@constprop :aggressive function trevc!(side::AbstractChar, howmny::AbstractChar, select::AbstractVector{BlasInt}, T::AbstractMatrix{$elty},
VL::AbstractMatrix{$elty} = similar(T),
VR::AbstractMatrix{$elty} = similar(T))
require_one_based_indexing(select, T, VL, VR)
Expand Down
6 changes: 6 additions & 0 deletions stdlib/LinearAlgebra/test/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1105,4 +1105,10 @@ end
end
end

@testset "type-stable eigvecs" begin
D = Float64[1 0; 0 2]
V = @inferred eigvecs(UpperTriangular(D))
@test V == Diagonal([1, 1])
end

end # module TestTriangular

0 comments on commit ea8b4af

Please sign in to comment.