code: def test_quantized_pooling():
      def check_quantized_pooling(
          data_shape,
          kernel,
          pool_type,
          pad,
          stride,
          global_pool,
          qdtype,
          convention="valid",
      ):
          if is_test_for_native_cpu():
              print(
                  "skipped testing quantized_pooling for native cpu since it is not supported yet"
              )
              return
          elif qdtype == "uint8" and is_test_for_gpu():
              print(
                  "skipped testing quantized_pooling for gpu uint8 since it is not supported yet"
              )
              return
          elif is_test_for_gpu() and len(data_shape) != 4:
              print(
                  "skipped testing quantized_pooling for gpu 5d layout since it is not supported yet"
              )
              return
  
          class PoolingBlock(mx.gluon.nn.HybridBlock):
              def __init__(
                  self,
                  kernel=kernel,
                  pad=pad,
                  stride=stride,
                  pool_type=pool_type,
                  global_pool=global_pool,
                  cudnn_off=False,
                  pooling_convention=convention,
              ):
                  super(PoolingBlock, self).__init__()
                  self._kwargs = {
                      "kernel": kernel,
                      "pad": pad,
                      "stride": stride,
                      "pool_type": pool_type,
                      "global_pool": global_pool,
                      "cudnn_off": False,
                      "pooling_convention": convention,
                  }
  
              def forward(self, data):
                  return npx.pooling(data, **self._kwargs)
  
          class QuantPoolingBlock(mx.gluon.nn.HybridBlock):
              def __init__(
                  self,
                  kernel=kernel,
                  pad=pad,
                  stride=stride,
                  pool_type=pool_type,
                  global_pool=global_pool,
                  cudnn_off=False,
                  pooling_convention=convention,
              ):
                  super(QuantPoolingBlock, self).__init__()
  
                  self._kwargs = {
                      "kernel": kernel,
                      "pad": pad,
                      "stride": stride,
                      "pool_type": pool_type,
                      "global_pool": global_pool,
                      "cudnn_off": False,
                      "pooling_convention": convention,
                  }
  
              def forward(self, data, min_data, max_data):
                  return npx.quantized_pooling(
                      data, min_data, max_data, **self._kwargs
                  )
  
          pooling_fp32 = PoolingBlock()
          if qdtype == "uint8":
              data_low = 0.0
              data_high = 127.0
          else:
              data_low = -127.0
              data_high = 127.0
  
          input_data = (
              mx.np.random.uniform(
                  low=data_low, high=data_high, size=data_shape
              )
              .astype("int32")
              .astype("float32")
          )
          output = pooling_fp32(input_data)
  
          quantized_pooling = QuantPoolingBlock(
              kernel=kernel,
              pad=pad,
              stride=stride,
              pool_type=pool_type,
              global_pool=global_pool,
              pooling_convention=convention,
          )
  
          int8_input_data = input_data.astype(qdtype)
          quantized_range = 127.0
          min_data = mx.np.array([-quantized_range])
          max_data = mx.np.array([quantized_range])
  
          qoutput, min_range, max_range = quantized_pooling(
              int8_input_data, min_data, max_data
          )
  
          if pool_type == "max":
              assert_almost_equal(output.asnumpy(), qoutput.asnumpy())
          elif (
              pool_type == "avg"
          ):  # for avg pooling, fp32 and int8 may be different due to rounding errors
              diff = mx.np.abs(output - qoutput.astype(output.dtype))
              cond = mx.np.less(2, diff).sum().item()
              assert cond == 0
  
      for qdtype in ["int8", "uint8"]:
          check_quantized_pooling(
              (3, 4, 56, 56),
              (3, 3),
              "max",
              (0, 0),
              (2, 2),
              False,
              qdtype,
          )
          check_quantized_pooling(
              (3, 4, 56, 56),
              (3, 3),
              "max",
              (0, 0),
              (2, 2),
              True,
              qdtype,
          )
          check_quantized_pooling(
              (3, 512, 7, 7),
              (7, 7),
              "avg",
              (0, 0),
              (1, 1),
              False,
              qdtype,
          )
          check_quantized_pooling(
              (3, 512, 7, 7),
              (7, 7),
              "avg",
              (0, 0),
              (1, 1),
              True,
              qdtype,
          )
          check_quantized_pooling(
              (3, 4, 3, 56, 56),
              (1, 3, 3),
              "max",
              (0, 0, 0),
              (1, 2, 2),
              False,
              qdtype,
          )
          check_quantized_pooling(
              (3, 4, 3, 56, 56),
              (1, 3, 3),
              "max",
              (0, 0, 0),
              (1, 2, 2),
              True,
              qdtype,
          )
          check_quantized_pooling(
              (3, 512, 3, 7, 7),
              (1, 7, 7),
              "avg",
              (0, 0, 0),
              (1, 2, 2),
              False,
              qdtype,
          )
          check_quantized_pooling(
              (3, 512, 3, 7, 7),
              (1, 7, 7),
              "avg",
              (0, 0, 0),
              (1, 2, 2),
              True,
              qdtype,
          )
  
          check_quantized_pooling(
              (3, 4, 56, 56),
              (3, 3),
              "max",
              (0, 0),
              (2, 2),
              False,
              qdtype,
              "full",
          )
          check_quantized_pooling(
              (3, 4, 56, 56),
              (3, 3),
              "max",
              (0, 0),
              (2, 2),
              True,
              qdtype,
              "full",
          )
          check_quantized_pooling(
              (3, 512, 7, 7),
              (7, 7),
              "avg",
              (0, 0),
              (1, 1),
              False,
              qdtype,
              "full",
          )
          check_quantized_pooling(
              (3, 512, 7, 7),
              (7, 7),
              "avg",
              (0, 0),
              (1, 1),
              True,
              qdtype,
              "full",
          )
          check_quantized_pooling(
              (3, 4, 3, 56, 56),
              (1, 3, 3),
              "max",
              (0, 0, 0),
              (1, 2, 2),
              False,
              qdtype,
              "full",
          )
          check_quantized_pooling(
              (3, 4, 3, 56, 56),
              (1, 3, 3),
              "max",
              (0, 0, 0),
              (1, 2, 2),
              True,
              qdtype,
              "full",
          )
          check_quantized_pooling(
              (3, 512, 3, 7, 7),
              (1, 7, 7),
              "avg",
              (0, 0, 0),
              (1, 2, 2),
              False,
              qdtype,
              "full",
          )
          check_quantized_pooling(
              (3, 512, 3, 7, 7),
              (1, 7, 7),
              "avg",
              (0, 0, 0),
              (1, 2, 2),
              True,
              qdtype,
              "full",
          )
  
imports: import os
  import mxnet
  import numpy
  from mxnet import npx
  from mxnet.util import use_np
  from mxnet.gluon.model_zoo import vision
  from mxnet.test_utils import assert_almost_equal, assert_exception, rand_ndarray, rand_shape_nd, same, DummyIter
  from common import xfail_when_nonstandard_decimal_separator
  from mxnet.io import NDArrayIter
  import unittest
  import operator
label_desc: Use image node_id 14 for calling a global function with example usage: test_quantized_pooling() and returns: npx, npx