code: def pool_2d_nxn_regions(inputs, output_size, mode="max"):
      """
      Performs a pooling operation that results in a fixed size:
      output_size x output_size.
      Used by SpatialPyramidPoolingLayer. Refer to appendix A in [1]
  
      Parameters
      ----------
      inputs : a tensor with 4 dimensions (N x C x H x W)
      output_size: integer
          The output size of the pooling operation
      mode : string
          Pooling mode, one of 'max', 'average_inc_pad', 'average_exc_pad'
          Defaults to 'max'.
  
      Returns a list of tensors, for each output bin.
         The list contains output_size*output_size elements, where
         each element is a 3D tensor (N x C x 1)
  
      References
      ----------
      .. [1] He, Kaiming et al (2015):
             Spatial Pyramid Pooling in Deep Convolutional Networks
             for Visual Recognition.
             http://arxiv.org/pdf/1406.4729.pdf.
      """
  
      if mode == "max":
          pooling_op = T.max
      elif mode in ["average_inc_pad", "average_exc_pad"]:
          pooling_op = T.mean
      else:
          msg = "Mode must be either 'max', 'average_inc_pad' or "
          msg += "'average_exc_pad'. Got '{0}'"
          raise ValueError(msg.format(mode))
  
      h, w = inputs.shape[2:]
  
      result = []
      n = float(output_size)
  
      for row in range(output_size):
          for col in range(output_size):
              start_h = T.floor(row / n * h).astype("int32")
              end_h = T.ceil((row + 1) / n * h).astype("int32")
              start_w = T.floor(col / n * w).astype("int32")
              end_w = T.ceil((col + 1) / n * w).astype("int32")
  
              pooling_region = inputs[
                  :, :, start_h:end_h, start_w:end_w
              ]
              this_result = pooling_op(pooling_region, axis=(2, 3))
              result.append(this_result.dimshuffle(0, 1, "x"))
      return result
  
imports: import theano.tensor
  from .base import Layer
  from ..utils import as_tuple
label_desc: Use image node_id 4 for calling a global function with example usage: pool_2d_nxn_regions(inputs, output_size, mode) and returns: result