code: def check_metric_serialization(
      metric: Metric,
      y_true: Union[tuple, np.ndarray],
      y_pred: Union[tuple, np.ndarray],
      sample_weight: Union[tuple, np.ndarray, None] = None,
      strict: bool = True,
  ):
      config = metric.get_config()
      class_ = metric.__class__
  
      check_config(config, class_, strict)
  
      metric_copy = class_(**config)
      metric_copy.set_weights(metric.get_weights())
  
      if isinstance(y_true, tuple):
          y_true = get_random_array(y_true)
      if isinstance(y_pred, tuple):
          y_pred = get_random_array(y_pred)
      if isinstance(sample_weight, tuple) and sample_weight is not None:
          sample_weight = get_random_array(sample_weight)
  
      # the behavior should be the same for the original and the copy
      if sample_weight is None:
          metric.update_state(y_true, y_pred)
          metric_copy.update_state(y_true, y_pred)
      else:
          metric.update_state(y_true, y_pred, sample_weight)
          metric_copy.update_state(y_true, y_pred, sample_weight)
  
      assert_all_arrays_close(
          metric.get_weights(), metric_copy.get_weights()
      )
      metric_result = metric.result().numpy()
      metric_copy_result = metric_copy.result().numpy()
  
      try:
          np.testing.assert_allclose(metric_result, metric_copy_result)
      except AssertionError as e:
          raise ValueError(
              "The original and the copy of the metric give different results after "
              "the same `.update_states()` call."
          ) from e
  
file_path: addons/tensorflow_addons/testing/serialization.py
imports: from typing import Union
  import inspect
  import numpy
  from tensorflow.keras.metrics import Metric
  import typeguard
label_desc: Use image node_id 1 for calling a global function with example usage: check_metric_serialization(metric, y_true, y_pred, sample_weight, strict) without return types