code: def _validate_bounding_result(
      matrix: np.ndarray,
      x: np.ndarray,
      y: np.ndarray,
      all_finite: bool = False,
      all_infinite: bool = False,
      is_gradient_bounding: bool = False,
  ):
      """Validate the bounding matrix is what is expected.
  
      Parameters
      ----------
      matrix: np.ndarray (2d array)
          Bounding matrix.
      x: np.ndarray (1d, 2d or 3d array)
          First time series.
      y: np.ndarray (1d, 2d or 3d array)
          Second time series.
      all_finite: bool, default = False
          Boolean that when true will check all the values are finite.
      all_infinite: bool, default = False
          Boolean that when true will check all the values (aside the middle diagonal)
          are infinite.
      is_gradient_bounding: bool, default = False
          Boolean that when true marks the bounding matrix as generated by an algorithm
          that uses a gradient and therefore the first a second column are allowed to
          be finite (aside the first and last element in the matrix).
      """
      assert isinstance(matrix, np.ndarray), (
          f"A bounding matrix must be of type np.ndarray. Instead one was provided with "
          f"{type(matrix)} type."
      )
      assert matrix.ndim == 2, (
          f"A bounding matrix must have two dimensions. Instead one was provided with "
          f"{matrix.ndim} dimensions."
      )
      assert matrix.shape == (len(x), len(y)), (
          f"A bounding matrix with shape len(x) by len(y) is expected ({len(x), len(y)}. "
          f"Instead one was given with shape {matrix.shape}"
      )
  
      unique, counts = np.unique(matrix, return_counts=True)
      count_dict = dict(zip(unique, counts))
  
      for key in count_dict:
          if np.isfinite(key):
              assert (
                  count_dict[key] >= len(y) or all_infinite is False
              ), (
                  "All the values in the bounding matrix should be finite. A infinite "
                  "value was found (aside from the diagonal)."
              )
          else:
              if is_gradient_bounding:
                  max_infinite = (
                      len(y) + len(x) - 2
                  )  # -2 as 0,0 and n,m should be finite
                  assert (
                      count_dict[key] >= max_infinite
                      or all_finite is False
                  ), (
                      "All values in the bounding matrix should be infinite. Aside"
                      "from the first column and last column."
                  )
              else:
                  assert all_finite is False, (
                      "All values in the bounding matrix should be"
                      "infinite. A finite value was found"
                  )
  
file_path: sktime/sktime/distances/tests/test_lower_bounding.py
imports: import numpy
  import pandas
  import pytest
  from sktime.distances.lower_bounding import LowerBounding
  from sktime.distances.tests._utils import create_test_distance_numpy
label_desc: Use image node_id 1 for calling a global function with example usage: _validate_bounding_result(matrix, x, y, all_finite, all_infinite, is_gradient_bounding) without return types