code: def test_add_weighted_metapaths() -> None:
      torch.manual_seed(12345)
  
      data = HeteroData()
      data["a"].num_nodes = 2
      data["b"].num_nodes = 3
      data["c"].num_nodes = 2
      data["d"].num_nodes = 2
      data["a", "b"].edge_index = tensor([[0, 1, 1], [0, 1, 2]])
      data["b", "a"].edge_index = data["a", "b"].edge_index.flip([0])
      data["b", "c"].edge_index = tensor([[0, 1, 2], [0, 1, 1]])
      data["c", "b"].edge_index = data["b", "c"].edge_index.flip([0])
      data["c", "d"].edge_index = tensor([[0, 1], [0, 0]])
      data["d", "c"].edge_index = data["c", "d"].edge_index.flip([0])
  
      metapaths = [
          [("a", "b"), ("b", "c")],
          [("a", "b"), ("b", "c"), ("c", "d")],
          [
              ("a", "b"),
              ("b", "c"),
              ("c", "d"),
              ("d", "c"),
              ("c", "b"),
              ("b", "a"),
          ],
      ]
      transform = AddMetaPaths(metapaths, weighted=True)
      out = transform(data)
  
      # Make sure manually added metapaths compute the correct number of edges:
      edge_index = out["a", "a"].edge_index
      edge_weight = out["a", "a"].edge_weight
      edge_index, edge_weight = coalesce(edge_index, edge_weight)
      assert edge_index.tolist() == [[0, 0, 1, 1], [0, 1, 0, 1]]
      assert edge_weight.tolist() == [1, 2, 2, 4]
  
      edge_index = out["a", "c"].edge_index
      edge_weight = out["a", "c"].edge_weight
      edge_index, edge_weight = coalesce(edge_index, edge_weight)
      assert edge_index.tolist() == [[0, 1], [0, 1]]
      assert edge_weight.tolist() == [1, 2]
  
      edge_index = out["a", "d"].edge_index
      edge_weight = out["a", "d"].edge_weight
      edge_index, edge_weight = coalesce(edge_index, edge_weight)
      assert edge_index.tolist() == [[0, 1], [0, 0]]
      assert edge_weight.tolist() == [1, 2]
  
      # Compute intra-table metapaths efficiently:
      metapaths = [[("a", "b"), ("b", "c"), ("c", "d")]]
      out = AddMetaPaths(metapaths, weighted=True)(data)
      out["d", "a"].edge_index = out["a", "d"].edge_index.flip([0])
      out["d", "a"].edge_weight = out["a", "d"].edge_weight
      metapaths = [[("a", "d"), ("d", "a")]]
      out = AddMetaPaths(metapaths, weighted=True)(out)
  
      edge_index = out["a", "a"].edge_index
      edge_weight = out["a", "a"].edge_weight
      edge_index, edge_weight = coalesce(edge_index, edge_weight)
      assert edge_index.tolist() == [[0, 0, 1, 1], [0, 1, 0, 1]]
      assert edge_weight.tolist() == [1, 2, 2, 4]
  
file_path: pytorch_geometric/test/transforms/test_add_metapaths.py
imports: import torch
  from torch import tensor
  from torch_geometric.data import HeteroData
  from torch_geometric.transforms import AddMetaPaths, AddRandomMetaPaths
  from torch_geometric.utils import coalesce
label_desc: Use image node_id 4 for calling a global function with example usage: test_add_weighted_metapaths() without return types