code: def to_torch_coo_tensor(
      edge_index: Tensor,
      edge_attr: Optional[Tensor] = None,
      size: Optional[
          Union[int, Tuple[Optional[int], Optional[int]]]
      ] = None,
      is_coalesced: bool = False,
  ) -> Tensor:
      r"""Converts a sparse adjacency matrix defined by edge indices and edge
      attributes to a :class:`torch.sparse.Tensor` with layout
      `torch.sparse_coo`.
      See :meth:`~torch_geometric.utils.to_edge_index` for the reverse operation.
  
      Args:
          edge_index (LongTensor): The edge indices.
          edge_attr (Tensor, optional): The edge attributes.
              (default: :obj:`None`)
          size (int or (int, int), optional): The size of the sparse matrix.
              If given as an integer, will create a quadratic sparse matrix.
              If set to :obj:`None`, will infer a quadratic sparse matrix based
              on :obj:`edge_index.max() + 1`. (default: :obj:`None`)
          is_coalesced (bool): If set to :obj:`True`, will assume that
              :obj:`edge_index` is already coalesced and thus avoids expensive
              computation. (default: :obj:`False`)
  
      :rtype: :class:`torch.sparse.Tensor`
  
      Example:
          >>> edge_index = torch.tensor([[0, 1, 1, 2, 2, 3],
          ...                            [1, 0, 2, 1, 3, 2]])
          >>> to_torch_coo_tensor(edge_index)
          tensor(indices=tensor([[0, 1, 1, 2, 2, 3],
                                 [1, 0, 2, 1, 3, 2]]),
                 values=tensor([1., 1., 1., 1., 1., 1.]),
                 size=(4, 4), nnz=6, layout=torch.sparse_coo)
  
      """
      if size is None:
          size = int(edge_index.max()) + 1
  
      if isinstance(size, (tuple, list)):
          num_src_nodes, num_dst_nodes = size
          if num_src_nodes is None:
              num_src_nodes = int(edge_index[0].max()) + 1
          if num_dst_nodes is None:
              num_dst_nodes = int(edge_index[1].max()) + 1
          size = (num_src_nodes, num_dst_nodes)
      else:
          size = (size, size)
  
      if not is_coalesced:
          edge_index, edge_attr = coalesce(
              edge_index, edge_attr, max(size)
          )
  
      if edge_attr is None:
          # Expanded tensors are not yet supported in all PyTorch code paths :(
          # edge_attr = torch.ones(1, device=edge_index.device)
          # edge_attr = edge_attr.expand(edge_index.size(1))
          edge_attr = torch.ones(
              edge_index.size(1), device=edge_index.device
          )
  
      adj = torch.sparse_coo_tensor(
          indices=edge_index,
          values=edge_attr,
          size=tuple(size) + edge_attr.size()[1:],
          device=edge_index.device,
      )
      adj = adj._coalesced_(True)
  
      return adj
  
imports: import typing
  import warnings
  from typing import Any, List, Optional, Tuple, Union
  import torch
  from torch import Tensor
  import torch_geometric.typing
  from torch_geometric.typing import SparseTensor
  from torch_geometric.utils import coalesce, cumsum
label_desc: Use image node_id 4 for calling a global function with example usage: to_torch_coo_tensor(edge_index, edge_attr, size, is_coalesced) and returns: adj