Skip to content

Commit fa0d4f2

Browse files
authored
[MRG] Replaces numpy compiler with setuptools (#409)
* Numpy ccompiler deprecation handled with setuptools ccompiler * Remove useless OMP Macro, already provides _OPENMP * RELEASES.md * Remove forgotten temporary bug added for logging purposes
1 parent e433775 commit fa0d4f2

File tree

5 files changed

+23
-26
lines changed

5 files changed

+23
-26
lines changed

RELEASES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ roughly 2^31) (PR #381)
2525
- Fixed an issue where a pytorch example would throw an error if executed on a GPU (Issue #389, PR #391)
2626
- Added a work-around for scipy's bug, where you cannot compute the Hamming distance with a "None" weight attribute. (Issue #400, PR #402)
2727
- Fixed an issue where the doc could not be built due to some changes in matplotlib's API (Issue #403, PR #402)
28+
- Replaced Numpy C Compiler with Setuptools C Compiler due to deprecation issues (Issue #408, PR #409)
2829

2930

3031
## 0.8.2

ot/helpers/pre_build_helpers.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,14 @@
44
import sys
55
import glob
66
import tempfile
7-
import setuptools # noqa
87
import subprocess
98

10-
from distutils.dist import Distribution
11-
from distutils.sysconfig import customize_compiler
12-
from numpy.distutils.ccompiler import new_compiler
13-
from numpy.distutils.command.config_compiler import config_cc
9+
from setuptools.command.build_ext import customize_compiler, new_compiler
1410

1511

1612
def _get_compiler():
17-
"""Get a compiler equivalent to the one that will be used to build POT
18-
Handles compiler specified as follows:
19-
- python setup.py build_ext --compiler=<compiler>
20-
- CC=<compiler> python setup.py build_ext
21-
"""
22-
dist = Distribution({'script_name': os.path.basename(sys.argv[0]),
23-
'script_args': sys.argv[1:],
24-
'cmdclass': {'config_cc': config_cc}})
25-
26-
cmd_opts = dist.command_options.get('build_ext')
27-
if cmd_opts is not None and 'compiler' in cmd_opts:
28-
compiler = cmd_opts['compiler'][1]
29-
else:
30-
compiler = None
31-
32-
ccompiler = new_compiler(compiler=compiler)
13+
ccompiler = new_compiler()
3314
customize_compiler(ccompiler)
34-
3515
return ccompiler
3616

3717

ot/lp/network_simplex_simple_omp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
//#include "core.h"
6868
//#include "lmath.h"
6969

70-
#ifdef OMP
70+
#ifdef _OPENMP
7171
#include <omp.h>
7272
#endif
7373
#include <cmath>
@@ -254,7 +254,7 @@ namespace lemon_omp {
254254
// Reset data structures
255255
reset();
256256
max_iter = maxiters;
257-
#ifdef OMP
257+
#ifdef _OPENMP
258258
if (max_threads < 0) {
259259
max_threads = omp_get_max_threads();
260260
}
@@ -513,7 +513,7 @@ namespace lemon_omp {
513513
int j;
514514
#pragma omp parallel
515515
{
516-
#ifdef OMP
516+
#ifdef _OPENMP
517517
int t = omp_get_thread_num();
518518
#else
519519
int t = 0;

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
link_args = []
3838

3939
if openmp_supported:
40-
compile_args += flags + ["/DOMP" if sys.platform == 'win32' else "-DOMP"]
40+
compile_args += flags
4141
link_args += flags
4242

4343
if sys.platform.startswith('darwin'):

test/test_ot.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,22 @@ def test_emd_emd2():
204204
np.testing.assert_allclose(w, 0)
205205

206206

207+
def test_omp_emd2():
208+
# test emd2 and emd2 with openmp for simple identity
209+
n = 100
210+
rng = np.random.RandomState(0)
211+
212+
x = rng.randn(n, 2)
213+
u = ot.utils.unif(n)
214+
215+
M = ot.dist(x, x)
216+
217+
w = ot.emd2(u, u, M)
218+
w2 = ot.emd2(u, u, M, numThreads=2)
219+
220+
np.testing.assert_allclose(w, w2)
221+
222+
207223
def test_emd_empty():
208224
# test emd and emd2 for simple identity
209225
n = 100

0 commit comments

Comments
 (0)