code: def test_trim_to_layer_basic():
      x0 = torch.arange(4)
      edge_index0 = torch.tensor([[1, 2, 3], [0, 1, 2]])
      edge_weight0 = torch.arange(3)
  
      num_sampled_nodes_per_hop = [1, 1, 1]
      num_sampled_edges_per_hop = [1, 1, 1]
  
      x1, edge_index1, edge_weight1 = trim_to_layer(
          layer=0,
          num_sampled_nodes_per_hop=num_sampled_nodes_per_hop,
          num_sampled_edges_per_hop=num_sampled_edges_per_hop,
          x=x0,
          edge_index=edge_index0,
          edge_attr=edge_weight0,
      )
      assert torch.equal(x1, torch.arange(4))
      assert edge_index1.tolist() == [[1, 2, 3], [0, 1, 2]]
      assert torch.equal(edge_weight1, torch.arange(3))
  
      if torch_geometric.typing.WITH_TORCH_SPARSE:
          adj0 = SparseTensor.from_edge_index(
              edge_index0, edge_weight0, (4, 4)
          )
          x1, adj_t1, _ = trim_to_layer(
              layer=0,
              num_sampled_nodes_per_hop=num_sampled_nodes_per_hop,
              num_sampled_edges_per_hop=num_sampled_edges_per_hop,
              x=x0,
              edge_index=adj0.t(),
              edge_attr=edge_weight0,
          )
          adj1 = adj_t1.t()
          assert adj1.sizes() == [4, 4]
  
          row, col, value = adj1.coo()
          assert torch.equal(x1, torch.arange(4))
          assert row.tolist() == [1, 2, 3]
          assert col.tolist() == [0, 1, 2]
          assert torch.equal(value, torch.arange(3))
  
      x2, edge_index2, edge_weight2 = trim_to_layer(
          layer=1,
          num_sampled_nodes_per_hop=num_sampled_nodes_per_hop,
          num_sampled_edges_per_hop=num_sampled_edges_per_hop,
          x=x1,
          edge_index=edge_index1,
          edge_attr=edge_weight1,
      )
      assert torch.equal(x2, torch.arange(3))
      assert edge_index2.tolist() == [[1, 2], [0, 1]]
      assert torch.equal(edge_weight2, torch.arange(2))
  
      if torch_geometric.typing.WITH_TORCH_SPARSE:
          adj1 = SparseTensor.from_edge_index(
              edge_index1, edge_weight1, (4, 4)
          )
          x2, adj_t2, _ = trim_to_layer(
              layer=1,
              num_sampled_nodes_per_hop=num_sampled_nodes_per_hop,
              num_sampled_edges_per_hop=num_sampled_edges_per_hop,
              x=x1,
              edge_index=adj1.t(),
          )
          adj2 = adj_t2.t()
          assert adj2.sizes() == [3, 3]
  
          row, col, value = adj2.coo()
          assert torch.equal(x2, torch.arange(3))
          assert row.tolist() == [1, 2]
          assert col.tolist() == [0, 1]
          assert torch.equal(value, torch.arange(2))
  
      x3, edge_index3, edge_weight3 = trim_to_layer(
          layer=2,
          num_sampled_nodes_per_hop=num_sampled_nodes_per_hop,
          num_sampled_edges_per_hop=num_sampled_edges_per_hop,
          x=x2,
          edge_index=edge_index2,
          edge_attr=edge_weight2,
      )
      assert torch.equal(x3, torch.arange(2))
      assert edge_index3.tolist() == [[1], [0]]
      assert torch.equal(edge_weight3, torch.arange(1))
  
      if torch_geometric.typing.WITH_TORCH_SPARSE:
          adj2 = SparseTensor.from_edge_index(
              edge_index2, edge_weight2, (3, 3)
          )
          x3, adj_t3, _ = trim_to_layer(
              layer=2,
              num_sampled_nodes_per_hop=num_sampled_nodes_per_hop,
              num_sampled_edges_per_hop=num_sampled_edges_per_hop,
              x=x2,
              edge_index=adj2.t(),
          )
          adj3 = adj_t3.t()
          assert adj3.sizes() == [2, 2]
  
          row, col, value = adj3.coo()
          assert torch.equal(x3, torch.arange(2))
          assert row.tolist() == [1]
          assert col.tolist() == [0]
          assert torch.equal(value, torch.arange(1))
  
imports: from typing import List, Optional
  import torch
  from torch import Tensor
  import torch_geometric.typing
  from torch_geometric.data import Data
  from torch_geometric.loader import NeighborLoader
  from torch_geometric.nn import GraphConv
  from torch_geometric.testing import withPackage
  from torch_geometric.typing import SparseTensor
  from torch_geometric.utils import trim_to_layer
  from torch_geometric.utils._trim_to_layer import trim_sparse_tensor
label_desc: Use image node_id 2 for calling a global function with example usage: test_trim_to_layer_basic() without return types