code: def kolmogorov_smirnov_distance_two_sample(
      samples1, samples2, name=None
  ):
      """Computes the Kolmogorov-Smirnov distance between the given empirical CDFs.
  
      The (absolute) Kolmogorov-Smirnov distance is the maximum (absolute)
      discrepancy between the CDFs, i.e.,
  
        sup_x(|cdf1(x) - cdf2(x)|)
  
      This is tractable to compute exactly for empirical CDFs, because they are
      piecewise constant with known piece boundaries (the samples).
  
      This function works even if the samples have duplicates (e.g., if the
      underlying distribution is discrete).
  
      Args:
        samples1: Tensor of shape [n] + B.  Samples from some (batch of)
          scalar-event distribution(s) of interest, giving a (batch of) empirical
          CDF(s).  Assumed IID across the 0 dimension.
        samples2: Tensor of shape [m] + B.  Samples from some (batch of)
          scalar-event distribution(s) of interest, giving a (batch of) empirical
          CDF(s).  Assumed IID across the 0 dimension.
        name: A name for this operation (optional).
  
      Returns:
        distance: Tensor of shape B: (Absolute) Kolmogorov-Smirnov distance between
          the two empirical CDFs given by the samples.
      """
      with tf.name_scope(
          name or "kolmogorov_smirnov_distance_two_sample"
      ):
          dtype = dtype_util.common_dtype(
              [samples1, samples2], tf.float32
          )
          samples1 = tf.convert_to_tensor(
              value=samples1, name="samples1", dtype=dtype
          )
          samples2 = tf.convert_to_tensor(
              value=samples2, name="samples2", dtype=dtype
          )
          samples2 = tf.sort(samples2, axis=0, direction="ASCENDING")
  
          cdf = functools.partial(
              empirical_cdfs,
              samples2,
              continuity="right",
              dtype=samples1.dtype,
          )
          left_continuous_cdf = functools.partial(
              empirical_cdfs,
              samples2,
              continuity="left",
              dtype=samples1.dtype,
          )
          return kolmogorov_smirnov_distance(
              samples1, cdf, left_continuous_cdf
          )
  
imports: import functools
  import itertools
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.util.seed_stream import SeedStream
label_desc: Use image node_id 6 for calling a global function with example usage: kolmogorov_smirnov_distance_two_sample(samples1, samples2, name) and returns: kolmogorov_smirnov_distance