Skip to content

Commit

Permalink
Test only if it is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
mwojcikowski committed Jun 11, 2018
1 parent 326fa97 commit 8fc78f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
10 changes: 10 additions & 0 deletions compiledtrees/code_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
CXX_COMPILER = sysconfig.get_config_var('CXX')
delete_files = True

# detect OpenMP support
if platform.system() == 'Darwin':
c_ver = subprocess.check_output([CXX_COMPILER, '--version']).decode('ascii')
if c_ver.find('clang') >= 0: # Xcode clang does not support OpenMP
OPENMP_SUPPORT = False
else: # GCC supports OpenMP
OPENMP_SUPPORT = True
else:
OPENMP_SUPPORT = True

EVALUATE_FN_NAME = "evaluate"
ALWAYS_INLINE = "__attribute__((__always_inline__))"

Expand Down
34 changes: 18 additions & 16 deletions compiledtrees/tests/test_compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from sklearn import ensemble, tree
from compiledtrees.compiled import CompiledRegressionPredictor
from compiledtrees.code_gen import OPENMP_SUPPORT
from sklearn.utils.testing import (assert_array_almost_equal,
assert_raises, assert_equal,
assert_allclose,
Expand Down Expand Up @@ -145,22 +146,23 @@ def test_openmp(self):
rf1_compiled.predict(X1, n_jobs=2),
decimal=10)

# On travis/appveyor check for any speedup Be less generous otherwise.
if 'TRAVIS' in os.environ or 'APPVEYOR' in os.environ:
target = 0.9
else:
target = 0.6
# multi sample scaling - parallel samples
start = datetime.now()
rf1_compiled.predict(X1, n_jobs=1)
t_single = (datetime.now() - start).microseconds

start = datetime.now()
rf1_compiled.predict(X1, n_jobs=2)
t_double = (datetime.now() - start).microseconds

# ensure almost linear speedup, 0.5 = liear
assert_greater(target, t_double / t_single) # Parallel samples
if OPENMP_SUPPORT:
# On travis/appveyor check for any speedup Be less generous otherwise.
if 'TRAVIS' in os.environ or 'APPVEYOR' in os.environ:
target = 0.9
else:
target = 0.6
# multi sample scaling - parallel samples
start = datetime.now()
rf1_compiled.predict(X1, n_jobs=1)
t_single = (datetime.now() - start).microseconds

start = datetime.now()
rf1_compiled.predict(X1, n_jobs=2)
t_double = (datetime.now() - start).microseconds

# ensure almost linear speedup, 0.5 = liear
assert_greater(target, t_double / t_single) # Parallel samples

def test_predictions_with_invalid_input(self):
num_features = 100
Expand Down

0 comments on commit 8fc78f2

Please sign in to comment.