code: def _pool(
      padded: np.ndarray,
      x_shape: Tuple[int],
      kernel_shape: Tuple[int],
      strides_shape: Tuple[int],
      out_shape: Tuple[int],
      pad_shape: Tuple[int],
      pooling_type: str,
      count_include_pad: Optional[int] = 0,
      ceil_mode: Optional[int] = 0,
      indices: bool = False,
      pads: Optional[np.ndarray] = None,
  ) -> np.ndarray:
      if pooling_type == "AVG":
          fpool = np.average
      elif pooling_type == "MAX":
          fpool = np.max
      else:
          raise NotImplementedError(
              f"Pooling type {pooling_type!r} does not support. Should be AVG, MAX."
          )
      spatial_size = len(x_shape) - 2
      y = np.zeros([x_shape[0], x_shape[1], *list(out_shape)])  # type: ignore
      if indices:
          z = np.full(y.shape, fill_value=-1, dtype=np.int64)
      round_fct = np.ceil if ceil_mode else np.floor
  
      def loop_range():  # type: ignore
          return [
              range(
                  int(
                      round_fct(  # type: ignore
                          float(
                              x_shape[i + 2]
                              + pad_shape[i]
                              - kernel_shape[i]
                          )
                          / float(strides_shape[i])
                          + 1
                      )
                  )
              )
              for i in range(spatial_size)
          ]
  
      for shape in itertools.product(range(x_shape[0]), range(x_shape[1]), *loop_range()):  # type: ignore
          window = padded[shape[0], shape[1]]
          listi = [
              range(
                  strides_shape[i] * shape[i + 2],
                  strides_shape[i] * shape[i + 2] + kernel_shape[i],
              )
              for i in range(spatial_size)
          ]
          listi2 = list(itertools.product(*listi))
          values = []
          for i in listi2:
              try:
                  values.append(window[i])
              except IndexError:
                  continue
          window_vals = np.array(values)
  
          if count_include_pad == 1 and pooling_type == "AVG":
              y[shape] = fpool(window_vals)
          else:
              no_nan = window_vals[np.where(~np.isnan(window_vals))]
              y[shape] = fpool(no_nan)
              if indices:
                  try:
                      window_vals_min = np.nan_to_num(
                          window_vals, nan=no_nan.min()
                      )
                  except TypeError:
                      # argument nan was introduced in numpy 1.17
                      window_vals_min = window_vals.copy()
                      window_vals_min[
                          np.isnan(window_vals_min)
                      ] = no_nan.min()
                  arg = np.argmax(window_vals_min)
                  coordinates = _get_indices(arg, out_shape)
                  delta = shape[2:] - pads[:, 0]  # type: ignore
                  coordinates += delta
                  new_arg = _get_index(coordinates, x_shape[2:])
                  z[shape] = new_arg
      if indices:
          return y.astype(padded.dtype), z  # type: ignore
      return y.astype(padded.dtype)
  
file_path: onnx/onnx/reference/ops/_op_common_pool.py
imports: import itertools
  from typing import Optional, Tuple
  import numpy
  from onnx.reference.op_run import OpRun
  from onnx.reference.ops._op_common_indices import _get_index, _get_indices
label_desc: Use image node_id 4 for calling a global function with example usage: _pool(padded, x_shape, kernel_shape, strides_shape, out_shape, pad_shape, pooling_type, count_include_pad, ceil_mode, indices, pads) and returns: y, unknown, y,  z