code: def test_batch_basic():
      torch_geometric.set_debug(True)
  
      x = torch.tensor([1.0, 2.0, 3.0])
      edge_index = torch.tensor([[0, 1, 1, 2], [1, 0, 2, 1]])
      data1 = Data(
          x=x,
          y=1,
          edge_index=edge_index,
          string="1",
          array=["1", "2"],
          num_nodes=3,
      )
  
      x = torch.tensor([1.0, 2.0])
      edge_index = torch.tensor([[0, 1], [1, 0]])
      data2 = Data(
          x=x,
          y=2,
          edge_index=edge_index,
          string="2",
          array=["3", "4", "5"],
          num_nodes=2,
      )
  
      x = torch.tensor([1.0, 2.0, 3.0, 4.0])
      edge_index = torch.tensor(
          [[0, 1, 1, 2, 2, 3], [1, 0, 2, 1, 3, 2]]
      )
      data3 = Data(
          x=x,
          y=3,
          edge_index=edge_index,
          string="3",
          array=["6", "7", "8", "9"],
          num_nodes=4,
      )
  
      batch = Batch.from_data_list([data1])
      assert str(batch) == (
          "DataBatch(x=[3], edge_index=[2, 4], y=[1], "
          "string=[1], array=[1], num_nodes=3, batch=[3], "
          "ptr=[2])"
      )
      assert batch.num_graphs == len(batch) == 1
      assert batch.x.tolist() == [1, 2, 3]
      assert batch.y.tolist() == [1]
      assert batch.edge_index.tolist() == [[0, 1, 1, 2], [1, 0, 2, 1]]
      assert batch.string == ["1"]
      assert batch.array == [["1", "2"]]
      assert batch.num_nodes == 3
      assert batch.batch.tolist() == [0, 0, 0]
      assert batch.ptr.tolist() == [0, 3]
  
      batch = Batch.from_data_list(
          [data1, data2, data3], follow_batch=["string"]
      )
  
      assert str(batch) == (
          "DataBatch(x=[9], edge_index=[2, 12], y=[3], "
          "string=[3], string_batch=[3], string_ptr=[4], "
          "array=[3], num_nodes=9, batch=[9], ptr=[4])"
      )
      assert batch.num_graphs == len(batch) == 3
      assert batch.x.tolist() == [1, 2, 3, 1, 2, 1, 2, 3, 4]
      assert batch.y.tolist() == [1, 2, 3]
      assert batch.edge_index.tolist() == [
          [0, 1, 1, 2, 3, 4, 5, 6, 6, 7, 7, 8],
          [1, 0, 2, 1, 4, 3, 6, 5, 7, 6, 8, 7],
      ]
      assert batch.string == ["1", "2", "3"]
      assert batch.string_batch.tolist() == [0, 1, 2]
      assert batch.string_ptr.tolist() == [0, 1, 2, 3]
      assert batch.array == [
          ["1", "2"],
          ["3", "4", "5"],
          ["6", "7", "8", "9"],
      ]
      assert batch.num_nodes == 9
      assert batch.batch.tolist() == [0, 0, 0, 1, 1, 2, 2, 2, 2]
      assert batch.ptr.tolist() == [0, 3, 5, 9]
  
      assert str(batch[0]) == (
          "Data(x=[3], edge_index=[2, 4], y=[1], "
          "string='1', array=[2], num_nodes=3)"
      )
      assert str(batch[1]) == (
          "Data(x=[2], edge_index=[2, 2], y=[1], "
          "string='2', array=[3], num_nodes=2)"
      )
      assert str(batch[2]) == (
          "Data(x=[4], edge_index=[2, 6], y=[1], "
          "string='3', array=[4], num_nodes=4)"
      )
  
      assert len(batch.index_select([1, 0])) == 2
      assert len(batch.index_select(torch.tensor([1, 0]))) == 2
      assert len(batch.index_select(torch.tensor([True, False]))) == 1
      assert (
          len(batch.index_select(np.array([1, 0], dtype=np.int64))) == 2
      )
      assert len(batch.index_select(np.array([True, False]))) == 1
      assert len(batch[:2]) == 2
  
      data_list = batch.to_data_list()
      assert len(data_list) == 3
  
      assert len(data_list[0]) == 6
      assert data_list[0].x.tolist() == [1, 2, 3]
      assert data_list[0].y.tolist() == [1]
      assert data_list[0].edge_index.tolist() == [
          [0, 1, 1, 2],
          [1, 0, 2, 1],
      ]
      assert data_list[0].string == "1"
      assert data_list[0].array == ["1", "2"]
      assert data_list[0].num_nodes == 3
  
      assert len(data_list[1]) == 6
      assert data_list[1].x.tolist() == [1, 2]
      assert data_list[1].y.tolist() == [2]
      assert data_list[1].edge_index.tolist() == [[0, 1], [1, 0]]
      assert data_list[1].string == "2"
      assert data_list[1].array == ["3", "4", "5"]
      assert data_list[1].num_nodes == 2
  
      assert len(data_list[2]) == 6
      assert data_list[2].x.tolist() == [1, 2, 3, 4]
      assert data_list[2].y.tolist() == [3]
      assert data_list[2].edge_index.tolist() == [
          [0, 1, 1, 2, 2, 3],
          [1, 0, 2, 1, 3, 2],
      ]
      assert data_list[2].string == "3"
      assert data_list[2].array == ["6", "7", "8", "9"]
      assert data_list[2].num_nodes == 4
  
      torch_geometric.set_debug(True)
  
imports: import os.path
  import numpy
  import pytest
  import torch
  import torch_geometric
  from torch_geometric import EdgeIndex
  from torch_geometric.data import Batch, Data, HeteroData
  from torch_geometric.testing import get_random_edge_index, withPackage
  from torch_geometric.typing import SparseTensor
  from torch_geometric.utils import to_edge_index, to_torch_sparse_tensor
label_desc: Use image node_id 1 for calling a global function with example usage: test_batch_basic() without return types