code: def test_reduce_all(shape, op, use_reduce):
      row = torch.randint(0, NUM_ROWS, (20,), device=F.ctx())
      col = torch.randint(0, NUM_COLS, (20,), device=F.ctx())
      val = torch.randn(*shape, device=F.ctx())
      val2 = val.clone()
      val = val.requires_grad_()
      val2 = val2.requires_grad_()
      A = dglsp.from_coo(row, col, val, shape=(NUM_ROWS, NUM_COLS))
  
      A2, M = _coalesce_dense(row, col, val2, NUM_ROWS, NUM_COLS, op)
  
      if not use_reduce:
          output = getattr(A, dgl_op_map[op])()
      else:
          output = A.reduce(rtype=dgl_op_map[op])
  
      if op == "mean":
          output2 = A2.sum((0, 1)) / M.sum()
      elif op == "prod":
          output2 = A2.prod(0).prod(
              0
          )  # prod() does not support tuple of dims
      else:
          output2 = getattr(A2, op)((0, 1))
      assert (output - output2).abs().max() < 1e-4
  
      head = (
          torch.randn(*output.shape).to(val)
          if output.dim() > 0
          else None
      )
      output.backward(head)
      output2.backward(head)
      assert (val.grad - val2.grad).abs().max() < 1e-4
  
file_path: dgl/tests/python/pytorch/sparse/test_reduction.py
imports: import doctest
  import operator
  import sys
  import backend
  import dgl.sparse
  import pytest
  import torch
label_desc: Use image node_id 3 for calling a global function with example usage: test_reduce_all(shape, op, use_reduce) without return types