MNT Enable O3 optimization for trees
@@ -419,10 +419,15 @@ extension_config = {
},
],
"tree": [
- {"sources": ["_tree.pyx"], "language": "c++", "include_np": True},
- {"sources": ["_splitter.pyx"], "include_np": True},
- {"sources": ["_criterion.pyx"], "include_np": True},
- {"sources": ["_utils.pyx"], "include_np": True},
+ {
+ "sources": ["_tree.pyx"],
+ "language": "c++",
+ "include_np": True,
+ "optimization_level": "O3",
+ },
+ {"sources": ["_splitter.pyx"], "include_np": True, "optimization_level": "O3"},
+ {"sources": ["_criterion.pyx"], "include_np": True, "optimization_level": "O3"},
+ {"sources": ["_utils.pyx"], "include_np": True, "optimization_level": "O3"},
],
"utils": [
{"sources": ["sparsefuncs_fast.pyx"], "include_np": True},
@@ -504,15 +509,14 @@ def configure_extension_modules():
is_pypy = platform.python_implementation() == "PyPy"
np_include = numpy.get_include()
+ default_optimization_level = "O2"
- optimization_level = "O2"
if os.name == "posix":
- default_extra_compile_args = [f"-{optimization_level}"]
default_libraries = ["m"]
else:
- default_extra_compile_args = [f"/{optimization_level}"]
default_libraries = []
+ default_extra_compile_args = []
build_with_debug_symbols = (
os.environ.get("SKLEARN_BUILD_ENABLE_DEBUG_SYMBOLS", "0") != "0"
)
@@ -575,6 +579,14 @@ def configure_extension_modules():
extra_compile_args = (
extension.get("extra_compile_args", []) + default_extra_compile_args
)
+ optimization_level = extension.get(
+ "optimization_level", default_optimization_level
+ )
+ if os.name == "posix":
+ extra_compile_args.append(f"-{optimization_level}")
+ else:
+ extra_compile_args.append(f"/{optimization_level}")
+
libraries_ext = extension.get("libraries", []) + default_libraries
new_ext = Extension(
