summaryrefslogtreecommitdiff
path: root/ot/lp/emd_wrap.pyx
diff options
context:
space:
mode:
authorAntoine Rolet <antoine.rolet@gmail.com>2017-09-09 12:37:56 +0900
committerAntoine Rolet <antoine.rolet@gmail.com>2017-09-09 12:37:56 +0900
commite58cd780ccf87736265e4e1a39afa3a167325ccc (patch)
treeeacf267e1ee18372054728961163c5bce19f3a06 /ot/lp/emd_wrap.pyx
parenta37e52e64f300fa0165a58932d5ac0ef1dd8c6f7 (diff)
Added convergence status to the log
Diffstat (limited to 'ot/lp/emd_wrap.pyx')
-rw-r--r--ot/lp/emd_wrap.pyx28
1 files changed, 17 insertions, 11 deletions
diff --git a/ot/lp/emd_wrap.pyx b/ot/lp/emd_wrap.pyx
index 5618dfc..19bcdd8 100644
--- a/ot/lp/emd_wrap.pyx
+++ b/ot/lp/emd_wrap.pyx
@@ -7,12 +7,12 @@ Cython linker with C solver
#
# License: MIT License
-import warnings
import numpy as np
cimport numpy as np
cimport cython
+import warnings
cdef extern from "EMD.h":
@@ -20,6 +20,19 @@ cdef extern from "EMD.h":
cdef enum ProblemType: INFEASIBLE, OPTIMAL, UNBOUNDED, MAX_ITER_REACHED
+def checkResult(resultCode):
+ if resultCode == OPTIMAL:
+ return None
+
+ if resultCode == INFEASIBLE:
+ message = "Problem infeasible. Check that a and b are in the simplex"
+ elif resultCode == UNBOUNDED:
+ message = "Problem unbounded"
+ elif resultCode == MAX_ITER_REACHED:
+ message = "numItermax reached before optimality. Try to increase numItermax."
+ warnings.warn(message)
+ return message
+
@cython.boundscheck(False)
@cython.wraparound(False)
@@ -77,13 +90,6 @@ def emd_c( np.ndarray[double, ndim=1, mode="c"] a,np.ndarray[double, ndim=1, mod
b=np.ones((n2,))/n2
# calling the function
- cdef int resultSolver = EMD_wrap(n1,n2,<double*> a.data,<double*> b.data,<double*> M.data,<double*> G.data, <double*> alpha.data, <double*> beta.data, <double*> &cost, numItermax)
- if resultSolver != OPTIMAL:
- if resultSolver == INFEASIBLE:
- warnings.warn("Problem infeasible. Check that a and b are in the simplex")
- elif resultSolver == UNBOUNDED:
- warnings.warn("Problem unbounded")
- elif resultSolver == MAX_ITER_REACHED:
- warnings.warn("numItermax reached before optimality. Try to increase numItermax.")
-
- return G, cost, alpha, beta
+ cdef int resultCode = EMD_wrap(n1,n2,<double*> a.data,<double*> b.data,<double*> M.data,<double*> G.data, <double*> alpha.data, <double*> beta.data, <double*> &cost, numItermax)
+
+ return G, cost, alpha, beta, resultCode