def build_and_fill2(self, name, dims): T = ambit.Tensor(ambit.TensorType.kCore, name, dims) N = [[0 for x in range(dims[1])] for x in range(dims[0])] data = T.tensor.data() for r in range(dims[0]): for c in range(dims[1]): value = random.random() data[r * dims[1] + c] = value N[r][c] = value return [T, N]
def build_and_fill3(self, name, dims): T = ambit.Tensor(ambit.TensorType.CoreTensor, name, dims) N = [[[0 for x in range(dims[2])] for x in range(dims[1])] for x in range(dims[0])] data = T.tensor.data() for p in range(dims[0]): for q in range(dims[1]): for r in range(dims[2]): value = random.random() data[p*dims[1]*dims[2] + q*dims[2] + r] = value N[p][q][r] = value return [T, N]
def build(self, name, dims, ttype=tensor_type, fill=None): # Builds arbitrary Tensors and numpy arrys # Accepts a list of integers or a string for dimensions if ttype != ambit.TensorType.kCore: raise ValueError("Only kCore is currently supported") if isinstance(dims, str): dims = [dim_size_dict[i] for i in dims] T = ambit.Tensor(ttype, name, dims) # Fill both N and T N = np.asarray(T) if fill: N.flat[:] = fill else: N.flat[:] = np.arange(np.prod(dims)) # Copy numpy array so we no longer share memory N = N.copy() return [T, N]
def __init__(self, world, dims, syms): self.factor = 1.0 self.world = world self.dims = dims self.syms = syms self.tensor = ambit.Tensor(world, dims, syms)