|
33 | 33 | {"method": "gaussian"}, |
34 | 34 | {"method": "gaussian", "reg": 1}, |
35 | 35 | {"method": "gaussian_hd", "rank": 1}, |
| 36 | + {"method": "gaussian_hd", "rank": 3}, |
36 | 37 | {"method": "factored", "rank": 2}, |
37 | 38 | {"method": "lowrank", "rank": 2, "max_iter": 5}, |
38 | 39 | {"method": "nystroem", "rank": 2}, |
39 | 40 | {"method": "sliced", "n_projections": 10}, |
| 41 | + {"method": "sliced", "n_projections": 10, "metric": "euclidean"}, |
40 | 42 | {"method": "max_sliced", "n_projections": 10}, |
| 43 | + {"method": "max_sliced", "n_projections": 10, "metric": "euclidean"}, |
41 | 44 | ] |
42 | 45 |
|
43 | 46 | lst_parameters_solve_sample_NotImplemented = [ |
@@ -808,6 +811,32 @@ def test_solve_sample_methods(nx, method_params): |
808 | 811 | np.testing.assert_allclose(sol2.value, 0, atol=1e-10) |
809 | 812 |
|
810 | 813 |
|
| 814 | +def test_zero_mass_solvers(): |
| 815 | + # test that solvers handle zero mass distributions correctly |
| 816 | + n_samples_s = 10 |
| 817 | + n_samples_t = 9 |
| 818 | + n_features = 2 |
| 819 | + rng = np.random.RandomState(42) |
| 820 | + |
| 821 | + x = rng.randn(n_samples_s, n_features) |
| 822 | + y = rng.randn(n_samples_t, n_features) |
| 823 | + a = ot.utils.unif(n_samples_s) |
| 824 | + b = ot.utils.unif(n_samples_t) |
| 825 | + |
| 826 | + # Set one of the distributions to zero mass |
| 827 | + a[0] = 0.0 |
| 828 | + b[0] = 0.0 |
| 829 | + |
| 830 | + a /= a.sum() |
| 831 | + b /= b.sum() |
| 832 | + |
| 833 | + res = ot.solve_sample(x, y, a, b) |
| 834 | + res_reg = ot.solve_sample(x, y, a, b, reg=1.0) |
| 835 | + |
| 836 | + assert np.isnan(res.value) == False |
| 837 | + assert np.isnan(res_reg.value) == False |
| 838 | + |
| 839 | + |
811 | 840 | @pytest.skip_backend("tf", reason="Not implemented for tf backend") |
812 | 841 | @pytest.mark.parametrize("debias", [True, False, "split"]) |
813 | 842 | @pytest.mark.parametrize("reg", [None, 10]) |
|
0 commit comments