コード例 #1
0
def test_contract_parallel(backend):
    a = tn.Node(np.eye(2), backend=backend)
    b = tn.Node(np.eye(2), backend=backend)
    edge1 = tn.connect(a[0], b[0])
    tn.connect(a[1], b[1])
    c = tn.contract_parallel(edge1)
    np.testing.assert_allclose(c.tensor, 2.0)
コード例 #2
0
def test_contract_copy_node_connected_neighbors(backend):
    a = tn.Node(np.array([[1, 2, 3], [10, 20, 30]]), backend=backend)
    b = tn.Node(np.array([[2, 1, 1], [2, 2, 2]]), backend=backend)
    c = tn.Node(np.array([3, 4, 4]), backend=backend)
    cn = tn.CopyNode(rank=3, dimension=3, backend=backend)
    tn.connect(a[0], b[0])
    tn.connect(a[1], cn[0])
    tn.connect(b[1], cn[1])
    tn.connect(c[0], cn[2])

    n = tn.contract_copy_node(cn)

    assert len(n.edges) == 2
    assert n.edges[0] == n.edges[1]

    val = tn.contract_parallel(n.edges[0])
    result = val.tensor
    assert list(result.shape) == []
    np.testing.assert_allclose(result, 26 + 460)