Skip to content

Commit 68c8708

Browse files
authored
Faster matrix sqrt for upper triangular matrices. (#31100)
Replacing Val(::Bool) in an argument list with an explicit if makes the call type stable. The issue was discussed in #31007.
1 parent f36036c commit 68c8708

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

stdlib/LinearAlgebra/src/triangular.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2586,7 +2586,13 @@ function sqrt(A::UpperTriangular)
25862586
end
25872587
end
25882588
end
2589-
sqrt(A,Val(realmatrix))
2589+
# Writing an explicit if instead of using Val(realmatrix) below
2590+
# makes the calls to sqrt(::UpperTriangular,::Val) type stable.
2591+
if realmatrix
2592+
return sqrt(A,Val(true))
2593+
else
2594+
return sqrt(A,Val(false))
2595+
end
25902596
end
25912597
function sqrt(A::UpperTriangular{T},::Val{realmatrix}) where {T,realmatrix}
25922598
B = A.data

0 commit comments

Comments
 (0)