code: def test_segment_reduce(reducer):
      ctx = F.ctx()
      value = F.tensor(np.random.rand(10, 5))
      v1 = F.attach_grad(F.clone(value))
      v2 = F.attach_grad(F.clone(value))
      seglen = F.tensor([2, 3, 0, 4, 1, 0, 0])
      u = F.copy_to(F.arange(0, F.shape(value)[0], F.int32), ctx)
      v = F.repeat(
          F.copy_to(F.arange(0, len(seglen), F.int32), ctx),
          seglen,
          dim=0,
      )
  
      num_nodes = {"_U": len(u), "_V": len(seglen)}
      g = dgl.convert.heterograph(
          {("_U", "_E", "_V"): (u, v)}, num_nodes_dict=num_nodes
      )
      with F.record_grad():
          rst1 = gspmm(g, "copy_lhs", reducer, v1, None)
          if reducer in ["max", "min"]:
              rst1 = F.replace_inf_with_zero(rst1)
          F.backward(F.reduce_sum(rst1))
          grad1 = F.grad(v1)
  
      with F.record_grad():
          rst2 = segment_reduce(seglen, v2, reducer=reducer)
          F.backward(F.reduce_sum(rst2))
          assert F.allclose(rst1, rst2)
          print("forward passed")
  
          grad2 = F.grad(v2)
          assert F.allclose(grad1, grad2)
          print("backward passed")
  
imports: import random
  import unittest
  import backend
  import dgl
  import numpy
  import pytest
  import torch
  from dgl.ops import gather_mm, gsddmm, gspmm, segment_reduce
  from utils import parametrize_idtype
  from utils.graph_cases import get_cases
label_desc: Use image node_id 7 for calling a global function with example usage: test_segment_reduce(reducer) without return types