The KS test compares two whole distributions, not just their means. The statistic D is the largest vertical gap between the two empirical CDFs.
Implement:
ecdf(sample, x): the fraction of the sample <= x, for each value in xks_statistic(a, b): D, evaluated at every value in the pooled sampleks_pvalue(D, n, m): the asymptotic p-value. With and , it's , clipped to [0, 1]ks_test(a, b): (D, p)