code: def min_num_samples_for_dkwm_cdf_test(
      discrepancy, false_fail_rate=1e-6, false_pass_rate=1e-6, name=None
  ):
      """Returns how many samples suffice for a one-sample DKWM CDF test.
  
      To wit, returns an upper bound on the number of samples necessary to
      guarantee detecting a K-S distance of CDFs of at least the given
      `discrepancy`, with the given `false_fail_rate` and `false_pass_rate`,
      using the [Dvoretzky-Kiefer-Wolfowitz-Massart inequality]
      (https://en.wikipedia.org/wiki/CDF-based_nonparametric_confidence_interval)
      on a scalar distribution.
  
      Args:
        discrepancy: Floating-point `Tensor` of desired upper limits on K-S
          distances that may go undetected with probability higher than
          `1 - false_pass_rate`.
        false_fail_rate: *Scalar* floating-point `Tensor` admissible total
          rate of false failures.
        false_pass_rate: *Scalar* floating-point `Tensor` admissible rate
          of false passes.
        name: A name for this operation (optional).
  
      Returns:
        n: `Tensor` of numbers of samples to be drawn from the distributions
          of interest.
  
      For each batch member `i`, of `K` total, drawing `n[i]` samples from some
      scalar distribution is enough to detect a K-S distribution of CDFs of size
      `discrepancy[i]` or more.  Specifically, we guarantee that (a) if the true CDF
      is the expected CDF, then `assert_true_cdf_equal_by_dkwm` will fail with
      probability at most `false_fail_rate / K` (which amounts to `false_fail_rate`
      if applied to the whole batch at once), and (b) if the true CDF differs from
      the expected CDF by at least `discrepancy[i]`, `assert_true_cdf_equal_by_dkwm`
      will pass with probability at most `false_pass_rate`.
  
      The required number of samples scales as
  
      - `O(-log(false_fail_rate/K))`,
      - `O(-log(false_pass_rate))`, and
      - `O(1 / discrepancy[i]**2)`.
      """
      with tf.name_scope(name or "min_num_samples_for_dkwm_cdf_test"):
          dtype = dtype_util.common_dtype(
              [false_fail_rate, false_pass_rate, discrepancy],
              tf.float32,
          )
          discrepancy = tf.convert_to_tensor(
              value=discrepancy, name="discrepancy", dtype=dtype
          )
          false_fail_rate = tf.convert_to_tensor(
              value=false_fail_rate, name="false_fail_rate", dtype=dtype
          )
          false_pass_rate = tf.convert_to_tensor(
              value=false_pass_rate, name="false_pass_rate", dtype=dtype
          )
          # Could choose to cleverly allocate envelopes, but this is sound.
          envelope1 = discrepancy / 2.0
          envelope2 = envelope1
          itemwise_false_fail_rate = _itemwise_error_rate(
              total_rate=false_fail_rate, param_tensors=[discrepancy]
          )
          n1 = -tf.math.log(itemwise_false_fail_rate / 2.0) / (
              2.0 * envelope1**2
          )
          n2 = -tf.math.log(false_pass_rate / 2.0) / (
              2.0 * envelope2**2
          )
          return tf.maximum(n1, n2)
  
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 3 for calling a global function with example usage: min_num_samples_for_dkwm_cdf_test(discrepancy, false_fail_rate, false_pass_rate, name) and returns: tf