def _ltens_to_array(ltens):
"""Computes the full array representation from an iterator yielding the
local tensors. Note that it does not get rid of virtual legs.
:param ltens: Iterator over local tensors
:returns: numpy.ndarray representing the contracted MPA
"""
ltens = ltens if isinstance(ltens, collections.Iterator) else iter(ltens)
res = first = next(ltens)
for tens in ltens:
res = matdot(res, tens)
if res is first:
# Always return a writable array, even if len(ltens) == 1.
res = res.copy()
return res
################################################
# Helper methods for variational compression #
################################################
评论列表
文章目录