code: def reduction(
      src: SparseTensor, dim: Optional[int] = None, reduce: str = "sum"
  ) -> torch.Tensor:
      value = src.storage.value()
  
      if dim is None:
          if value is not None:
              if reduce == "sum" or reduce == "add":
                  return value.sum()
              elif reduce == "mean":
                  return value.mean()
              elif reduce == "min":
                  return value.min()
              elif reduce == "max":
                  return value.max()
              else:
                  raise ValueError
          else:
              if reduce == "sum" or reduce == "add":
                  return torch.tensor(
                      src.nnz(), dtype=src.dtype(), device=src.device()
                  )
              elif (
                  reduce == "mean" or reduce == "min" or reduce == "max"
              ):
                  return torch.tensor(
                      1, dtype=src.dtype(), device=src.device()
                  )
              else:
                  raise ValueError
      else:
          if dim < 0:
              dim = src.dim() + dim
  
          if dim == 0 and value is not None:
              col = src.storage.col()
              return scatter(value, col, 0, None, src.size(1), reduce)
          elif dim == 0 and value is None:
              if reduce == "sum" or reduce == "add":
                  return src.storage.colcount().to(src.dtype())
              elif (
                  reduce == "mean" or reduce == "min" or reduce == "max"
              ):
                  return torch.ones(src.size(1), dtype=src.dtype())
              else:
                  raise ValueError
          elif dim == 1 and value is not None:
              return segment_csr(
                  value, src.storage.rowptr(), None, reduce
              )
          elif dim == 1 and value is None:
              if reduce == "sum" or reduce == "add":
                  return src.storage.rowcount().to(src.dtype())
              elif (
                  reduce == "mean" or reduce == "min" or reduce == "max"
              ):
                  return torch.ones(src.size(0), dtype=src.dtype())
              else:
                  raise ValueError
          elif dim > 1 and value is not None:
              if reduce == "sum" or reduce == "add":
                  return value.sum(dim=dim - 1)
              elif reduce == "mean":
                  return value.mean(dim=dim - 1)
              elif reduce == "min":
                  return value.min(dim=dim - 1)[0]
              elif reduce == "max":
                  return value.max(dim=dim - 1)[0]
              else:
                  raise ValueError
          else:
              raise ValueError
  
file_path: pytorch_sparse/torch_sparse/reduce.py
imports: from typing import Optional
  import torch
  from torch_scatter import scatter, segment_csr
  from torch_sparse.tensor import SparseTensor
label_desc: Use image node_id 1 for calling a global function with example usage: reduction(src, dim, reduce) and returns: scatter, value, torch, value, torch, src, segment_csr, value, torch, value, src, torch, value, value, value, value