code: def _calc_prob_2samp(
      d, n1, n2, alternative, mode
  ):  # pragma: no cover
      MAX_AUTO_N = 10000  # 'auto' will attempt to be exact if n1,n2 <= MAX_AUTO_N
  
      g = gcd(n1, n2)
      n1g = n1 // g
      n2g = n2 // g
      prob = -mt.inf
      original_mode = mode
      if mode == "auto":
          mode = "exact" if max(n1, n2) <= MAX_AUTO_N else "asymp"
      elif mode == "exact":
          # If lcm(n1, n2) is too big, switch from exact to asymp
          if n1g >= np.iinfo(np.int_).max / n2g:
              mode = "asymp"
              warnings.warn(
                  f"Exact ks_2samp calculation not possible with samples sizes "
                  f"{n1} and {n2}. Switching to 'asymp'.",
                  RuntimeWarning,
              )
  
      if mode == "exact":
          success, d, prob = _attempt_exact_2kssamp(
              n1, n2, g, d, alternative
          )
          if not success:
              mode = "asymp"
              if original_mode == "exact":
                  warnings.warn(
                      f"ks_2samp: Exact calculation unsuccessful. "
                      f"Switching to mode={mode}.",
                      RuntimeWarning,
                  )
  
      if mode == "asymp":
          # The product n1*n2 is large.  Use Smirnov's asymptotic formula.
          # Ensure float to avoid overflow in multiplication
          # sorted because the one-sided formula is not symmetric in n1, n2
          m, n = sorted([float(n1), float(n2)], reverse=True)
          en = m * n / (m + n)
          if alternative == "two-sided":
              prob = distributions.kstwo.sf(d, np.round(en))
          else:
              z = np.sqrt(en) * d
              # Use Hodges' suggested approximation Eqn 5.3
              # Requires m to be the larger of (n1, n2)
              expt = (
                  -2 * z**2
                  - 2 * z * (m + 2 * n) / np.sqrt(m * n * (m + n)) / 3.0
              )
              prob = np.exp(expt)
  
      return np.clip(prob, 0, 1)
  
file_path: mars/mars/tensor/stats/ks.py
imports: import math
  import warnings
  from math import gcd
  from collections import namedtuple
  from typing import Callable, Tuple, Union
  import numpy
  from scipy import special
  from scipy.stats import distributions
  from ...None import tensor
  from ...core import ExecutableTuple
  from ...typing import TileableType
label_desc: Use image node_id 5 for calling a global function with example usage: _calc_prob_2samp(d, n1, n2, alternative, mode) and returns: np