code: def max_pooling(_input, pool_shape, pool_stride, padding="VALID"):
      """Helper function for performing max pooling.
  
      Args:
          _input (tf.Tensor): Input tf.Tensor to the CNN.
          pool_shape (int): Dimension of the pooling layer.
          pool_stride (int): The stride of the pooling layer.
          padding (str): The type of padding algorithm to use, either 'SAME'
              or 'VALID'.
  
      Return:
          tf.Tensor: The output tf.Tensor after max pooling.
  
      """
      batch_size = _input.shape[0]
      if padding == "VALID":
          height_size = (
              int((_input.shape[1] - pool_shape) / pool_stride) + 1
          )
          width_size = (
              int((_input.shape[2] - pool_shape) / pool_stride) + 1
          )
      else:
          height_size = int(
              (_input.shape[1] + pool_stride - 1) / pool_stride
          )
          width_size = int(
              (_input.shape[2] + pool_stride - 1) / pool_stride
          )
  
      # max pooling
      results = np.empty(
          (batch_size, height_size, width_size, _input.shape[3])
      )
      for b in range(batch_size):
          for i in range(0, results.shape[1]):
              for j in range(0, results.shape[2]):
                  for k in range(_input.shape[3]):
                      row = i * pool_shape
                      col = j * pool_shape
                      results[b][i][j][k] = np.max(
                          _input[
                              b,
                              row : row + pool_shape,
                              col : col + pool_shape,  # noqa: W504
                              k,
                          ]
                      )
  
      return results
  
file_path: garage/tests/helpers.py
imports: import cloudpickle
  import numpy
  import pytest
  from garage import Environment
  from tests.quirks import KNOWN_GYM_RENDER_NOT_IMPLEMENTED
label_desc: Use image node_id 7 for calling a global function with example usage: max_pooling(_input, pool_shape, pool_stride, padding) and returns: results