code: def test_compress_weights():
      test_vecs = [
          {
              # Stimulus
              "accel": vapi.NpuAccelerator.Ethos_U55_256,
              "block_depth": 8,
              "ifm_dtype": np.uint8,
              "shape": (3, 3, 16, 64),
              "layout": "HWIO",
              "zero_point": np.int64(134),
              "dilation": (1, 1),
              "is_depthwise": False,
              # Reference outputs
              "block_traversal": vapi.NpuBlockTraversal.PART_KERNEL_FIRST,
          },
          {
              # Stimulus
              "accel": vapi.NpuAccelerator.Ethos_U55_256,
              "block_depth": 8,
              "ifm_dtype": np.uint8,
              "shape": (3, 3, 32, 64),
              "layout": "HWIO",
              "zero_point": np.int64(134),
              "dilation": (1, 1),
              "is_depthwise": False,
              # Reference outputs
              "block_traversal": vapi.NpuBlockTraversal.DEPTH_FIRST,
          },
          {
              # Stimulus
              "accel": vapi.NpuAccelerator.Ethos_U55_256,
              "block_depth": 8,
              "ifm_dtype": np.int16,
              "shape": (3, 3, 16, 64),
              "layout": "HWIO",
              "zero_point": np.int64(134),
              "dilation": (1, 1),
              "is_depthwise": False,
              # Reference outputs
              "block_traversal": vapi.NpuBlockTraversal.DEPTH_FIRST,
          },
          # Pass-through value check
          {
              # Stimulus
              "accel": vapi.NpuAccelerator.Ethos_U55_128,
              "block_depth": 16,
              "ifm_dtype": np.uint8,
              "shape": (243, 152, 7, 1),
              "layout": "HWOI",
              "zero_point": np.int64(110),
              "dilation": (2, 2),
              "is_depthwise": True,
              # Reference outputs
              "block_traversal": vapi.NpuBlockTraversal.DEPTH_FIRST,
          },
          {
              # Stimulus
              "accel": vapi.NpuAccelerator.Ethos_U55_128,
              "block_depth": 32,
              "ifm_dtype": np.uint8,
              "shape": (64, 67, 35, 8),
              "layout": "OHWI",
              "zero_point": np.int64(100),
              "dilation": (1, 2),
              "is_depthwise": False,
              # Reference outputs
              "block_traversal": vapi.NpuBlockTraversal.PART_KERNEL_FIRST,
          },
      ]
  
      def verify(test_vec, mock_obj):
          layout_transform_indices = {
              "HWIO": (3, 0, 1, 2),
              "HWOI": (2, 0, 1, 3),
              "OHWI": (0, 1, 2, 3),
          }
  
          assert mock_obj
          mock_obj.assert_called_once()
          assert (
              mock_obj.call_args[1]["accelerator"] == test_vec["accel"]
          )
          assert (
              mock_obj.call_args[1]["accelerator"] == test_vec["accel"]
          )
          ishape = test_vec["shape"]
          shape_owhi = (
              ishape[layout_transform_indices[test_vec["layout"]][0]],
              ishape[layout_transform_indices[test_vec["layout"]][1]],
              ishape[layout_transform_indices[test_vec["layout"]][2]],
              ishape[layout_transform_indices[test_vec["layout"]][3]],
          )
          assert (
              mock_obj.call_args[1]["weights_volume"].shape
              == shape_owhi
          )
          assert (
              mock_obj.call_args[1]["dilation_xy"]
              == test_vec["dilation"]
          )
          assert (
              mock_obj.call_args[1]["ifm_bitdepth"]
              == np.iinfo(test_vec["ifm_dtype"]).bits
          )
          assert (
              mock_obj.call_args[1]["ofm_block_depth"]
              == test_vec["block_depth"]
          )
          assert (
              mock_obj.call_args[1]["is_depthwise"]
              == test_vec["is_depthwise"]
          )
          assert (
              mock_obj.call_args[1]["block_traversal"]
              == test_vec["block_traversal"]
          )
  
      def create_mock(test_vec):
          with patch(
              "ethosu.vela.api.npu_encode_weights"
          ) as mock_npu_encode_weights:
              ifm_bitdepth = np.iinfo(test_vec["ifm_dtype"]).bits
              ifm_dtype = test_vec["ifm_dtype"]
              max = np.iinfo(ifm_dtype).max
              min = np.iinfo(ifm_dtype).min
              values = np.random.randint(
                  min, max, test_vec["shape"], ifm_dtype
              )
              vela_api.compress_weights(
                  weights=values,
                  weights_zp=test_vec["zero_point"],
                  weights_layout=test_vec["layout"],
                  ifm_bitdepth=ifm_bitdepth,
                  block_depth=test_vec["block_depth"],
                  dilation=test_vec["dilation"],
                  accel_config=test_vec["accel"],
                  is_depthwise=test_vec["is_depthwise"],
              )
              return mock_npu_encode_weights
  
      for tv in test_vecs:
          mock_obj = create_mock(tv)
          verify(tv, mock_obj)
  
imports: import pytest
  import numpy
  from ethosu.vela import api
  from unittest.mock import patch
  import tvm
  from tvm.script import tir
  from tvm.tir import stmt_functor
  from tvm.relay.backend.contrib.ethosu import vela_api
  import tvm.relay.backend.contrib.ethosu.tir_to_cs_translator
label_desc: Use image node_id 3 for calling a global function with example usage: test_compress_weights() and returns: mock_npu_encode_weights