def get_chargearray(num_charges, dtype=np.float64):
    D = np.random.randint(8, 12)
    charge = BaseCharge(np.random.randint(-5, 6, (num_charges, D)),
                        charge_types=[U1Charge] * num_charges)
    flow = False
    index = Index(charge, flow)
    return ChargeArray.random(indices=[index], dtype=dtype)
def test_broadcast_right_multiplication_raises():
    np.random.seed(10)
    backend = symmetric_backend.SymmetricBackend()
    num_charges = 1
    Ds = [10, 30, 24]
    R = len(Ds)
    indices = [
        Index(
            BaseCharge(np.random.randint(-5, 6, (num_charges, Ds[n])),
                       charge_types=[U1Charge] * num_charges), False)
        for n in range(R)
    ]
    tensor1 = backend.randn(indices)
    tensor2 = ChargeArray.random(indices=indices)
    with pytest.raises(ValueError):
        backend.broadcast_right_multiplication(tensor1, tensor2)
def test_broadcast_left_multiplication(dtype, num_charges):
    np.random.seed(10)
    backend = symmetric_backend.SymmetricBackend()
    Ds = [10, 30, 24]
    R = len(Ds)
    indices = [
        Index(
            BaseCharge(np.random.randint(-5, 6, (num_charges, Ds[n])),
                       charge_types=[U1Charge] * num_charges), False)
        for n in range(R)
    ]

    tensor1 = ChargeArray.random(indices=[indices[0]], dtype=dtype)
    tensor2 = backend.randn(indices, dtype=dtype)
    t1dense = tensor1.todense()
    t2dense = tensor2.todense()
    out = backend.broadcast_left_multiplication(tensor1, tensor2)
    dense = np.reshape(t1dense, (10, 1, 1)) * t2dense
    np.testing.assert_allclose(out.todense(), dense)
Exemple #4
0
def test_broadcast_right_multiplication(dtype, num_charges):
    np.random.seed(10)
    backend = symmetric_backend.SymmetricBackend()
    Ds = [10, 30, 24]
    R = len(Ds)
    indices = [
        Index(
            BaseCharge(np.random.randint(-5, 6, (Ds[n], num_charges)),
                       charge_types=[U1Charge] * num_charges), False)
        for n in range(R)
    ]
    tensor1 = backend.randn(indices, dtype=dtype)
    tensor2 = ChargeArray.random(indices=[indices[-1].copy().flip_flow()],
                                 dtype=dtype)
    t1dense = tensor1.todense()
    t2dense = tensor2.todense()
    out = backend.broadcast_right_multiplication(tensor1, tensor2)
    dense = t1dense * t2dense
    np.testing.assert_allclose(out.todense(), dense)