Skip to content

Commit d0af9c5

Browse files
authored
Avoid constprop in syevd! and syev! (JuliaLang#56442)
This improves compilation times slightly: ```julia julia> using LinearAlgebra julia> A = rand(2,2); julia> @time eigen!(Hermitian(A)); 0.163380 seconds (180.51 k allocations: 8.760 MiB, 99.88% compilation time) # master 0.155285 seconds (163.77 k allocations: 7.971 MiB, 99.87% compilation time) # This PR ``` The idea is that the constant propagation is only required to infer the return type, and isn't necessary in the body of the method. We may therefore annotate the body with a `@constprop :none`.
1 parent 9c4541b commit d0af9c5

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

stdlib/LinearAlgebra/src/lapack.jl

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5318,6 +5318,14 @@ solution `X`.
53185318
"""
53195319
hetrs!(uplo::AbstractChar, A::AbstractMatrix, ipiv::AbstractVector{BlasInt}, B::AbstractVecOrMat)
53205320

5321+
for f in (:syevd!, :syev!)
5322+
_f = Symbol(:_, f)
5323+
@eval function $f(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix)
5324+
W, A = $_f(jobz, uplo, A)
5325+
jobz == 'V' ? (W, A) : W
5326+
end
5327+
end
5328+
53215329
# Symmetric (real) eigensolvers
53225330
for (syev, syevr, syevd, sygvd, elty) in
53235331
((:dsyev_,:dsyevr_,:dsyevd_,:dsygvd_,:Float64),
@@ -5329,7 +5337,7 @@ for (syev, syevr, syevd, sygvd, elty) in
53295337
# INTEGER INFO, LDA, LWORK, N
53305338
# * .. Array Arguments ..
53315339
# DOUBLE PRECISION A( LDA, * ), W( * ), WORK( * )
5332-
Base.@constprop :aggressive function syev!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
5340+
Base.@constprop :none function _syev!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
53335341
require_one_based_indexing(A)
53345342
@chkvalidparam 1 jobz ('N', 'V')
53355343
chkuplo(uplo)
@@ -5350,7 +5358,7 @@ for (syev, syevr, syevd, sygvd, elty) in
53505358
resize!(work, lwork)
53515359
end
53525360
end
5353-
jobz == 'V' ? (W, A) : W
5361+
W, A
53545362
end
53555363

53565364
# SUBROUTINE DSYEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
@@ -5429,7 +5437,7 @@ for (syev, syevr, syevd, sygvd, elty) in
54295437
# * .. Array Arguments ..
54305438
# INTEGER IWORK( * )
54315439
# DOUBLE PRECISION A( LDA, * ), W( * ), WORK( * )
5432-
Base.@constprop :aggressive function syevd!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
5440+
Base.@constprop :none function _syevd!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
54335441
require_one_based_indexing(A)
54345442
@chkvalidparam 1 jobz ('N', 'V')
54355443
chkstride1(A)
@@ -5459,7 +5467,7 @@ for (syev, syevr, syevd, sygvd, elty) in
54595467
resize!(iwork, liwork)
54605468
end
54615469
end
5462-
jobz == 'V' ? (W, A) : W
5470+
W, A
54635471
end
54645472

54655473
# Generalized eigenproblem
@@ -5526,7 +5534,7 @@ for (syev, syevr, syevd, sygvd, elty, relty) in
55265534
# * .. Array Arguments ..
55275535
# DOUBLE PRECISION RWORK( * ), W( * )
55285536
# COMPLEX*16 A( LDA, * ), WORK( * )
5529-
Base.@constprop :aggressive function syev!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
5537+
Base.@constprop :none function _syev!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
55305538
require_one_based_indexing(A)
55315539
@chkvalidparam 1 jobz ('N', 'V')
55325540
chkstride1(A)
@@ -5550,7 +5558,7 @@ for (syev, syevr, syevd, sygvd, elty, relty) in
55505558
resize!(work, lwork)
55515559
end
55525560
end
5553-
jobz == 'V' ? (W, A) : W
5561+
W, A
55545562
end
55555563

55565564
# SUBROUTINE ZHEEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
@@ -5639,7 +5647,7 @@ for (syev, syevr, syevd, sygvd, elty, relty) in
56395647
# INTEGER IWORK( * )
56405648
# DOUBLE PRECISION RWORK( * )
56415649
# COMPLEX*16 A( LDA, * ), WORK( * )
5642-
Base.@constprop :aggressive function syevd!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
5650+
Base.@constprop :none function _syevd!(jobz::AbstractChar, uplo::AbstractChar, A::AbstractMatrix{$elty})
56435651
require_one_based_indexing(A)
56445652
@chkvalidparam 1 jobz ('N', 'V')
56455653
chkstride1(A)
@@ -5673,7 +5681,7 @@ for (syev, syevr, syevd, sygvd, elty, relty) in
56735681
resize!(iwork, liwork)
56745682
end
56755683
end
5676-
jobz == 'V' ? (W, A) : W
5684+
W, A
56775685
end
56785686

56795687
# SUBROUTINE ZHEGVD( ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK,

0 commit comments

Comments
 (0)