code: def test_forward_reduce():
      """Reduce"""
  
      class ReduceAxis(Enum):
          # pylint: disable=invalid-name
          CHW = 0
          HW = 1
          C = 2
          H = 3
          W = 4
  
      def _verify_reduce(
          input_dim, mode, axis, ref_func, dtype="float32"
      ):
          print(input_dim, mode, axis)
          a_np = np.random.uniform(size=input_dim).astype(dtype)
  
          # translate to axis from coreml format
          if axis == ReduceAxis.CHW:
              np_axis = (-3, -2, -1)
          elif axis == ReduceAxis.HW:
              np_axis = (-2, -1)
          elif axis == ReduceAxis.C:
              np_axis = -3
          elif axis == ReduceAxis.H:
              np_axis = -2
          elif axis == ReduceAxis.W:
              np_axis = -1
  
          if ref_func is np.argmax:
              ref_val = np.expand_dims(
                  ref_func(a_np, np_axis), np_axis
              ).astype(dtype)
          else:
              ref_val = ref_func(a_np, np_axis, keepdims=True)
  
          inputs = [("input", datatypes.Array(*input_dim))]
          output = [("output", datatypes.Array(*ref_val.shape))]
          builder = NeuralNetworkBuilder(inputs, output)
          builder.add_reduce(
              name=mode,
              input_name="input",
              output_name="output",
              axis=axis.name,
              mode=mode,
          )
  
          model = cm.models.MLModel(builder.spec)
          for target, dev in tvm.testing.enabled_targets():
              out = run_tvm_graph(
                  model,
                  target,
                  dev,
                  [a_np],
                  ["input"],
                  ref_val.shape,
                  dtype,
              )
              tvm.testing.assert_allclose(
                  out, ref_val, rtol=1e-5, atol=1e-5
              )
  
      dshapes = [[10, 10], [1, 10, 10], [1, 3, 10, 10]]
      for dshape in dshapes:
          for axis in ReduceAxis:
              if len(dshape) < 3 and axis in [
                  ReduceAxis.CHW,
                  ReduceAxis.C,
              ]:
                  # input must have rank at least 3
                  continue
              _verify_reduce(dshape, "sum", axis, np.sum)
              _verify_reduce(dshape, "avg", axis, np.mean)
              _verify_reduce(dshape, "prod", axis, np.prod)
              _verify_reduce(dshape, "min", axis, np.min)
              _verify_reduce(dshape, "max", axis, np.max)
              if axis in [ReduceAxis.C, ReduceAxis.H, ReduceAxis.W]:
                  # For mode ArgMax, axis must be [-1] or [-2] or [-3]
                  _verify_reduce(
                      dshape, "argmax", axis, np.argmax, dtype="int32"
                  )
  
imports: from os import path
  from enum import Enum
  import tempfile
  import numpy
  import model_zoo
  import coremltools
  from coremltools.models.neural_network import NeuralNetworkBuilder
  from coremltools.models import datatypes
  from tensorflow import keras
  import tvm
  import tvm.topi.testing
  import tvm.testing
  from tvm.contrib import graph_executor
  from tvm.topi.testing import conv2d_nchw_python
  from tvm import relay
label_desc: Use image node_id 33 for calling a global function with example usage: test_forward_reduce() without return types