Skip to content

Commit 92405f2

Browse files
aravindh-krishnamoorthydkarraschoscardssmith
authored andcommitted
Fix log_quasitriu for internal scaling s=0 (#56311)
This PR is a potential fix for #54833. ## Description The function https://github.com/JuliaLang/julia/blob/2a06376c18afd7ec875335070743dcebcd85dee7/stdlib/LinearAlgebra/src/triangular.jl#L2220 computes $\boldsymbol{A}^{\dfrac{1}{2^s}} - \boldsymbol{I}$ for a real-valued $2\times 2$ matrix $\boldsymbol{A}$ using Algorithm 5.1 in [R1]. However, the algorithm in [R1] as well as the above function do not handle the case $s=0.$ This fix extends the function to compute $\boldsymbol{A}^{\dfrac{1}{2^s}} - \boldsymbol{I} \Bigg|_{s=0} = \boldsymbol{A} - \boldsymbol{I}.$ ## Checklist - [X] Fix code: `stdlib\LinearAlgebra\src\triangular.jl` in function `_sqrt_pow_diag_block_2x2!(A, A0, s)`. - [X] Add test case: `stdlib\LinearAlgebra\test\triangular.jl`. - [X] Update `NEWS.md`. - [X] Testing and self review. | Tag | Reference | | --- | --- | | <nobr>[R1]</nobr> | Al-Mohy, Awad H. and Higham, Nicholas J. "Improved Inverse Scaling and Squaring Algorithms for the Matrix Logarithm", 2011, url: https://eprints.maths.manchester.ac.uk/1687/1/paper11.pdf | --------- Co-authored-by: Daniel Karrasch <[email protected]> Co-authored-by: Oscar Smith <[email protected]> (cherry picked from commit 2cdfe06)
1 parent debbc22 commit 92405f2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

stdlib/LinearAlgebra/src/triangular.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,11 @@ end
20682068
# SIAM J. Sci. Comput., 34(4), (2012) C153–C169. doi: 10.1137/110852553
20692069
# Algorithm 5.1
20702070
Base.@propagate_inbounds function _sqrt_pow_diag_block_2x2!(A, A0, s)
2071+
if iszero(s)
2072+
A[1,1] -= 1
2073+
A[2,2] -= 1
2074+
return A
2075+
end
20712076
_sqrt_real_2x2!(A, A0)
20722077
if isone(s)
20732078
A[1,1] -= 1

stdlib/LinearAlgebra/test/triangular.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,4 +1130,14 @@ end
11301130
end
11311131
end
11321132

1133+
@testset "log_quasitriu with internal scaling s=0 (issue #54833)" begin
1134+
M = [0.9949357359852791 -0.015567763143324862 -0.09091193493947397 -0.03994428739762443 0.07338356301650806;
1135+
0.011813655598647289 0.9968988574699793 -0.06204555000202496 0.04694097614450692 0.09028834462782365;
1136+
0.092737943594701 0.059546719185135925 0.9935850721633324 0.025348893985651405 -0.018530261590167685;
1137+
0.0369187299165628 -0.04903571106913449 -0.025962938675946543 0.9977767446862031 0.12901494726320517;
1138+
0.0 0.0 0.0 0.0 1.0]
1139+
1140+
@test exp(log(M)) M
1141+
end
1142+
11331143
end # module TestTriangular

0 commit comments

Comments
 (0)