Skip to content

Commit a2e4054

Browse files
jishnubKristofferC
authored andcommitted
Don't access parent of triangular matrix in powm (#52583)
Since the values stored in the parent corresponding to the structural zeros of a tridiagonal matrix aren't well-defined, using it in `ldiv!` is a footgun that may lead to heisenbugs (one seen in https://buildkite.com/julialang/julia-master/builds/31285#018c7cc7-6c77-41ac-a01b-1c7d14cb1b15). This PR changes it to using the tridiagonal matrix directly in `ldiv!`, which should lead to predictable results, and be bug-free. The failing tests for #52571 pass locally with this change. (cherry picked from commit ef549ae)
1 parent 3120989 commit a2e4054

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

stdlib/LinearAlgebra/src/triangular.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ end
15511551
# Higham and Lin, "An improved Schur-Padé algorithm for fractional powers of
15521552
# a matrix and their Fréchet derivatives", SIAM. J. Matrix Anal. & Appl.,
15531553
# 34(3), (2013) 1341–1360.
1554-
function powm!(A0::UpperTriangular{<:BlasFloat}, p::Real)
1554+
function powm!(A0::UpperTriangular, p::Real)
15551555
if abs(p) >= 1
15561556
throw(ArgumentError("p must be a real number in (-1,1), got $p"))
15571557
end
@@ -1583,22 +1583,22 @@ function powm!(A0::UpperTriangular{<:BlasFloat}, p::Real)
15831583
end
15841584
copyto!(Stmp, S)
15851585
mul!(S, A, c)
1586-
ldiv!(Stmp, S.data)
1586+
ldiv!(Stmp, S)
15871587

15881588
c = (p - j) / (j4 - 2)
15891589
for i = 1:n
15901590
@inbounds S[i, i] = S[i, i] + 1
15911591
end
15921592
copyto!(Stmp, S)
15931593
mul!(S, A, c)
1594-
ldiv!(Stmp, S.data)
1594+
ldiv!(Stmp, S)
15951595
end
15961596
for i = 1:n
15971597
S[i, i] = S[i, i] + 1
15981598
end
15991599
copyto!(Stmp, S)
16001600
mul!(S, A, -p)
1601-
ldiv!(Stmp, S.data)
1601+
ldiv!(Stmp, S)
16021602
for i = 1:n
16031603
@inbounds S[i, i] = S[i, i] + 1
16041604
end

stdlib/LinearAlgebra/test/dense.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,11 @@ end
10671067
end
10681068
end
10691069

1070+
@testset "BigFloat triangular real power" begin
1071+
A = Float64[3 1; 0 3]
1072+
@test A^(3/4) big.(A)^(3/4)
1073+
end
1074+
10701075
@testset "diagonal integer matrix to real power" begin
10711076
A = Matrix(Diagonal([1, 2, 3]))
10721077
@test A^2.3 float(A)^2.3

0 commit comments

Comments
 (0)