def svd(self, a): if not isinstance(a, self.tensor): raise TypeError('the input should be {}'.format(self.tensor.__qualname__)) if a.ndim != 2: raise TypeError('the input tensor should be a matrix') u, s, vh = ctf.svd(a.unwrap()) return self.tensor(u), self.tensor(ctf.real(s)), self.tensor(vh)
def _einsvd_reduced(self, expr, a, rank): u, s, vh = a.tsr.i(expr.inputs[0].indices_string).svd( expr.outputs[0].indices_string, expr.outputs[1].indices_string, rank=rank, ) u_newshape = expr.outputs[0].newshape(u.shape) vh_newshape = expr.outputs[1].newshape(vh.shape) if u_newshape != u.shape: u = u.reshape(*u_newshape) if vh_newshape != vh.shape: vh = vh.reshape(*vh_newshape) return self.tensor(u), self.tensor(ctf.real(s)), self.tensor(vh)
def _einsvd_reduced(self, expr, a, rank, absorb_s): u_str, vh_str = expr.outputs[0].indices_string, expr.outputs[ 1].indices_string u, s, vh = a.tsr.i(expr.inputs[0].indices_string).svd(u_str, vh_str, rank=rank) u, s, vh = self.tensor(u), self.tensor(ctf.real(s)), self.tensor(vh) u, s, vh = svd_absorb_s_ctf(u, s, vh, absorb_s, u_str, vh_str) u_newshape = expr.outputs[0].newshape(u.shape) vh_newshape = expr.outputs[1].newshape(vh.shape) if u_newshape != u.shape: u = u.reshape(*u_newshape) if vh_newshape != vh.shape: vh = vh.reshape(*vh_newshape) return u, s, vh
def real(val): try: val = ctf.real(val) except: val = npreal(val) return val