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.
  • Loading branch information
jishnub authored Jul 30, 2024
1 parent 125bac4 commit 686804d
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 @@ -5329,7 +5329,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})
require_one_based_indexing(A)
@chkvalidparam 1 jobz ('N', 'V')
chkuplo(uplo)
Expand Down Expand Up @@ -5429,7 +5429,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})
require_one_based_indexing(A)
@chkvalidparam 1 jobz ('N', 'V')
chkstride1(A)
Expand Down Expand Up @@ -5526,7 +5526,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})
require_one_based_indexing(A)
@chkvalidparam 1 jobz ('N', 'V')
chkstride1(A)
Expand Down Expand Up @@ -5639,7 +5639,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})
require_one_based_indexing(A)
@chkvalidparam 1 jobz ('N', 'V')
chkstride1(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 @@ -889,4 +889,14 @@ end
@test UpperTriangular(A) == UpperTriangular(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 686804d

Please sign in to comment.