Skip to content

Commit b417357

Browse files
committed
add sqrtm
1 parent 5079568 commit b417357

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/StaticArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Base: getindex, setindex!, size, similar, vec, show,
88
length, convert, promote_op, map, map!, reduce, reducedim, mapreducedim,
99
mapreduce, broadcast, broadcast!, conj, transpose, ctranspose,
1010
hcat, vcat, ones, zeros, eye, one, cross, vecdot, reshape, fill,
11-
fill!, det, inv, eig, eigvals, expm, trace, vecnorm, norm, dot, diagm,
11+
fill!, det, inv, eig, eigvals, expm, sqrtm, trace, vecnorm, norm, dot, diagm,
1212
sum, diff, prod, count, any, all, minimum,
1313
maximum, extrema, mean, copy, rand, randn, randexp, rand!, randn!,
1414
randexp!, normalize, normalize!, read, read!, write

src/sqrtm.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@inline sqrtm(A::StaticMatrix) = _sqrtm(Size(A),A)
2+
3+
@inline function _sqrtm(::Size{(2,2)}, A::StaticMatrix)
4+
a,b,c,d = A
5+
s = sqrtm(a*d-b*c)
6+
t = inv(sqrtm(a+d+2s))
7+
similar_type(typeof(A),typeof(t))(t*(a+s), t*b, t*c, t*(d+s))
8+
end
9+
10+
@inline _sqrtm(s::Size, A::StaticArray) = s(Base.sqrtm(Array(A)))

0 commit comments

Comments
 (0)