diff --git a/RELEASES.md b/RELEASES.md index 9317ee06c..583918898 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -22,6 +22,7 @@ #### Closed issues +- Fix `ot.bregman.screenkhorn` failing with a shape error when `ns_budget` and `nt_budget` are the full source and target sizes and these differ (PR #871) - Fix ordinary JAX gradients for dense `ot.emd2` and preserve the magnitude and higher-order dependence of gradients supplied to `JaxBackend.set_gradients`, including the envelope gradients in `ot.solve` (Issue #625) - Fix `ot.semidiscrete_wasserstein2_unif_circle` pairing sorted sample locations with unsorted weights, which broke permutation and rotation invariance for nonuniform weights (Issue #921) - Fix an out-of-bounds read in `ot.bsp.merge_bijections`: the number of plans was taken from `perms.shape[1]` (the number of samples) instead of `perms.shape[0]`, so merging fewer plans than samples read past the array and merging more silently dropped plans. A `perms` outside the documented `(n_plans, n_samples)` layout, an empty plan stack and rows that are not permutations are now rejected (PR #911, Issue #910) diff --git a/ot/bregman/_screenkhorn.py b/ot/bregman/_screenkhorn.py index ea00a03cc..b562c0188 100644 --- a/ot/bregman/_screenkhorn.py +++ b/ot/bregman/_screenkhorn.py @@ -182,8 +182,8 @@ def projection(u, epsilon): K_IJc = [] K_IcJ = [] - vec_eps_IJc = nx.zeros((nt,), type_as=M) - vec_eps_IcJ = nx.zeros((ns,), type_as=M) + vec_eps_IJc = nx.zeros((ns,), type_as=M) + vec_eps_IcJ = nx.zeros((nt,), type_as=M) else: # sum of rows and columns of K diff --git a/test/test_bregman.py b/test/test_bregman.py index 17b400306..ddfefad3b 100644 --- a/test/test_bregman.py +++ b/test/test_bregman.py @@ -1434,6 +1434,20 @@ def test_screenkhorn(nx): np.testing.assert_allclose(G_sink.sum(1), G_screen.sum(1), atol=1e-02) + +def test_screenkhorn_full_budget_non_square(): + # with the full budget no point is screened out, which used to fail with + # a shape error whenever the source and target sizes differ + rng = np.random.RandomState(0) + ns, nt = 20, 12 + a = ot.unif(ns) + b = ot.unif(nt) + M = ot.dist(rng.randn(ns, 2), rng.randn(nt, 2)) + + G_screen = ot.bregman.screenkhorn(a, b, M, 1.0, ns_budget=ns, nt_budget=nt) + np.testing.assert_allclose(G_screen, ot.sinkhorn(a, b, M, 1.0), atol=1e-4) + + def test_convolutional_barycenter_non_square(nx): # test for image with height not equal width A = np.ones((2, 2, 3)) / (2 * 3)