From 61131ccd32efffe2b721d0862fc94fc2d43b403d Mon Sep 17 00:00:00 2001 From: Nathan Cassereau Date: Fri, 3 Jun 2022 16:53:21 +0200 Subject: [PATCH 01/10] avoid overflow on openmp version of emd solver --- ot/lp/EMD_wrapper.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ot/lp/EMD_wrapper.cpp b/ot/lp/EMD_wrapper.cpp index 457216bc4..ccb3c0be3 100644 --- a/ot/lp/EMD_wrapper.cpp +++ b/ot/lp/EMD_wrapper.cpp @@ -126,7 +126,7 @@ int EMD_wrap_omp(int n1, int n2, double *X, double *Y, double *D, double *G, // beware M and C are stored in row major C style!!! using namespace lemon_omp; - int n, m, cur; + uint64_t n, m, cur; typedef FullBipartiteDigraph Digraph; DIGRAPH_TYPEDEFS(Digraph); @@ -153,15 +153,15 @@ int EMD_wrap_omp(int n1, int n2, double *X, double *Y, double *D, double *G, // Define the graph - std::vector indI(n), indJ(m); + std::vector indI(n), indJ(m); std::vector weights1(n), weights2(m); Digraph di(n, m); - NetworkSimplexSimple net(di, true, n+m, ((int64_t)n)*((int64_t)m), maxIter, numThreads); + NetworkSimplexSimple net(di, true, (int) (n + m), n * m, maxIter, numThreads); // Set supply and demand, don't account for 0 values (faster) cur=0; - for (int i=0; i0) { weights1[ cur ] = val; @@ -172,7 +172,7 @@ int EMD_wrap_omp(int n1, int n2, double *X, double *Y, double *D, double *G, // Demand is actually negative supply... cur=0; - for (int i=0; i0) { weights2[ cur ] = -val; @@ -181,12 +181,12 @@ int EMD_wrap_omp(int n1, int n2, double *X, double *Y, double *D, double *G, } - net.supplyMap(&weights1[0], n, &weights2[0], m); + net.supplyMap(&weights1[0], (int) n, &weights2[0], (int) m); // Set the cost of each edge int64_t idarc = 0; - for (int i=0; i Date: Tue, 7 Jun 2022 13:11:51 +0200 Subject: [PATCH 02/10] monothread version updated --- ot/lp/EMD_wrapper.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ot/lp/EMD_wrapper.cpp b/ot/lp/EMD_wrapper.cpp index ccb3c0be3..16458d028 100644 --- a/ot/lp/EMD_wrapper.cpp +++ b/ot/lp/EMD_wrapper.cpp @@ -24,7 +24,7 @@ int EMD_wrap(int n1, int n2, double *X, double *Y, double *D, double *G, // beware M and C are stored in row major C style!!! using namespace lemon; - int n, m, cur; + uint64_t n, m, cur; typedef FullBipartiteDigraph Digraph; DIGRAPH_TYPEDEFS(Digraph); @@ -51,15 +51,15 @@ int EMD_wrap(int n1, int n2, double *X, double *Y, double *D, double *G, // Define the graph - std::vector indI(n), indJ(m); + std::vector indI(n), indJ(m); std::vector weights1(n), weights2(m); Digraph di(n, m); - NetworkSimplexSimple net(di, true, n+m, ((int64_t)n)*((int64_t)m), maxIter); + NetworkSimplexSimple net(di, true, (int) (n + m), n * m, maxIter); // Set supply and demand, don't account for 0 values (faster) cur=0; - for (int i=0; i0) { weights1[ cur ] = val; @@ -70,7 +70,7 @@ int EMD_wrap(int n1, int n2, double *X, double *Y, double *D, double *G, // Demand is actually negative supply... cur=0; - for (int i=0; i0) { weights2[ cur ] = -val; @@ -83,8 +83,8 @@ int EMD_wrap(int n1, int n2, double *X, double *Y, double *D, double *G, // Set the cost of each edge int64_t idarc = 0; - for (int i=0; i Date: Tue, 7 Jun 2022 13:18:26 +0200 Subject: [PATCH 03/10] Fixed typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 12340d525..4c69e0a6b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ POT provides the following generic OT solvers (links to examples): * Debiased Sinkhorn barycenters [Sinkhorn divergence barycenter](https://pythonot.github.io/auto_examples/barycenters/plot_debiased_barycenter.html) [37] * [Smooth optimal transport solvers](https://pythonot.github.io/auto_examples/plot_OT_1D_smooth.html) (dual and semi-dual) for KL and squared L2 regularizations [17]. * Weak OT solver between empirical distributions [39] -* Non regularized [Wasserstein barycenters [16] ](https://pythonot.github.io/auto_examples/barycenters/plot_barycenter_lp_vs_entropic.html)) with LP solver (only small scale). +* Non regularized [Wasserstein barycenters [16] ](https://pythonot.github.io/auto_examples/barycenters/plot_barycenter_lp_vs_entropic.html) with LP solver (only small scale). * [Gromov-Wasserstein distances](https://pythonot.github.io/auto_examples/gromov/plot_gromov.html) and [GW barycenters](https://pythonot.github.io/auto_examples/gromov/plot_gromov_barycenter.html) (exact [13] and regularized [12]), differentiable using gradients from * [Fused-Gromov-Wasserstein distances solver](https://pythonot.github.io/auto_examples/gromov/plot_fgw.html#sphx-glr-auto-examples-plot-fgw-py) and [FGW barycenters](https://pythonot.github.io/auto_examples/gromov/plot_barycenter_fgw.html) [24] * [Stochastic From fd991739d124279da73dbdfe0403b03e8172236e Mon Sep 17 00:00:00 2001 From: Nathan Cassereau Date: Tue, 7 Jun 2022 13:18:37 +0200 Subject: [PATCH 04/10] added PR in releases --- RELEASES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index fdaff590d..4779e4305 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -13,7 +13,8 @@ - Fixed an issue where Sinkhorn solver assumed a symmetric cost matrix (Issue #374, PR #375) - Fixed an issue where hitting iteration limits would be reported to stderr by std::cerr regardless of Python's stderr stream status (PR #377) - Fixed an issue where the metric argument in ot.dist did not allow a callable parameter (Issue #378, PR #379) -- Fixed an issue where the max number of iterations in ot.emd was not allow to go beyond 2^31 (PR #380) +- Fixed an issue where the max number of iterations in ot.emd was not allow to go beyond 2^31 (PR #380) +- Fixed an issue where pointers would overflow in the EMD solver, returning an incomplete transport plan above a certain size (PR #381) ## 0.8.2 From af8f72182cd840b88724d6322e8d429adcb1ed04 Mon Sep 17 00:00:00 2001 From: Nathan Cassereau Date: Tue, 7 Jun 2022 13:20:22 +0200 Subject: [PATCH 05/10] typo in releases.md --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index 4779e4305..178cb8583 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -13,7 +13,7 @@ - Fixed an issue where Sinkhorn solver assumed a symmetric cost matrix (Issue #374, PR #375) - Fixed an issue where hitting iteration limits would be reported to stderr by std::cerr regardless of Python's stderr stream status (PR #377) - Fixed an issue where the metric argument in ot.dist did not allow a callable parameter (Issue #378, PR #379) -- Fixed an issue where the max number of iterations in ot.emd was not allow to go beyond 2^31 (PR #380) +- Fixed an issue where the max number of iterations in ot.emd was not allowed to go beyond 2^31 (PR #380) - Fixed an issue where pointers would overflow in the EMD solver, returning an incomplete transport plan above a certain size (PR #381) From c52aa3315f5465d46bed000c98ef22da98cf02bf Mon Sep 17 00:00:00 2001 From: Nathan Cassereau Date: Tue, 7 Jun 2022 13:26:21 +0200 Subject: [PATCH 06/10] added a precision to releases.md --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index 178cb8583..f540ee7c2 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -14,7 +14,7 @@ - Fixed an issue where hitting iteration limits would be reported to stderr by std::cerr regardless of Python's stderr stream status (PR #377) - Fixed an issue where the metric argument in ot.dist did not allow a callable parameter (Issue #378, PR #379) - Fixed an issue where the max number of iterations in ot.emd was not allowed to go beyond 2^31 (PR #380) -- Fixed an issue where pointers would overflow in the EMD solver, returning an incomplete transport plan above a certain size (PR #381) +- Fixed an issue where pointers would overflow in the EMD solver, returning an incomplete transport plan above a certain size (around 46k) (PR #381) ## 0.8.2 From 6c53b24aeed30485443c20deb22b6dfb3f96f995 Mon Sep 17 00:00:00 2001 From: Nathan Cassereau Date: Tue, 7 Jun 2022 13:28:31 +0200 Subject: [PATCH 07/10] added a precision to releases.md --- RELEASES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index f540ee7c2..b38461787 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -14,7 +14,9 @@ - Fixed an issue where hitting iteration limits would be reported to stderr by std::cerr regardless of Python's stderr stream status (PR #377) - Fixed an issue where the metric argument in ot.dist did not allow a callable parameter (Issue #378, PR #379) - Fixed an issue where the max number of iterations in ot.emd was not allowed to go beyond 2^31 (PR #380) -- Fixed an issue where pointers would overflow in the EMD solver, returning an incomplete transport plan above a certain size (around 46k) (PR #381) +- Fixed an issue where pointers would overflow in the EMD solver, returning an +incomplete transport plan above a certain size (slightly above 46k, its square being +roughly 2^31) (PR #381) ## 0.8.2 From 6671bbb0180b7e2d08e0133fbaf839f5a434961d Mon Sep 17 00:00:00 2001 From: Nathan Cassereau Date: Wed, 8 Jun 2022 15:23:03 +0200 Subject: [PATCH 08/10] correct readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c69e0a6b..7c9475b80 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ POT provides the following generic OT solvers (links to examples): * [Smooth optimal transport solvers](https://pythonot.github.io/auto_examples/plot_OT_1D_smooth.html) (dual and semi-dual) for KL and squared L2 regularizations [17]. * Weak OT solver between empirical distributions [39] * Non regularized [Wasserstein barycenters [16] ](https://pythonot.github.io/auto_examples/barycenters/plot_barycenter_lp_vs_entropic.html) with LP solver (only small scale). -* [Gromov-Wasserstein distances](https://pythonot.github.io/auto_examples/gromov/plot_gromov.html) and [GW barycenters](https://pythonot.github.io/auto_examples/gromov/plot_gromov_barycenter.html) (exact [13] and regularized [12]), differentiable using gradients from +* [Gromov-Wasserstein distances](https://pythonot.github.io/auto_examples/gromov/plot_gromov.html) and [GW barycenters](https://pythonot.github.io/auto_examples/gromov/plot_gromov_barycenter.html) (exact [13] and regularized [12]), differentiable using gradients from Graph Dictionary Learning [38] * [Fused-Gromov-Wasserstein distances solver](https://pythonot.github.io/auto_examples/gromov/plot_fgw.html#sphx-glr-auto-examples-plot-fgw-py) and [FGW barycenters](https://pythonot.github.io/auto_examples/gromov/plot_barycenter_fgw.html) [24] * [Stochastic solver](https://pythonot.github.io/auto_examples/others/plot_stochastic.html) and From 43f743e3f153ea7a023f6aa5a2b1bcef0044e9f8 Mon Sep 17 00:00:00 2001 From: Nathan Cassereau Date: Wed, 8 Jun 2022 15:23:22 +0200 Subject: [PATCH 09/10] forgot to cast --- ot/lp/EMD_wrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ot/lp/EMD_wrapper.cpp b/ot/lp/EMD_wrapper.cpp index 16458d028..4aa5a6e72 100644 --- a/ot/lp/EMD_wrapper.cpp +++ b/ot/lp/EMD_wrapper.cpp @@ -79,7 +79,7 @@ int EMD_wrap(int n1, int n2, double *X, double *Y, double *D, double *G, } - net.supplyMap(&weights1[0], n, &weights2[0], m); + net.supplyMap(&weights1[0], (int) n, &weights2[0], (int) m); // Set the cost of each edge int64_t idarc = 0; From ee084444d1e46b536c2646a75b2adc4563b5d107 Mon Sep 17 00:00:00 2001 From: Nathan Cassereau Date: Wed, 8 Jun 2022 16:37:10 +0200 Subject: [PATCH 10/10] lower error --- ot/lp/network_simplex_simple_omp.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ot/lp/network_simplex_simple_omp.h b/ot/lp/network_simplex_simple_omp.h index 5f19d731a..c324d4cb7 100644 --- a/ot/lp/network_simplex_simple_omp.h +++ b/ot/lp/network_simplex_simple_omp.h @@ -41,8 +41,8 @@ #undef EPSILON #undef _EPSILON #undef MAX_DEBUG_ITER -#define EPSILON std::numeric_limits::epsilon()*10 -#define _EPSILON 1e-8 +#define EPSILON std::numeric_limits::epsilon() +#define _EPSILON 1e-14 #define MAX_DEBUG_ITER 100000 /// \ingroup min_cost_flow_algs