@@ -7,19 +7,32 @@ Cython linker with C solver
77#
88# License: MIT License
99
10- import warnings
1110import numpy as np
1211cimport numpy as np
1312
1413cimport cython
1514
15+ import warnings
1616
1717
1818cdef extern from " EMD.h" :
1919 int EMD_wrap(int n1,int n2, double * X, double * Y,double * D, double * G, double * alpha, double * beta, double * cost, int numItermax)
2020 cdef enum ProblemType: INFEASIBLE, OPTIMAL, UNBOUNDED, MAX_ITER_REACHED
2121
2222
23+ def checkResult (resultCode ):
24+ if resultCode == OPTIMAL:
25+ return None
26+
27+ if resultCode == INFEASIBLE:
28+ message = " Problem infeasible. Check that a and b are in the simplex"
29+ elif resultCode == UNBOUNDED:
30+ message = " Problem unbounded"
31+ elif resultCode == MAX_ITER_REACHED:
32+ message = " numItermax reached before optimality. Try to increase numItermax."
33+ warnings.warn(message)
34+ return message
35+
2336
2437@ cython.boundscheck (False )
2538@ cython.wraparound (False )
@@ -77,13 +90,6 @@ def emd_c( np.ndarray[double, ndim=1, mode="c"] a,np.ndarray[double, ndim=1, mod
7790 b= np.ones((n2,))/ n2
7891
7992 # calling the function
80- 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)
81- if resultSolver != OPTIMAL:
82- if resultSolver == INFEASIBLE:
83- warnings.warn(" Problem infeasible. Check that a and b are in the simplex" )
84- elif resultSolver == UNBOUNDED:
85- warnings.warn(" Problem unbounded" )
86- elif resultSolver == MAX_ITER_REACHED:
87- warnings.warn(" numItermax reached before optimality. Try to increase numItermax." )
88-
89- return G, cost, alpha, beta
93+ 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)
94+
95+ return G, cost, alpha, beta, resultCode
0 commit comments