Computing All Optimal Partial $p$-Wasserstein Matchings on the Line

Sebastian Angrick, Jacobus Conradi, Mónika Csikós, Niko Hastrich, Danny Mittal, André Nusser, Krzysztof Onak, Sharath RaghvendraNeurIPS 2026

TL;DR

Matching two sets of points on a 1D line is trivially fast if you match everything: just sort and pair them up in order. But if your data has outliers and you only want to match subsets of points (partial optimal transport), the math gets tricky, forcing existing algorithms into a sluggish quadratic bottleneck whenever distances are squared or raised to higher powers ($p > 1$). This paper breaks that quadratic barrier using a clever marriage of range trees and Fast Fourier Transforms (FFTs), computing all optimal partial matchings in near-linear time.

What Problem Does This Paper Address?

Optimal transport (specifically, the $p$-Wasserstein distance) measures the cheapest way to move probability mass from one distribution to another, where moving a unit from $a$ to $b$ costs $|a - b|^p$. While high-dimensional transport is computationally heavy, 1D transport is so fast—just $O(n \log n)$ via sorting—that many machine learning methods project high-dimensional data onto random 1D lines ("sliced Wasserstein") to scale up.

Real-world data, however, is messy and full of outliers. Instead of matching 100% of the data, we often want the Optimal Transport profile (OT-profile): the minimum cost of matching $k$ pairs of points for every $k$ from $1$ to $n$.

For $p=1$, you can compute this entire profile in $O(n \log n)$ time because you can add new matched pairs greedily without undoing previous ones. For $p > 1$ (like standard squared Euclidean cost, $p=2$), convexity ruins this neat trick. Adding just one new pair of points can force every single previously matched edge to shift over. Across all $n$ steps, $\Theta(n^2)$ distinct edges appear, trapping explicit matching algorithms in $\Theta(n^2)$ time. The authors ask: is this quadratic wall fundamental, or can we bypass it?

Methods

The authors combine a classic algorithmic framework with a brand-new data structure:

  • Standard Framework (1D Hungarian Algorithm): Building on recent work, they grow the matching one pair at a time. Instead of storing individual edges—which shift constantly—they represent the current matching implicitly as a set of disjoint balanced intervals (segments containing equal numbers of red and blue points). Within any balanced interval, points are implicitly matched in sorted order. Adding a new pair simply merges or updates adjacent intervals using a priority queue.
Figure 3: Construction of IM and adjacent free pairs.
  • What’s New (FFT-Augmented Range Tree): To pick the best next pair of free points, the algorithm must quickly ask: "What is the exact $p$-Wasserstein cost of matching all points inside this balanced interval?" Doing this naively takes linear time per query. Instead, the authors build a binary range tree over the sorted points. Because points inside a balanced interval are matched in order, every matched pair $(r_j, b_{j+d})$ shares a constant index offset, or shift $d$.
Figure 2: The order-preserving minimum-cost matching of I has shift −2. We decompose the edges of this matching that are contained in S ∩I into three disjoint matchings of cost Cost(I ∩leftS, d), Cost(I ∩rightS, d), and W(leftS, rightS, d). Note that W(rightS, leftS, −2) = 0.

Computing the costs for all possible shifts at every tree node looks quadratic at first glance. Here comes the magic trick: for integer $p$, they algebraically expand $(b_{j+d} - r_j)^p$ using the binomial theorem. This turns the sum of costs for each shift into a discrete convolution of point-coordinate powers, which they precompute simultaneously across the tree using Fast Fourier Transforms (FFT). Queries then take just $O(\log n)$ time by summing precomputed shift values across $O(\log n)$ tree nodes.

Datasets

No real-world benchmarks were used; the authors evaluate their C++ implementation (FFTHungarian) on synthetic 1D point sets of sizes $n = 10^2$ to $10^7$ drawn from continuous distributions with varying overlap:

  • Variance perturbations: $\mathcal{N}(0, 1^2)$ vs. $\mathcal{N}(0, \sigma^2)$ for $\sigma \in \{1, 1.01, 1.1, 2\}$.
  • Mean perturbations: $\mathcal{N}(0, 1^2)$ vs. $\mathcal{N}(\mu, 1^2)$ for $\mu \in \{0, 0.01, 0.1, 1\}$.
  • Bimodal perturbations: $\mathcal{N}(0, 1^2)$ vs. an equal mixture $\frac{1}{2}\mathcal{N}(-\mu, 1^2) + \frac{1}{2}\mathcal{N}(\mu, 1^2)$.

