code: def reduce_axes(X, axes, reducer, atype=None):
      def get_index(idx, ridx):
          j = 0
          k = 0
          ret = []
          for val in axes:
              ret.append(idx[j] if val == 0 else ridx[k])
              j += val == 0
              k += val != 0
          return tuple(ret)
  
      ishape = X.shape
      odim = (len(ishape) + 1 - axes[0]) // 2
      oshape = [tvm.te.size_var() for _ in range(odim)]
      ridx = [
          tvm.te.reduce_axis((0, ishape[i]))
          for (i, val) in enumerate(axes)
          if val == 1
      ]
      ret = tvm.te.compute(
          oshape,
          lambda *idx: reducer(
              X[get_index(idx, ridx)].astype(atype)
              if atype
              else X[get_index(idx, ridx)],
              axis=ridx,
          ),
          name="ret",
      )
      return ret
  
label_desc: Use image node_id 2 for calling a global function with example usage: reduce_axes(X, axes, reducer, atype) and returns: ret, tuple