def get_square_matrix(shape, num_charges, dtype=np.float64): charge = BaseCharge( np.random.randint(-5, 5, (shape, num_charges)), charge_types=[U1Charge] * num_charges) flows = [True, False] indices = [Index(charge, flows[n]) for n in range(2)] return BlockSparseTensor.random(indices=indices, dtype=dtype)
def get_zeros(shape, num_charges, dtype=np.float64): R = len(shape) charges = [ BaseCharge(np.random.randint(-5, 6, (num_charges, shape[n])), charge_types=[U1Charge] * num_charges) for n in range(R) ] flows = list(np.full(R, fill_value=False, dtype=np.bool)) indices = [Index(charges[n], flows[n]) for n in range(R)] return BlockSparseTensor.zeros(indices=indices, dtype=dtype)
def get_random_symmetric(shape, flows, num_charges, seed=10, dtype=np.float64): assert np.all(np.asarray(shape) == shape[0]) np.random.seed(seed) R = len(shape) charge = BaseCharge(np.random.randint(-5, 5, (shape[0], num_charges)), charge_types=[U1Charge] * num_charges) indices = [Index(charge, flows[n]) for n in range(R)] return BlockSparseTensor.random(indices=indices, dtype=dtype)
def test_sparse_shape(num_charges): np.random.seed(10) dtype = np.float64 shape = [10, 11, 12, 13] R = len(shape) charges = [ BaseCharge(np.random.randint(-5, 5, (shape[n], num_charges)), charge_types=[U1Charge] * num_charges) for n in range(R) ] flows = list(np.full(R, fill_value=False, dtype=np.bool)) indices = [Index(charges[n], flows[n]) for n in range(R)] a = BlockSparseTensor.random(indices=indices, dtype=dtype) node = tn.Node(a, backend='symmetric') for s1, s2 in zip(node.sparse_shape, indices): assert s1 == s2
def get_ones(shape, dtype=np.float64): R = len(shape) charges = [U1Charge(np.random.randint(-5, 5, shape[n])) for n in range(R)] flows = list(np.full(R, fill_value=False, dtype=np.bool)) indices = [Index(charges[n], flows[n]) for n in range(R)] return BlockSparseTensor.ones(indices=indices, dtype=dtype)