code: def test_pooling(pooling, padds, chans, backend):
      assert "1D" in pooling.__name__ or "2D" in pooling.__name__
  
      input_shape = (
          (18, 15, 3) if "2D" in pooling.__name__ else (121, 3)
      )
      X_input = np.random.rand(100, *input_shape)
  
      keras_model = tf.keras.models.Sequential()
      keras_model.add(pooling(padding=padds, input_shape=input_shape))
      keras_model.compile()
  
      hls_cfg = hls4ml.utils.config_from_keras_model(keras_model)
      output_dir = str(
          test_root_path
          / f"hls4mlprj_keras_api_pooling_{pooling.__name__}_channels_{chans}_padds_{padds}_backend_{backend}"
      )
      hls_model = hls4ml.converters.convert_from_keras_model(
          keras_model,
          hls_config=hls_cfg,
          output_dir=output_dir,
          backend=backend,
      )
      hls_model.compile()
  
      # Verify accuracy
      keras_prediction = keras_model.predict(X_input)
      hls_prediction = hls_model.predict(X_input).reshape(
          keras_prediction.shape
      )
      np.testing.assert_allclose(
          hls_prediction, keras_prediction, rtol=0, atol=3e-2
      )
  
      # Verify correct parsing of layer
      hls_pool = list(hls_model.get_layers())[-1]
      ker_pool = keras_model.layers[-1]
      if "2D" in pooling.__name__:
          assert hls_pool.attributes["name"] == ker_pool._name
          assert hls_pool.attributes["class_name"][-2] == str(2)
          assert (
              hls_pool.attributes["stride_height"]
              == ker_pool.strides[0]
          )
          assert (
              hls_pool.attributes["stride_width"] == ker_pool.strides[1]
          )
          assert (
              hls_pool.attributes["pool_height"]
              == ker_pool.pool_size[1]
          )
          assert (
              hls_pool.attributes["pool_width"] == ker_pool.pool_size[0]
          )
          assert hls_pool.attributes["padding"] == ker_pool.padding
  
          if hls_pool.attributes["data_format"] == "channels_last":
              assert (
                  hls_pool.attributes["in_height"]
                  == ker_pool.input_shape[1]
              )
              assert (
                  hls_pool.attributes["in_width"]
                  == ker_pool.input_shape[2]
              )
              assert (
                  hls_pool.attributes["n_filt"]
                  == ker_pool.input_shape[3]
              )
          elif hls_pool.attributes["data_format"] == "channels_first":
              assert (
                  hls_pool.attributes["in_height"]
                  == ker_pool.input_shape[2]
              )
              assert (
                  hls_pool.attributes["in_width"]
                  == ker_pool.input_shape[3]
              )
              assert (
                  hls_pool.attributes["n_filt"]
                  == ker_pool.input_shape[1]
              )
  
          if hls_pool.attributes["padding"] == "same":
              # Height
              in_height = ker_pool.input_shape[1]
              if ker_pool.data_format == "channels_first":
                  in_height = ker_pool.input_shape[2]
              out_height = int(
                  math.ceil(
                      float(in_height) / float(ker_pool.strides[0])
                  )
              )
              assert out_height == hls_pool.attributes["out_height"]
              if in_height % ker_pool.strides[0] == 0:
                  pad_along_height = max(
                      ker_pool.pool_size[1] - ker_pool.strides[0], 0
                  )
              else:
                  pad_along_height = max(
                      ker_pool.pool_size[1]
                      - (in_height % ker_pool.strides[0]),
                      0,
                  )
              pad_top = pad_along_height // 2
              pad_bottom = pad_along_height - pad_top
              assert pad_bottom == hls_pool.attributes["pad_bottom"]
              assert pad_top == hls_pool.attributes["pad_top"]
  
              # Width
              in_width = ker_pool.input_shape[2]
              if ker_pool.data_format == "channels_first":
                  in_height = keras_model.layers[1].input_shape[-1]
              out_width = int(
                  math.ceil(
                      float(in_width) / float(ker_pool.strides[1])
                  )
              )
              assert out_width == hls_pool.attributes["out_width"]
              if in_width % ker_pool.strides[1] == 0:
                  pad_along_width = max(
                      ker_pool.pool_size[0] - ker_pool.strides[1], 0
                  )
              else:
                  pad_along_width = max(
                      ker_pool.pool_size[0]
                      - (in_width % ker_pool.strides[1]),
                      0,
                  )
              pad_left = pad_along_width // 2
              pad_right = pad_along_width - pad_left
              assert pad_left == hls_pool.attributes["pad_left"]
              assert pad_right == hls_pool.attributes["pad_right"]
  
          elif hls_pool.attributes["padding"] == "valid":
              if hls_pool.attributes["data_format"] == "channels_first":
                  in_height = ker_pool.input_shape[2]
                  in_width = ker_pool.input_shape[3]
              elif (
                  hls_pool.attributes["data_format"] == "channels_last"
              ):
                  in_height = ker_pool.input_shape[1]
                  in_width = ker_pool.input_shape[2]
  
              out_width = int(
                  math.ceil(
                      float(in_width - ker_pool.pool_size[0] + 1)
                      / float(ker_pool.strides[1])
                  )
              )
              out_height = int(
                  math.ceil(
                      float(in_height - ker_pool.pool_size[1] + 1)
                      / float(ker_pool.strides[0])
                  )
              )
  
              assert hls_pool.attributes["out_height"] == out_height
              assert hls_pool.attributes["out_width"] == out_width
              assert hls_pool.attributes["pad_top"] == 0
              assert hls_pool.attributes["pad_bottom"] == 0
              assert hls_pool.attributes["pad_left"] == 0
              assert hls_pool.attributes["pad_right"] == 0
  
      elif "1D" in pooling.__name__:
          assert hls_pool.attributes["name"] == ker_pool._name
          assert hls_pool.attributes["class_name"][-2] == str(1)
          assert hls_pool.attributes["n_in"] == ker_pool.input_shape[1]
          assert (
              hls_pool.attributes["n_filt"] == ker_pool.input_shape[2]
          )
          assert (
              hls_pool.attributes["pool_width"] == ker_pool.pool_size[0]
          )
          assert (
              hls_pool.attributes["stride_width"] == ker_pool.strides[0]
          )
          assert hls_pool.attributes["padding"] == ker_pool.padding
  
          out_same = math.ceil(
              float(ker_pool.input_shape[1])
              / float(ker_pool.strides[0])
          )
          out_valid = math.ceil(
              float(ker_pool.input_shape[1] - ker_pool.pool_size[0] + 1)
              / ker_pool.strides[0]
          )
  
          if hls_pool.attributes["padding"] == "same":
              assert hls_pool.attributes["n_out"] == out_same
              if ker_pool.input_shape[1] % ker_pool.strides[0] == 0:
                  pad_along_width = max(
                      ker_pool.pool_size[0] - ker_pool.strides[0], 0
                  )
              else:
                  pad_along_width = max(
                      ker_pool.pool_size[0]
                      - (ker_pool.input_shape[1] % ker_pool.strides[0]),
                      0,
                  )
              assert (
                  hls_pool.attributes["pad_left"]
                  == pad_along_width // 2
              )
              assert (
                  hls_pool.attributes["pad_right"]
                  == pad_along_width - pad_along_width // 2
              )
  
          elif hls_pool.attributes["padding"] == "valid":
              assert hls_pool.attributes["n_out"] == out_valid
              assert hls_pool.attributes["pad_left"] == 0
              assert hls_pool.attributes["pad_right"] == 0
  
file_path: hls4ml/test/pytest/test_keras_api.py
imports: import math
  from pathlib import Path
  import numpy
  import pytest
  import tensorflow
  from tensorflow.keras.layers import ELU, Activation, AveragePooling1D, AveragePooling2D, Conv1D, Conv2D, Dense, DepthwiseConv1D, DepthwiseConv2D, LeakyReLU, MaxPooling1D, MaxPooling2D, PReLU
  import hls4ml
label_desc: Use image node_id 7 for calling a global function with example usage: test_pooling(pooling, padds, chans, backend) without return types