Skip to content

Commit 184e2e1

Browse files
authored
Refactor sqrt_inv_sqrt (#158)
1 parent efb6bca commit 184e2e1

File tree

10 files changed

+182
-202
lines changed

10 files changed

+182
-202
lines changed

src/ITensorNetworks.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ include("caches/beliefpropagationcache.jl")
3636
include("contraction_tree_to_graph.jl")
3737
include("gauging.jl")
3838
include("utils.jl")
39-
include("ITensorsExt/itensorutils.jl")
39+
include("ITensorsExtensions/ITensorsExtensions.jl")
4040
include("solvers/local_solvers/eigsolve.jl")
4141
include("solvers/local_solvers/exponentiate.jl")
4242
include("solvers/local_solvers/dmrg_x.jl")

src/ITensorsExt/itensorutils.jl

-90
This file was deleted.

src/ITensorsExtensions/ITensorsExtensions.jl

+20-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ using ITensors:
1212
map_diag,
1313
noncommonind,
1414
noprime,
15+
replaceind,
1516
replaceinds,
17+
sim,
1618
space,
1719
sqrt_decomp
1820
using ITensors.NDTensors:
@@ -52,16 +54,24 @@ invsqrt_diag(it::ITensor) = map_diag(inv ∘ sqrt, it)
5254
pinv_diag(it::ITensor) = map_diag(pinv, it)
5355
pinvsqrt_diag(it::ITensor) = map_diag(pinv sqrt, it)
5456

55-
function map_itensor(
56-
f::Function, A::ITensor, lind=first(inds(A)); regularization=nothing, kwargs...
57-
)
58-
USV = svd(A, lind; kwargs...)
59-
U, S, V, spec, u, v = USV
60-
S = map_diag(s -> f(s + regularization), S)
61-
sqrtDL, δᵤᵥ, sqrtDR = sqrt_decomp(S, u, v)
62-
sqrtDR = denseblocks(sqrtDR) * denseblocks(δᵤᵥ)
63-
L, R = U * sqrtDL, V * sqrtDR
64-
return L * R
57+
#TODO: Make this work for non-hermitian A
58+
function eigendecomp(A::ITensor, linds, rinds; ishermitian=false, kwargs...)
59+
@assert ishermitian
60+
D, U = eigen(A, linds, rinds; ishermitian, kwargs...)
61+
ul, ur = noncommonind(D, U), commonind(D, U)
62+
Ul = replaceinds(U, vcat(rinds, ur), vcat(linds, ul))
63+
64+
return Ul, D, dag(U)
65+
end
66+
67+
function map_eigvals(f::Function, A::ITensor, inds...; ishermitian=false, kwargs...)
68+
if isdiag(A)
69+
return map_diag(f, A)
70+
end
71+
72+
Ul, D, Ur = eigendecomp(A, inds...; ishermitian, kwargs...)
73+
74+
return Ul * map_diag(f, D) * Ur
6575
end
6676

6777
# Analagous to `denseblocks`.

0 commit comments

Comments
 (0)