def test_trace(): chinfo = chinfo3 legs = [gen_random_legcharge(chinfo, s) for s in (7, 8, 9)] legs.append(legs[1].conj()) A = npc.Array.from_func(np.random.random, legs, qtotal=[1], shape_kw='size') Aflat = A.to_ndarray() Atr = npc.trace(A, leg1=1, leg2=-1) Atr.test_sanity() Aflattr = np.trace(Aflat, axis1=1, axis2=-1) npt.assert_array_almost_equal_nulp(Atr.to_ndarray(), Aflattr, A.shape[1])
def to_dense(self): psi = self.tpmps.get_theta(0, self.tpmps.L) psi = npc.trace(psi, 'vL', 'vR') psi = psi.to_ndarray() return psi.ravel() * self.tpmps.norm