From 907523599fabc704bbb6273485122a2ee6e227e1 Mon Sep 17 00:00:00 2001 From: Mateusz Baran Date: Mon, 18 Feb 2019 10:40:19 +0100 Subject: [PATCH] Faster matrix sqrt for upper triangular matrices. Replacing Val(::Bool) in an argument list with an explicit if makes the call type stable. The issue was discussed in #31007. --- stdlib/LinearAlgebra/src/triangular.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stdlib/LinearAlgebra/src/triangular.jl b/stdlib/LinearAlgebra/src/triangular.jl index 408dc391a89c1..73a861358022b 100644 --- a/stdlib/LinearAlgebra/src/triangular.jl +++ b/stdlib/LinearAlgebra/src/triangular.jl @@ -2586,7 +2586,13 @@ function sqrt(A::UpperTriangular) end end end - sqrt(A,Val(realmatrix)) + # Writing an explicit if instead of using Val(realmatrix) below + # makes the calls to sqrt(::UpperTriangular,::Val) type stable. + if realmatrix + return sqrt(A,Val(true)) + else + return sqrt(A,Val(false)) + end end function sqrt(A::UpperTriangular{T},::Val{realmatrix}) where {T,realmatrix} B = A.data