File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed
Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 6262function _compute_truncdim(Σdata, trunc:: TruncationDimension , p= 2 )
6363 I = keytype(Σdata)
6464 truncdim = SectorDict{I,Int}(c => length(v) for (c, v) in Σdata)
65- while sum(dim(c) * d for (c, d) in truncdim) > trunc. dim
65+ S = []
66+ for (c, v) in Σdata
67+ for i in 1 : dim(c)
68+ push!(S, v)
69+ end
70+ end
71+
72+ S = sort(vcat(S... ); by= x -> - x)
73+
74+ n = trunc. dim
75+
76+ cutoff = eps(scalartype(S))
77+ deg_threshold = 1.0 - sqrt(cutoff)
78+ n_above_cutoff = count(>= (cutoff), S / S[1 ])
79+ n = Int(min(n, n_above_cutoff))
80+ if n > 0 && n < length(S)
81+
82+ # 从初始截断点开始向后检查
83+ last_index = n
84+ for i in n: (length(S) - 1 )
85+ # 如果下一个奇异值与当前奇异值非常接近
86+ if S[i + 1 ] >= S[i] * deg_threshold
87+ last_index = i + 1
88+ else
89+ # 一旦发现差异足够大的相邻奇异值,停止扩展
90+ break
91+ end
92+ end
93+ n = last_index
94+ end
95+ while sum(dim(c) * d for (c, d) in truncdim) > n
6696 cmin = _findnexttruncvalue(Σdata, truncdim, p)
6797 isnothing(cmin) && break
6898 truncdim[cmin] -= 1
You can’t perform that action at this time.
0 commit comments