Skip to content

Commit a17b39b

Browse files
committed
Better sqrt decomp
1 parent 20277cd commit a17b39b

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/tensor_operations/matrix_decomposition.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -599,15 +599,7 @@ function Base.sqrt(T::ITensor; ishermitian=true, atol=1e-15)
599599
# return itensor(sqrt(tensor(T)))
600600
#end
601601
D, U = eigen(T; ishermitian=ishermitian)
602-
sqrtD = D
603-
for n in 1:mindim(D)
604-
Dnn = D[n, n]
605-
if Dnn < 0 && abs(Dnn) < atol
606-
sqrtD[n, n] = 0
607-
else
608-
sqrtD[n, n] = sqrt(Dnn)
609-
end
610-
end
602+
sqrtD = map_diag(x -> x < 0 && abs(x) < atol ? 0 : sqrt(x), D)
611603
return U' * sqrtD * dag(U)
612604
end
613605

0 commit comments

Comments
 (0)