code: def batch_compute_kernel_matrix(
      x: Union[list, np.ndarray],
      y: Union[list, np.ndarray],
      kernel: Callable[[np.ndarray, np.ndarray], np.ndarray],
      batch_size: int = int(1e10),
      preprocess_fn: Optional[
          Callable[[Union[list, np.ndarray]], np.ndarray]
      ] = None,
  ) -> np.ndarray:
      """
      Compute the kernel matrix between `x` and `y` by filling in blocks of size
      `batch_size x batch_size` at a time.
  
      Parameters
      ----------
      x
          The first list/`numpy` array of data instances.
      y
          The second list/`numpy` array of data instances.
      kernel
          Kernel function to be used for kernel matrix computation.
      batch_size
          Batch size to be used for each prediction.
      preprocess_fn
          Optional preprocessing function for each batch.
  
      Returns
      -------
      Kernel matrix in the form of a `numpy` array.
      """
      if type(x) != type(y):  # noqa: E721
          raise ValueError("x and y should be of the same type")
  
      n_x, n_y = len(x), len(y)
      n_batch_x, n_batch_y = int(np.ceil(n_x / batch_size)), int(
          np.ceil(n_y / batch_size)
      )
  
      k_is = []
      for i in range(n_batch_x):
          istart, istop = i * batch_size, min((i + 1) * batch_size, n_x)
          x_batch = x[istart:istop]
          if preprocess_fn is not None:
              x_batch = preprocess_fn(x_batch)
          k_ijs = []
          for j in range(n_batch_y):
              jstart, jstop = j * batch_size, min(
                  (j + 1) * batch_size, n_y
              )
              y_batch = y[jstart:jstop]
              if preprocess_fn is not None:
                  y_batch = preprocess_fn(y_batch)
              k_ijs.append(kernel(x_batch, y_batch))  # type: ignore
          k_is.append(np.concatenate(k_ijs, axis=1))
      k_mat = np.concatenate(k_is, axis=0)
      return k_mat
  
file_path: alibi/alibi/utils/distance.py
imports: import numpy
  from sklearn.manifold import MDS
  from typing import Dict, Tuple, Callable, Optional, Union
label_desc: Use image node_id 6 for calling a global function with example usage: batch_compute_kernel_matrix(x, y, kernel, batch_size, preprocess_fn) and returns: k_mat