code: def cat_csr(
      tensors: List[Tensor], dim: Union[int, Tuple[int, int]]
  ) -> Tensor:
      assert dim in {0, 1, (0, 1)}
      assert tensors[0].layout == torch.sparse_csr
  
      rows, cols, values = [], [], []
      num_rows = num_cols = nnz = 0
  
      if dim == 0:
          for i, tensor in enumerate(tensors):
              if i == 0:
                  rows.append(tensor.crow_indices())
              else:
                  rows.append(tensor.crow_indices()[1:] + nnz)
              cols.append(tensor.col_indices())
              values.append(tensor.values())
              num_rows += tensor.size(0)
              num_cols = max(num_cols, tensor.size(1))
              nnz += cols[-1].numel()
  
          return torch.sparse_csr_tensor(
              crow_indices=torch.cat(rows),
              col_indices=torch.cat(cols),
              values=torch.cat(values),
              size=(num_rows, num_cols) + values[-1].size()[1:],
              device=tensor.device,
          )
  
      elif dim == 1:
          for i, tensor in enumerate(tensors):
              rows.append(ptr2index(tensor.crow_indices()))
              if i == 0:
                  cols.append(tensor.col_indices())
              else:
                  cols.append(tensor.col_indices() + num_cols)
              values.append(tensor.values())
              num_rows = max(num_rows, tensor.size(0))
              num_cols += tensor.size(1)
  
          return torch.sparse_coo_tensor(
              indices=torch.stack(
                  (torch.cat(rows), torch.cat(cols)), 0
              ),
              values=torch.cat(values),
              size=(num_rows, num_cols) + values[-1].size()[1:],
              device=tensor.device,
          )
  
      else:
          for i, tensor in enumerate(tensors):
              if i == 0:
                  rows.append(tensor.crow_indices())
                  cols.append(tensor.col_indices())
              else:
                  rows.append(tensor.crow_indices()[1:] + nnz)
                  cols.append(tensor.col_indices() + num_cols)
              values.append(tensor.values())
              num_rows += tensor.size(0)
              num_cols += tensor.size(1)
              nnz += cols[-1].numel()
  
          return torch.sparse_csr_tensor(
              crow_indices=torch.cat(rows),
              col_indices=torch.cat(cols),
              values=torch.cat(values),
              size=(num_rows, num_cols) + values[-1].size()[1:],
              device=tensor.device,
          )
  
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 14 for calling a global function with example usage: cat_csr(tensors, dim) and returns: torch, torch, torch