code: def test_maxpool(self):
      # generate flatted images
      maxpoolshps = ((2, 2), (3, 3), (4, 4), (5, 5), (6, 6))
      rng = np.random.default_rng(2938)
      imval = rng.random((4, 5, 10, 10))
  
      images = dmatrix()
      for maxpoolshp in maxpoolshps:
          # symbolic stuff
          output, outshp = sp.max_pool(
              images, imval.shape[1:], maxpoolshp
          )
          f = function(
              [
                  images,
              ],
              [
                  output,
              ],
          )
          output_val = f(imval.reshape(imval.shape[0], -1))
  
          # numeric verification
          my_output_val = np.zeros(
              (
                  imval.shape[0],
                  imval.shape[1],
                  imval.shape[2] // maxpoolshp[0],
                  imval.shape[3] // maxpoolshp[1],
              )
          )
          assert np.prod(my_output_val.shape[1:]) == np.prod(
              np.r_[imval.shape[1], outshp]
          )
  
          for n in range(imval.shape[0]):
              for k in range(imval.shape[1]):
                  for i in range(imval.shape[2] // maxpoolshp[0]):
                      for j in range(imval.shape[3] // maxpoolshp[1]):
                          ii, jj = i * maxpoolshp[0], j * maxpoolshp[1]
                          patch = imval[
                              n,
                              k,
                              ii : ii + maxpoolshp[0],
                              jj : jj + maxpoolshp[1],
                          ]
                          my_output_val[n, k, i, j] = np.max(patch)
          my_output_val = my_output_val.reshape(imval.shape[0], -1)
          assert np.all(output_val == my_output_val)
  
          def mp(input):
              output, outshp = sp.max_pool(
                  input, imval.shape[1:], maxpoolshp
              )
              return output
  
          utt.verify_grad(mp, [imval.reshape(imval.shape[0], -1)])
  
file_path: pytensor/tests/sparse/sandbox/test_sp.py
imports: import time
  import pytest
  import numpy
  from scipy.signal import convolve2d
  from pytensor import function
  from pytensor.sparse.sandbox import sp
  from pytensor.tensor.type import dmatrix, dvector
  from tests import unittest_tools
label_desc: Use image node_id 3 for calling the TestSP obj's underlying member method code with example usage: obj.test_maxpool() and returns: output