code: def test_pool():
      # -----
      # uint, int
      # -----
      for dtype in [
          np.uint8,
          np.uint16,
          np.uint32,
          np.int8,
          np.int16,
          np.int32,
      ]:
          (
              min_value,
              center_value,
              max_value,
          ) = iadt.get_value_range_of_dtype(dtype)
  
          for func in [np.min, np.average, np.max]:
              arr = np.array(
                  [
                      [0, 1, 2, 3],
                      [4, 5, 6, 7],
                      [8, 9, 10, 11],
                      [12, 13, 14, 15],
                  ],
                  dtype=dtype,
              )
              arr_pooled = ia.pool(arr, 2, func)
              assert arr_pooled.shape == (2, 2)
              assert arr_pooled.dtype == np.dtype(dtype)
              assert arr_pooled[0, 0] == int(func([0, 1, 4, 5]))
              assert arr_pooled[0, 1] == int(func([2, 3, 6, 7]))
              assert arr_pooled[1, 0] == int(func([8, 9, 12, 13]))
              assert arr_pooled[1, 1] == int(func([10, 11, 14, 15]))
  
              arr = np.array(
                  [
                      [0, 1, 2, 3],
                      [4, 5, 6, 7],
                      [8, 9, 10, 11],
                      [12, 13, 14, 15],
                  ],
                  dtype=dtype,
              )
              arr = np.tile(arr[:, :, np.newaxis], (1, 1, 3))
              arr[..., 1] += 1
              arr[..., 2] += 2
              arr_pooled = ia.pool(arr, 2, func)
              assert arr_pooled.shape == (2, 2, 3)
              assert arr_pooled.dtype == np.dtype(dtype)
              for c in sm.xrange(3):
                  assert (
                      arr_pooled[0, 0, c] == int(func([0, 1, 4, 5])) + c
                  )
                  assert (
                      arr_pooled[0, 1, c] == int(func([2, 3, 6, 7])) + c
                  )
                  assert (
                      arr_pooled[1, 0, c]
                      == int(func([8, 9, 12, 13])) + c
                  )
                  assert (
                      arr_pooled[1, 1, c]
                      == int(func([10, 11, 14, 15])) + c
                  )
  
              for value in [
                  min_value,
                  min_value + 50,
                  min_value + 100,
                  0,
                  10,
                  max_value,
                  int(center_value + 0.10 * max_value),
                  int(center_value + 0.20 * max_value),
                  int(center_value + 0.25 * max_value),
                  int(center_value + 0.33 * max_value),
              ]:
                  arr = np.full((4, 4), value, dtype=dtype)
                  arr_pooled = ia.pool(arr, 2, func)
                  assert arr_pooled.shape == (2, 2)
                  assert arr_pooled.dtype == np.dtype(dtype)
                  assert np.all(arr_pooled == value)
  
                  arr = np.full((4, 4, 3), value, dtype=dtype)
                  arr_pooled = ia.pool(arr, 2, func)
                  assert arr_pooled.shape == (2, 2, 3)
                  assert arr_pooled.dtype == np.dtype(dtype)
                  assert np.all(arr_pooled == value)
  
      # -----
      # float
      # -----
      try:
          high_res_dt = np.float128
          dtypes = ["float16", "float32", "float64", "float128"]
      except AttributeError:
          high_res_dt = np.float64
          dtypes = ["float16", "float32", "float64"]
  
      for dtype in dtypes:
          dtype = np.dtype(dtype)
  
          def _allclose(a, b):
              atol = 1e-4 if dtype == np.float16 else 1e-8
              return np.allclose(a, b, atol=atol, rtol=0)
  
          for func in [np.min, np.average, np.max]:
              arr = np.array(
                  [
                      [0, 1, 2, 3],
                      [4, 5, 6, 7],
                      [8, 9, 10, 11],
                      [12, 13, 14, 15],
                  ],
                  dtype=dtype,
              )
              arr_pooled = ia.pool(arr, 2, func)
              assert arr_pooled.shape == (2, 2)
              assert arr_pooled.dtype == np.dtype(dtype)
              assert arr_pooled[0, 0] == func([0, 1, 4, 5])
              assert arr_pooled[0, 1] == func([2, 3, 6, 7])
              assert arr_pooled[1, 0] == func([8, 9, 12, 13])
              assert arr_pooled[1, 1] == func([10, 11, 14, 15])
  
              arr = np.array(
                  [
                      [0, 1, 2, 3],
                      [4, 5, 6, 7],
                      [8, 9, 10, 11],
                      [12, 13, 14, 15],
                  ],
                  dtype=dtype,
              )
              arr = np.tile(arr[:, :, np.newaxis], (1, 1, 3))
              arr[..., 1] += 1
              arr[..., 2] += 2
              arr_pooled = ia.pool(arr, 2, func)
              assert arr_pooled.shape == (2, 2, 3)
              assert arr_pooled.dtype == np.dtype(dtype)
              for c in sm.xrange(3):
                  assert arr_pooled[0, 0, c] == func([0, 1, 4, 5]) + c
                  assert arr_pooled[0, 1, c] == func([2, 3, 6, 7]) + c
                  assert arr_pooled[1, 0, c] == func([8, 9, 12, 13]) + c
                  assert (
                      arr_pooled[1, 1, c] == func([10, 11, 14, 15]) + c
                  )
  
              isize = np.dtype(dtype).itemsize
              for value in [
                  (-1) * (1000 ** (isize - 1)),
                  -50.0,
                  0.0,
                  50.0,
                  1000 ** (isize - 1),
              ]:
                  arr = np.full((4, 4), value, dtype=dtype)
                  arr_pooled = ia.pool(arr, 2, func)
                  dt = np.result_type(arr_pooled, 1.0)
                  y = np.array(
                      arr_pooled, dtype=dt, copy=False, subok=True
                  )
                  assert arr_pooled.shape == (2, 2)
                  assert arr_pooled.dtype == np.dtype(dtype)
                  assert _allclose(arr_pooled, high_res_dt(value))
  
                  arr = np.full((4, 4, 3), value, dtype=dtype)
                  arr_pooled = ia.pool(arr, 2, func)
                  assert arr_pooled.shape == (2, 2, 3)
                  assert arr_pooled.dtype == np.dtype(dtype)
                  assert _allclose(arr_pooled, high_res_dt(value))
  
      # ----
      # bool
      # ----
      arr = np.zeros((4, 4), dtype=bool)
      arr[0, 0] = True
      arr[0, 1] = True
      arr[1, 0] = True
      arr_pooled = ia.pool(arr, 2, np.min)
      assert arr_pooled.dtype == arr.dtype
      assert np.all(arr_pooled == 0)
  
      arr_pooled = ia.pool(arr, 2, np.average)
      assert arr_pooled.dtype == arr.dtype
      assert np.all(arr_pooled[0, 0] == 1)
      assert np.all(arr_pooled[:, 1] == 0)
      assert np.all(arr_pooled[1, :] == 0)
  
      arr_pooled = ia.pool(arr, 2, np.max)
      assert arr_pooled.dtype == arr.dtype
      assert np.all(arr_pooled[0, 0] == 1)
      assert np.all(arr_pooled[:, 1] == 0)
      assert np.all(arr_pooled[1, :] == 0)
  
      # preserve_dtype off
      arr = np.uint8(
          [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]
      )
      arr_pooled = ia.pool(arr, 2, np.average, preserve_dtype=False)
      assert arr_pooled.shape == (2, 2)
      assert arr_pooled.dtype == np.float64
      assert np.allclose(arr_pooled[0, 0], np.average([0, 1, 4, 5]))
      assert np.allclose(arr_pooled[0, 1], np.average([2, 3, 6, 7]))
      assert np.allclose(arr_pooled[1, 0], np.average([8, 9, 12, 13]))
      assert np.allclose(arr_pooled[1, 1], np.average([10, 11, 14, 15]))
  
      # maximum function
      arr = np.uint8(
          [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]
      )
      arr_pooled = ia.pool(arr, 2, np.max)
      assert arr_pooled.shape == (2, 2)
      assert arr_pooled.dtype == arr.dtype.type
      assert arr_pooled[0, 0] == int(np.max([0, 1, 4, 5]))
      assert arr_pooled[0, 1] == int(np.max([2, 3, 6, 7]))
      assert arr_pooled[1, 0] == int(np.max([8, 9, 12, 13]))
      assert arr_pooled[1, 1] == int(np.max([10, 11, 14, 15]))
  
      # 3d array
      arr = np.uint8(
          [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]
      )
      arr = np.tile(arr[..., np.newaxis], (1, 1, 3))
      arr_pooled = ia.pool(arr, 2, np.average)
      assert arr_pooled.shape == (2, 2, 3)
      assert np.array_equal(arr_pooled[..., 0], arr_pooled[..., 1])
      assert np.array_equal(arr_pooled[..., 1], arr_pooled[..., 2])
      arr_pooled = arr_pooled[..., 0]
      assert arr_pooled.dtype == arr.dtype.type
      assert arr_pooled[0, 0] == int(np.average([0, 1, 4, 5]))
      assert arr_pooled[0, 1] == int(np.average([2, 3, 6, 7]))
      assert arr_pooled[1, 0] == int(np.average([8, 9, 12, 13]))
      assert arr_pooled[1, 1] == int(np.average([10, 11, 14, 15]))
  
      # block_size per axis
      arr = np.float32(
          [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]
      )
      arr_pooled = ia.pool(arr, (2, 1), np.average)
      assert arr_pooled.shape == (2, 4)
      assert arr_pooled.dtype == arr.dtype.type
      assert np.allclose(arr_pooled[0, 0], np.average([0, 4]))
      assert np.allclose(arr_pooled[0, 1], np.average([1, 5]))
      assert np.allclose(arr_pooled[0, 2], np.average([2, 6]))
      assert np.allclose(arr_pooled[0, 3], np.average([3, 7]))
      assert np.allclose(arr_pooled[1, 0], np.average([8, 12]))
      assert np.allclose(arr_pooled[1, 1], np.average([9, 13]))
      assert np.allclose(arr_pooled[1, 2], np.average([10, 14]))
      assert np.allclose(arr_pooled[1, 3], np.average([11, 15]))
  
      # cval
      arr = np.uint8([[0, 1, 2], [4, 5, 6], [8, 9, 10]])
      arr_pooled = ia.pool(arr, 2, np.average)
      assert arr_pooled.shape == (2, 2)
      assert arr_pooled.dtype == arr.dtype.type
      assert arr_pooled[0, 0] == int(np.average([0, 1, 4, 5]))
      assert arr_pooled[0, 1] == int(np.average([2, 0, 6, 0]))
      assert arr_pooled[1, 0] == int(np.average([8, 9, 0, 0]))
      assert arr_pooled[1, 1] == int(np.average([10, 0, 0, 0]))
  
      arr = np.uint8([[0, 1], [4, 5]])
      arr_pooled = ia.pool(arr, (4, 1), np.average)
      assert arr_pooled.shape == (1, 2)
      assert arr_pooled.dtype == arr.dtype.type
      assert arr_pooled[0, 0] == int(np.average([0, 4, 0, 0]))
      assert arr_pooled[0, 1] == int(np.average([1, 5, 0, 0]))
  
      arr = np.uint8([[0, 1, 2], [4, 5, 6], [8, 9, 10]])
      arr_pooled = ia.pool(arr, 2, np.average, pad_cval=22)
      assert arr_pooled.shape == (2, 2)
      assert arr_pooled.dtype == arr.dtype.type
      assert arr_pooled[0, 0] == int(np.average([0, 1, 4, 5]))
      assert arr_pooled[0, 1] == int(np.average([2, 22, 6, 22]))
      assert arr_pooled[1, 0] == int(np.average([8, 9, 22, 22]))
      assert arr_pooled[1, 1] == int(np.average([10, 22, 22, 22]))
  
      # padding mode
      arr = np.uint8([[0, 1, 2], [4, 5, 6], [8, 9, 10]])
      arr_pooled = ia.pool(arr, 2, np.average, pad_mode="edge")
      assert arr_pooled.shape == (2, 2)
      assert arr_pooled.dtype == arr.dtype.type
      assert arr_pooled[0, 0] == int(np.average([0, 1, 4, 5]))
      assert arr_pooled[0, 1] == int(np.average([2, 2, 6, 6]))
      assert arr_pooled[1, 0] == int(np.average([8, 9, 8, 9]))
      assert arr_pooled[1, 1] == int(np.average([10, 10, 10, 10]))
  
      # same as above, but with float32 to make averages more accurate
      arr = np.float32([[0, 1, 2], [4, 5, 6], [8, 9, 10]])
      arr_pooled = ia.pool(arr, 2, np.average, pad_mode="edge")
      assert arr_pooled.shape == (2, 2)
      assert arr_pooled.dtype == arr.dtype.type
      assert np.isclose(arr_pooled[0, 0], np.average([0, 1, 4, 5]))
      assert np.isclose(arr_pooled[0, 1], np.average([2, 2, 6, 6]))
      assert np.isclose(arr_pooled[1, 0], np.average([8, 9, 8, 9]))
      assert np.isclose(arr_pooled[1, 1], np.average([10, 10, 10, 10]))
  
imports: from __future__ import print_function, division, absolute_import
  import time
  import warnings
  import sys
  import matplotlib
  import numpy
  import six.moves
  import cv2
  import imgaug
  from imgaug import dtypes
  import imgaug.random
  from imgaug.testutils import assertWarns
label_desc: Use image node_id 28 for calling a global function with example usage: test_pool() and returns: np