code: def ks_p_value(n: int, m: int, d: float) -> float:
      """Computes the p-value for the two-sided two-sample KS test from the D-statistic.
  
      This uses the stable recursion from T. Viehmann: Numerically more stable computation of the p-values for the two-sample Kolmogorov-Smirnov test.
      """
      size = int(2 * m * d + 2)
      lastrow, row = numpy.zeros((2, size), dtype=numpy.float64)
      last_start_j = 0
      for i in range(n + 1):
          start_j = max(int(m * (i / n + d)) + 1 - size, 0)
          lastrow, row = row, lastrow
          val = 0.0
          for jj in range(size):
              j = jj + start_j
              dist = i / n - j / m
              if dist > d or dist < -d:
                  val = 1.0
              elif i == 0 or j == 0:
                  val = 0.0
              elif jj + start_j - last_start_j >= size:
                  val = (i + val * j) / (i + j)
              else:
                  val = (
                      lastrow[jj + start_j - last_start_j] * i + val * j
                  ) / (i + j)
              row[jj] = val
          jjmax = min(size, m + 1 - start_j)
          last_start_j = start_j
      return row[m - start_j]
  
file_path: TorchDrift/torchdrift/detectors/ks.py
imports: from typing import Optional
  import torch
  import numpy
  from .None import Detector
  import torchdrift.utils
label_desc: Use image node_id 1 for calling a global function with example usage: ks_p_value(n, m, d) and returns: row