Skip to content

Commit 4229c51

Browse files
committed
handle 2x2 null matrix case
1 parent 01e6fea commit 4229c51

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/sqrtm.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ end
77

88
@inline function _sqrtm(::Size{(2,2)}, A::SA) where {SA<:StaticArray}
99
a,b,c,d = A
10-
s = sqrtm(a*d-b*c)
11-
t = inv(sqrtm(a+d+2s))
12-
similar_type(SA,typeof(t))(t*(a+s), t*b, t*c, t*(d+s))
10+
if a==b==c==d==0
11+
zero(A)
12+
else
13+
s = sqrtm(a*d-b*c)
14+
t = inv(sqrtm(a+d+2s))
15+
similar_type(SA,typeof(t))(t*(a+s), t*b, t*c, t*(d+s))
16+
end
1317
end
1418

1519
@inline _sqrtm(s::Size, A::StaticArray) = s(Base.sqrtm(Array(A)))

0 commit comments

Comments
 (0)