Key Insights and Ideas

  • Implicit beats explicit: Even though the sequence of optimal matchings from $k=1$ to $n$ contains $\Theta(n^2)$ unique edges, you never have to write them down. Representing matchings as balanced intervals compresses the state space to $O(n)$ and requires only a handful of interval merges per step.
  • Polynomial expansion unlocks FFT: Absolute differences $|a - b|^p$ normally resist algebraic tricks. By separating left-to-right and right-to-left crossings inside a range tree node, the signs become fixed, letting binomial expansion turn geometric transport costs into fast polynomial multiplication.
  • A sharp complexity cliff at $p = \infty$: While every finite integer $p$ yields to near-linear time, the bottleneck case ($p = \infty$, minimizing the maximum matched distance) hits a wall. The authors prove it is computationally equivalent (up to log factors) to $(\min, +)$-convolution—a notoriously hard problem in fine-grained complexity with no known near-linear algorithm.

Key Results

  • Theoretical Speedup: Computes all $k$-partial $p$-Wasserstein costs for any integer $p \in \mathbb{N}$ in $O(p\, n \log^2 n)$ time and $O(n \log n)$ space, breaking the $\Omega(n^2)$ barrier.
  • Practical Speedup: Tested at $p=2$ against the state-of-the-art optimized baseline (PAWL), FFTHungarian is significantly faster whenever $n \ge 10,000$ and the two distributions are not identical. Even with a tiny 10% difference in mean or standard deviation, PAWL degrades toward quadratic time (hitting a 60-second timeout well before $n = 10^7$), whereas FFTHungarian scales near-linearly and finishes orders of magnitude faster.
  • Lower Bound Equivalence: Proves that solving the $p=\infty$ OT-profile in $\widetilde{O}(n^{2-\varepsilon})$ time is possible if and only if $(\min, +)$-convolution can be solved in $\widetilde{O}(n^{2-\varepsilon})$ time (where the fastest currently claimed Lean-verified bound sits around $O(n^{1.9602})$).

Limitations and Future Work

  • Integer $p$ and Uniform Weights: The binomial expansion trick relies on $p$ being a finite positive integer ($p \in \mathbb{N}$), leaving fractional $p > 1$ unaddressed. Furthermore, the algorithm assumes discrete distributions supported on $n$ points with uniform mass ($1/n$ each), rather than arbitrary point weights.
  • The $p = \infty$ Bottleneck: Near-linear time does not extend to $p = \infty$ unless a major breakthrough occurs in $(\min, +)$-convolution.
  • Two-Interval Queries: As noted in their appendix results, generalizing the data structure to query transport between two separate intervals $I_B$ and $I_R$ (rather than a single shared interval $I$) runs into combinatorial Boolean matrix multiplication hardness.

Summary updated

Abstract

For $p \ge 1$, the $p$-Wasserstein distance measures the minimum cost of transporting probability mass between distributions, where moving unit mass between two points costs the $p$th power of their distance. For discrete distributions in one dimension, full transport is especially simple: after sorting, mass is matched in order along the line. By contrast, partial and unbalanced transport on the line remains much less understood. Recently, Chapel and Tavenard [ICLR'25] showed that, for $p=1$, all optimal partial transport plans between distributions supported on $n$ points, with uniform mass at each point, can be computed in $O(n\log n)$ time by exploiting the metric structure of the cost. For $p>1$, this structure no longer applies, and existing approaches require $\Omega(n^2)$ time. Our main contribution is an FFT-based data structure for balanced-interval transport queries, which bypasses this quadratic bottleneck and yields for any finite $p\ge 1$ an $O(p\,n\log^2 n)$-time algorithm for computing all optimal partial $p$-Wasserstein transports costs on the line. We also provide an open-source C++ implementation that outperforms the state-of-the-art baseline on a range of synthetic instances. Finally, we show that computing all optimal partial $\infty$-Wasserstein transport costs is (up to poly-logarithmic factors) equivalent to $(\min,+)$-convolution, for which the fastest currently claimed algorithm requires $\Omega(n^{1.96})$ time.
BibTeX
@inproceedings{angrick2026computing,
  author = {Sebastian Angrick and Jacobus Conradi and Mónika Csikós and Niko Hastrich and Danny Mittal and André Nusser and Krzysztof Onak and Sharath Raghvendra},
  title = {{Computing All Optimal Partial $p$-Wasserstein Matchings on the Line}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=88SUwJD17z},
}
Figure