Skip to content

Commit c6b59ef

Browse files
authored
Merge a8e5bf5 into 791f690
2 parents 791f690 + a8e5bf5 commit c6b59ef

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/tensor_operations/matrix_decomposition.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -781,13 +781,19 @@ function factorize(
781781
Lis = commoninds(A, indices(Linds...))
782782
Ris = uniqueinds(A, Lis)
783783
dL, dR = dim(Lis), dim(Ris)
784-
# maxdim is forced to be at most the max given SVD
785-
if isnothing(maxdim)
786-
maxdim = min(dL, dR)
784+
if isnothing(eigen_perturbation)
785+
# maxdim is forced to be at most the max given SVD
786+
if isnothing(maxdim)
787+
maxdim = min(dL, dR)
788+
end
789+
maxdim = min(maxdim, min(dL, dR))
790+
else
791+
if isnothing(maxdim)
792+
maxdim = max(dL, dR)
793+
end
794+
maxdim = min(maxdim, max(dL, dR))
787795
end
788-
maxdim = min(maxdim, min(dL, dR))
789796
might_truncate = !isnothing(cutoff) || maxdim < min(dL, dR)
790-
791797
if isnothing(which_decomp)
792798
if !might_truncate && ortho != "none"
793799
which_decomp = "qr"

test/base/test_decomp.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ end
136136
)
137137
end
138138

139+
@testset "factorize with eigen_perturbation dimensions" begin
140+
elt = Float64
141+
di = 10
142+
dj = 5
143+
maxdim = di - 1
144+
i = Index(di, "i")
145+
j = Index(dj, "j")
146+
a = randomITensor(elt, i, j)
147+
δ = randomITensor(elt, i, j)
148+
δ² = prime(δ, i) * dag(δ)
149+
= prime(a, i) * dag(a)
150+
x, y = factorize(a, i; ortho="left", which_decomp="eigen", maxdim)
151+
l = commonind(x, y)
152+
@test dim(l) == dj
153+
xδ, yδ = factorize(
154+
a, i; ortho="left", which_decomp="eigen", eigen_perturbation=δ², maxdim
155+
)
156+
= commonind(xδ, yδ)
157+
@test dim(lδ) == maxdim
158+
end
159+
139160
@testset "QR/RQ/QL/LQ decomp on MPS dense $elt tensor with all possible collections on Q/R/L" for ninds in
140161
[
141162
0, 1, 2, 3

0 commit comments

Comments
 (0)