Skip to content

Commit

Permalink
[ITensors] Fix eigen_perturbation rank (#1302)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Jan 16, 2024
1 parent 791f690 commit f673d04
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/tensor_operations/matrix_decomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -781,13 +781,19 @@ function factorize(
Lis = commoninds(A, indices(Linds...))
Ris = uniqueinds(A, Lis)
dL, dR = dim(Lis), dim(Ris)
# maxdim is forced to be at most the max given SVD
if isnothing(maxdim)
maxdim = min(dL, dR)
if isnothing(eigen_perturbation)
# maxdim is forced to be at most the max given SVD
if isnothing(maxdim)
maxdim = min(dL, dR)
end
maxdim = min(maxdim, min(dL, dR))
else
if isnothing(maxdim)
maxdim = max(dL, dR)
end
maxdim = min(maxdim, max(dL, dR))
end
maxdim = min(maxdim, min(dL, dR))
might_truncate = !isnothing(cutoff) || maxdim < min(dL, dR)

if isnothing(which_decomp)
if !might_truncate && ortho != "none"
which_decomp = "qr"
Expand Down
21 changes: 21 additions & 0 deletions test/base/test_decomp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@ end
)
end

@testset "factorize with eigen_perturbation dimensions" begin
elt = Float64
di = 10
dj = 5
maxdim = di - 1
i = Index(di, "i")
j = Index(dj, "j")
a = randomITensor(elt, i, j)
δ = randomITensor(elt, i, j)
δ² = prime(δ, i) * dag(δ)
= prime(a, i) * dag(a)
x, y = factorize(a, i; ortho="left", which_decomp="eigen", maxdim)
l = commonind(x, y)
@test dim(l) == dj
xδ, yδ = factorize(
a, i; ortho="left", which_decomp="eigen", eigen_perturbation=δ², maxdim
)
= commonind(xδ, yδ)
@test dim(lδ) == maxdim
end

@testset "QR/RQ/QL/LQ decomp on MPS dense $elt tensor with all possible collections on Q/R/L" for ninds in
[
0, 1, 2, 3
Expand Down

0 comments on commit f673d04

Please sign in to comment.