code: def test_data():
      torch_geometric.set_debug(True)
  
      x = torch.tensor([[1, 3, 5], [2, 4, 6]], dtype=torch.float).t()
      edge_index = torch.tensor([[0, 0, 1, 1, 2], [1, 1, 0, 2, 1]])
      data = Data(x=x, edge_index=edge_index).to(torch.device("cpu"))
      data.validate(raise_on_error=True)
  
      N = data.num_nodes
      assert N == 3
  
      assert data.node_attrs() == ["x"]
      assert data.edge_attrs() == ["edge_index"]
  
      assert data.x.tolist() == x.tolist()
      assert data["x"].tolist() == x.tolist()
      assert data.get("x").tolist() == x.tolist()
      assert data.get("y", 2) == 2
      assert data.get("y", None) is None
      assert data.num_edge_types == 1
      assert data.num_node_types == 1
      assert next(data("x")) == ("x", x)
  
      assert sorted(data.keys()) == ["edge_index", "x"]
      assert len(data) == 2
      assert "x" in data and "edge_index" in data and "pos" not in data
  
      data.apply_(lambda x: x.mul_(2), "x")
      assert torch.allclose(data.x, x)
  
      data.requires_grad_("x")
      assert data.x.requires_grad is True
  
      D = data.to_dict()
      assert len(D) == 2
      assert "x" in D and "edge_index" in D
  
      D = data.to_namedtuple()
      assert len(D) == 2
      assert D.x is not None and D.edge_index is not None
  
      assert data.__cat_dim__("x", data.x) == 0
      assert data.__cat_dim__("edge_index", data.edge_index) == -1
      assert data.__inc__("x", data.x) == 0
      assert (
          data.__inc__("edge_index", data.edge_index) == data.num_nodes
      )
  
      assert not data.x.is_contiguous()
      data.contiguous()
      assert data.x.is_contiguous()
  
      assert not data.is_coalesced()
      data = data.coalesce()
      assert data.is_coalesced()
  
      clone = data.clone()
      assert clone != data
      assert len(clone) == len(data)
      assert clone.x.data_ptr() != data.x.data_ptr()
      assert clone.x.tolist() == data.x.tolist()
      assert clone.edge_index.data_ptr() != data.edge_index.data_ptr()
      assert clone.edge_index.tolist() == data.edge_index.tolist()
  
      # Test `data.to_heterogeneous()`:
      out = data.to_heterogeneous()
      assert torch.allclose(data.x, out["0"].x)
      assert torch.allclose(data.edge_index, out["0", "0"].edge_index)
  
      data.edge_type = torch.tensor([0, 0, 1, 0])
      out = data.to_heterogeneous()
      assert torch.allclose(data.x, out["0"].x)
      assert [store.num_edges for store in out.edge_stores] == [3, 1]
      data.edge_type = None
  
      data["x"] = x + 1
      assert data.x.tolist() == (x + 1).tolist()
  
      assert str(data) == "Data(x=[3, 2], edge_index=[2, 4])"
  
      dictionary = {"x": data.x, "edge_index": data.edge_index}
      data = Data.from_dict(dictionary)
      assert sorted(data.keys()) == ["edge_index", "x"]
  
      assert not data.has_isolated_nodes()
      assert not data.has_self_loops()
      assert data.is_undirected()
      assert not data.is_directed()
  
      assert data.num_nodes == 3
      assert data.num_edges == 4
      with pytest.warns(UserWarning, match="deprecated"):
          assert data.num_faces is None
      assert data.num_node_features == 2
      assert data.num_features == 2
  
      data.edge_attr = torch.randn(data.num_edges, 2)
      assert data.num_edge_features == 2
      data.edge_attr = None
  
      data.x = None
      with pytest.warns(
          UserWarning, match="Unable to accurately infer"
      ):
          assert data.num_nodes == 3
  
      data.edge_index = None
      with pytest.warns(
          UserWarning, match="Unable to accurately infer"
      ):
          assert data.num_nodes is None
      assert data.num_edges == 0
  
      data.num_nodes = 4
      assert data.num_nodes == 4
  
      data = Data(x=x, attribute=x)
      assert len(data) == 2
      assert data.x.tolist() == x.tolist()
      assert data.attribute.tolist() == x.tolist()
  
      face = torch.tensor([[0, 1], [1, 2], [2, 3]])
      data = Data(num_nodes=4, face=face)
      with pytest.warns(UserWarning, match="deprecated"):
          assert data.num_faces == 2
      assert data.num_nodes == 4
  
      data = Data(title="test")
      assert str(data) == "Data(title='test')"
      assert data.num_node_features == 0
      assert data.num_edge_features == 0
  
      key = value = "test_value"
      data[key] = value
      assert data[key] == value
      del data[value]
      del data[value]  # Deleting unset attributes should work as well.
  
      assert data.get(key) is None
      assert data.get("title") == "test"
  
      torch_geometric.set_debug(False)
  
imports: import copy
  import pytest
  import torch
  import torch.multiprocessing
  import torch_geometric
  from torch_geometric.data import Data
  from torch_geometric.data.storage import AttrType
  from torch_geometric.testing import get_random_tensor_frame, withPackage
label_desc: Use image node_id 1 for calling a global function with example usage: test_data() without return types