code: def test_to_sparse_tensor_num_nodes_equals_num_edges():
      x = torch.arange(4)
      y = torch.arange(4)
      edge_index = torch.tensor([[0, 1, 1, 2], [1, 0, 2, 1]])
      edge_weight = torch.randn(edge_index.size(1))
      edge_attr = torch.randn(edge_index.size(1), 8)
  
      perm = torch.tensor([1, 0, 3, 2])
  
      data = Data(
          x=x,
          edge_index=edge_index,
          edge_weight=edge_weight,
          edge_attr=edge_attr,
          y=y,
      )
      data = ToSparseTensor()(data)
  
      assert len(data) == 4
      assert torch.equal(data.x, x)
      assert torch.equal(data.y, y)
      assert torch.equal(data.edge_attr, edge_attr[perm])
  
file_path: pytorch_geometric/test/transforms/test_to_sparse_tensor.py
imports: import pytest
  import torch
  import torch_geometric.typing
  from torch_geometric.data import Data, HeteroData
  from torch_geometric.transforms import ToSparseTensor
label_desc: Use image node_id 4 for calling a global function with example usage: test_to_sparse_tensor_num_nodes_equals_num_edges() without return types