code: def permutation_test(
      x: np.ndarray,
      y: np.ndarray,
      metric: Callable,
      n_permutations: int = 100,
      **kwargs,
  ) -> Tuple[float, float, np.ndarray]:
      """
      Apply a permutation test to samples x and y.
  
      Parameters
      ----------
      x
          Batch of instances of shape [Nx, features].
      y
          Batch of instances of shape [Ny, features].
      n_permutations
          Number of permutations used in the test.
      metric
          Distance metric used for the test. Defaults to Maximum Mean Discrepancy.
      kwargs
          Kwargs for the metric. For the default this includes for instance the kernel used.
  
      Returns
      -------
      p-value obtained from the permutation test, the metric between the reference and test set \
      and the metric values from the permutation test.
      """
      n, k = x.shape[0], 0
      dist = metric(x, y, **kwargs)
      x_y = np.concatenate([x, y])
      dist_permutations = np.zeros(n_permutations)
      for _ in range(n_permutations):
          np.random.shuffle(x_y)
          x, y = x_y[:n], x_y[n:]
          dist_permutation = metric(x, y, **kwargs)
          dist_permutations[_] = dist_permutation
          k += dist <= dist_permutation
      return k / n_permutations, dist, dist_permutations
  
imports: import numpy
  from typing import Callable, Tuple, Union
label_desc: Use image node_id 1 for calling a global function with example usage: permutation_test(x, y, metric, n_permutations) and returns: unknown,  dist,  dist_permutations