def _compress_svd_l(self, rank, relerr, svdfunc):
"""Compresses the MPA in place from right to left using SVD;
yields a right-canonical state
See :func:`~compress` for more details and arguments.
"""
assert rank > 0, "Cannot compress to rank={}".format(rank)
assert (relerr is None) or ((0. <= relerr) and (relerr <= 1.)), \
"relerr={} not allowed".format(relerr)
for site in range(len(self) - 1, 0, -1):
ltens = self._lt[site]
matshape = (ltens.shape[0], -1)
if relerr is None:
u, sv, v = svdfunc(ltens.reshape(matshape), rank)
rank_t = len(sv)
else:
u, sv, v = svd(ltens.reshape(matshape))
svsum = np.cumsum(sv) / np.sum(sv)
rank_relerr = np.searchsorted(svsum, 1 - relerr) + 1
rank_t = min(ltens.shape[0], v.shape[0], rank, rank_relerr)
yield sv, rank_t
newtens = (matdot(self._lt[site - 1], u[:, :rank_t] * sv[None, :rank_t]),
v[:rank_t, :].reshape((rank_t, ) + ltens.shape[1:]))
self._lt.update(slice(site - 1, site + 1), newtens,
canonicalization=(None, 'right'))
yield np.sum(np.abs(self._lt[0])**2)
评论列表
文章目录