Skip to content

Commit

Permalink
LAPACK: Aggressive constprop to concretely infer syev!/syevd! (#55295)
Browse files Browse the repository at this point in the history
Currently, these are inferred as a 2-Tuple of possible return types
depending on `jobz`, but since `jobz` is usually a constant, we may
propagate it aggressively and have the return types inferred concretely.

(cherry picked from commit 686804d)
  • Loading branch information
jishnub authored and KristofferC committed Oct 9, 2024
1 parent 36ff239 commit beb0c7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions stdlib/LinearAlgebra/src/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5183,7 +5183,7 @@ for (syev, syevr, syevd, sygvd, elty) in
# INTEGER INFO, LDA, LWORK, N
# * .. Array Arguments ..
# DOUBLE PRECISION A( LDA, * ), W( * ), WORK( * )
function syev!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
Base.@constprop :aggressive function syev!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
chkstride1(A)
n = checksquare(A)
W = similar(A, $elty, n)
Expand Down Expand Up @@ -5277,7 +5277,7 @@ for (syev, syevr, syevd, sygvd, elty) in
# * .. Array Arguments ..
# INTEGER IWORK( * )
# DOUBLE PRECISION A( LDA, * ), W( * ), WORK( * )
function syevd!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
Base.@constprop :aggressive function syevd!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
chkstride1(A)
n = checksquare(A)
chkuplofinite(A, uplo)
Expand Down Expand Up @@ -5368,7 +5368,7 @@ for (syev, syevr, syevd, sygvd, elty, relty) in
# * .. Array Arguments ..
# DOUBLE PRECISION RWORK( * ), W( * )
# COMPLEX*16 A( LDA, * ), WORK( * )
function syev!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
Base.@constprop :aggressive function syev!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
chkstride1(A)
chkuplofinite(A, uplo)
n = checksquare(A)
Expand Down Expand Up @@ -5476,7 +5476,7 @@ for (syev, syevr, syevd, sygvd, elty, relty) in
# INTEGER IWORK( * )
# DOUBLE PRECISION RWORK( * )
# COMPLEX*16 A( LDA, * ), WORK( * )
function syevd!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
Base.@constprop :aggressive function syevd!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
chkstride1(A)
chkuplofinite(A, uplo)
n = checksquare(A)
Expand Down
10 changes: 10 additions & 0 deletions stdlib/LinearAlgebra/test/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -729,4 +729,14 @@ a = zeros(2,0), zeros(0)
@test_throws DimensionMismatch LinearAlgebra.LAPACK.getrs!('N', A, ipiv, b)
end

@testset "inference in syev!/syevd!" begin
for T in (Float32, Float64), CT in (T, Complex{T})
A = rand(CT, 4,4)
@inferred (A -> LAPACK.syev!('N', 'U', A))(A)
@inferred (A -> LAPACK.syev!('V', 'U', A))(A)
@inferred (A -> LAPACK.syevd!('N', 'U', A))(A)
@inferred (A -> LAPACK.syevd!('V', 'U', A))(A)
end
end

end # module TestLAPACK

0 comments on commit beb0c7d

Please sign in to comment.