(nx, metric)
| 1164 | @pytest.skip_backend("jax") |
| 1165 | @pytest.mark.parametrize("metric", ["sqeuclidean", "euclidean"]) |
| 1166 | def test_geomloss_solver(nx, metric): |
| 1167 | # test sinkhorn |
| 1168 | n = 10 |
| 1169 | a = ot.unif(n) |
| 1170 | b = ot.unif(n) |
| 1171 | |
| 1172 | X_s = np.reshape(1.0 * np.arange(n), (n, 1)) |
| 1173 | X_t = np.reshape(1.0 * np.arange(0, n), (n, 1)) |
| 1174 | |
| 1175 | ab, bb, X_sb, X_tb = nx.from_numpy(a, b, X_s, X_t) |
| 1176 | |
| 1177 | G_sqe = nx.to_numpy(ot.bregman.empirical_sinkhorn(X_sb, X_tb, 1, metric=metric)) |
| 1178 | |
| 1179 | value, log = ot.bregman.empirical_sinkhorn2_geomloss( |
| 1180 | X_sb, X_tb, 1, metric=metric, log=True |
| 1181 | ) |
| 1182 | G_geomloss = nx.to_numpy(log["lazy_plan"][:]) |
| 1183 | |
| 1184 | print(value) |
| 1185 | |
| 1186 | # call with log = False |
| 1187 | ot.bregman.empirical_sinkhorn2_geomloss(X_sb, X_tb, 1, metric=metric) |
| 1188 | |
| 1189 | # check equality of plans |
| 1190 | np.testing.assert_allclose(G_sqe, G_geomloss, atol=1e-03) # metric sqeuclidian |
| 1191 | |
| 1192 | # check error on wrong metric |
| 1193 | with pytest.raises(ValueError): |
| 1194 | ot.bregman.empirical_sinkhorn2_geomloss(X_sb, X_tb, 1, metric="wrong_metric") |
| 1195 | |
| 1196 | |
| 1197 | def test_lazy_empirical_sinkhorn(nx): |
nothing calls this directly
no test coverage detected