Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT Adding meson compiler directives #242

Merged
merged 8 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/whats_new/v0.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Changelog
---------
- |Fix| Trunk simulators now correctly generate random values with a fixed seed,
by `Sambit Panda`_ (:pr:`#236`)
- |Efficiency| All scikit-tree estimators are now at least 2X faster than they were
in previous versions. This was due to adding in compiler-directives to turn on
optimizations '-03' when compiling the C++ generated code from Cython. In addition,
we explicitly turned off bounds-checking and related runtime checks in the Cython code,
which would lead to performance degradation during runtime. by `Adam Li`_ (:pr:`#242`)

Code and Documentation Contributors
-----------------------------------
Expand Down
42 changes: 28 additions & 14 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
project(
'scikit-tree',
'c', 'cpp',
'c', 'cpp', 'cython',
# Note that the git commit hash cannot be added dynamically here
# That only happens when importing from a git repository.
# See `sktree/__init__.py`
version: '0.8.0dev0',
license: 'BSD-3',
meson_version: '>= 0.64.0',
meson_version: '>= 1.1.0',
default_options: [
'buildtype=debugoptimized',
'c_std=c99',
Expand All @@ -29,6 +29,20 @@ elif cc.get_id() == 'msvc'
endif
endif

# Suppress warning for deprecated Numpy API.
# (Suppress warning messages emitted by #warning directives).
# Replace with numpy_nodepr_api after Cython 3.0 is out
# '-Wno-maybe-uninitialized'
# numpy_nodepr_api = '-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION'
_global_c_args = cc.get_supported_arguments(
'-Wno-unused-but-set-variable',
'-Wno-unused-function',
'-Wno-conversion',
'-Wno-misleading-indentation',
'-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION',
)
add_project_arguments(_global_c_args, language : 'c')

# We need -lm for all C code (assuming it uses math functions, which is safe to
# assume for scikit-tree). For C++ it isn't needed, because libstdc++/libc++ is
# guaranteed to depend on it. For Fortran code, Meson already adds `-lm`.
Expand All @@ -50,22 +64,22 @@ r = run_command('mv', 'sktree/_lib/sklearn_fork/sklearn', 'sktree/_lib/sklearn',

# Setup Python:
# https://mesonbuild.com/Python-module.html
py3_mod = import('python')
py = import('python').find_installation(pure: false)
# py3_mod = import('python')

# NOTE: with Meson >=0.64.0 we can add `pure: false` here and remove that line
# everywhere else, see https://github.com/mesonbuild/meson/pull/10783.
py3 = py3_mod.find_installation(
'python3',
pure: false # Will be installed next to binaries
)
# py3.install_env('venv')
# # NOTE: with Meson >=0.64.0 we can add `pure: false` here and remove that line
# # everywhere else, see https://github.com/mesonbuild/meson/pull/10783.
# py3 = py3_mod.find_installation(
# 'python3',
# pure: false # Will be installed next to binaries
# )
# py.install_env('venv')

# print some debugging output
message(py3.full_path())
message(py3.get_install_dir())
if py3.language_version().version_compare('<3.9')
message(py.full_path())
message(py.get_install_dir())
if py.language_version().version_compare('<3.9')
error('At least Python 3.9 is required.')
endif
py3_dep = py3.dependency()

subdir('sktree')
1 change: 1 addition & 0 deletions sktree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import sys

print("using current cython branch.")
__version__ = "0.8.0dev0"
logger = logging.getLogger(__name__)

Expand Down
40 changes: 0 additions & 40 deletions sktree/_build_utils/cythoner.py

This file was deleted.

60 changes: 38 additions & 22 deletions sktree/_lib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@ if not fs.exists('sklearn')
endif

# install tree/ submodule
extensions = [
'_tree',
'_utils',
'_criterion',
'_splitter',
]
tree_extension_metadata = {
'_tree':
{'sources': ['./sklearn/tree/' + '_tree.pyx'],
'override_options': ['cython_language=cpp', 'optimization=3']},
'_splitter':
{'sources': ['./sklearn/tree/' + '_splitter.pyx'],
'override_options': ['cython_language=cpp', 'optimization=3']},
'_criterion':
{'sources': ['./sklearn/tree/' + '_criterion.pyx'],
'override_options': ['cython_language=cpp', 'optimization=3']},
'_utils':
{'sources': ['./sklearn/tree/' + '_utils.pyx'],
'override_options': ['cython_language=cpp', 'optimization=3']},
}

foreach ext: extensions
py3.extension_module(ext,
cython_gen_cpp.process('./sklearn/tree/' + ext + '.pyx'),
c_args: cython_c_args,
include_directories: [incdir_numpy,],
install: true,

foreach ext_name, ext_dict : tree_extension_metadata
py.extension_module(
ext_name,
ext_dict.get('sources'),
dependencies: [np_dep],
override_options : ext_dict.get('override_options', []),
cython_args: cython_c_args,
subdir: 'sktree/_lib/sklearn/tree/',
install: true
)
endforeach

Expand All @@ -28,7 +39,7 @@ python_sources = [
'./sklearn/tree/_reingold_tilford.py',
]

py3.install_sources(
py.install_sources(
python_sources,
subdir: 'sktree/_lib/sklearn/tree' # Folder relative to site-packages to install to
)
Expand All @@ -38,7 +49,7 @@ python_sources = [
'_forest.py',
]
foreach py_source: python_sources
py3.install_sources(
py.install_sources(
'./sklearn/ensemble/' + py_source,
subdir: 'sktree/_lib/sklearn/ensemble'
)
Expand All @@ -51,10 +62,13 @@ extensions = [
]

foreach ext: extensions
py3.extension_module(ext,
cython_gen_cpp.process('./sklearn/neighbors/' + ext + '.pyx'),
c_args: cython_c_args,
include_directories: [incdir_numpy,],
py.extension_module(
ext,
['./sklearn/neighbors/' + ext + '.pyx'],
c_args: c_args,
dependencies: [np_dep],
cython_args: cython_c_args,
override_options : ['optimization=3', 'cython_language=cpp'],
install: true,
subdir: 'sktree/_lib/sklearn/neighbors/',
)
Expand All @@ -67,10 +81,12 @@ extensions = [
]

foreach ext: extensions
py3.extension_module(ext,
cython_gen_cpp.process('./sklearn/utils/' + ext + '.pyx'),
c_args: cython_c_args,
include_directories: [incdir_numpy,],
py.extension_module(ext,
['./sklearn/utils/' + ext + '.pyx'],
c_args: c_args,
dependencies: [np_dep],
cython_args: cython_c_args,
override_options : ['optimization=3', 'cython_language=cpp'],
install: true,
subdir: 'sktree/_lib/sklearn/utils/',
)
Expand Down
2 changes: 1 addition & 1 deletion sktree/_lib/sklearn_fork
Submodule sklearn_fork updated 78 files
+4 −4 .github/ISSUE_TEMPLATE/config.yml
+1 −1 .github/workflows/check-manifest.yml
+1 −1 .github/workflows/labeler-title-regex.yml
+2 −2 .github/workflows/lint.yml
+1 −1 .github/workflows/publish_pypi.yml
+1 −1 .github/workflows/update_tracking_issue.yml
+3 −3 .github/workflows/wheels.yml
+4 −2 README.rst
+4 −4 build_tools/azure/pylatest_conda_forge_mkl_linux-64_conda.lock
+7 −7 build_tools/azure/pylatest_conda_forge_mkl_osx-64_conda.lock
+4 −4 build_tools/azure/pylatest_conda_mkl_no_openmp_osx-64_conda.lock
+3 −3 build_tools/azure/pylatest_pip_openblas_pandas_linux-64_conda.lock
+2 −2 build_tools/azure/pymin_conda_defaults_openblas_linux-64_conda.lock
+5 −5 build_tools/azure/pymin_conda_forge_mkl_win-64_conda.lock
+6 −6 build_tools/azure/pymin_conda_forge_openblas_ubuntu_2204_linux-64_conda.lock
+5 −5 build_tools/azure/pypy3_linux-64_conda.lock
+1 −1 build_tools/azure/test_script.sh
+1 −1 build_tools/azure/ubuntu_atlas_lock.txt
+10 −10 build_tools/circle/doc_linux-64_conda.lock
+5 −5 build_tools/circle/doc_min_dependencies_linux-64_conda.lock
+5 −5 build_tools/cirrus/pymin_conda_forge_linux-aarch64_conda.lock
+2 −5 doc/faq.rst
+3 −3 doc/metadata_routing.rst
+29 −5 doc/support.rst
+3 −2 doc/templates/index.html
+5 −0 doc/themes/scikit-learn-modern/static/css/theme.css
+15 −0 doc/whats_new/v1.4.rst
+50 −4 doc/whats_new/v1.5.rst
+9 −5 examples/compose/plot_digits_pipe.py
+10 −2 examples/miscellaneous/plot_outlier_detection_bench.py
+1 −1 examples/tree/plot_unveil_tree_structure.py
+9 −0 sklearn/datasets/_base.py
+29 −0 sklearn/datasets/_lfw.py
+11 −0 sklearn/datasets/_olivetti_faces.py
+9 −0 sklearn/datasets/_rcv1.py
+93 −2 sklearn/datasets/_samples_generator.py
+18 −1 sklearn/datasets/_svmlight_format_io.py
+23 −0 sklearn/datasets/_twenty_newsgroups.py
+6 −9 sklearn/decomposition/_pca.py
+19 −1 sklearn/decomposition/tests/test_pca.py
+4 −0 sklearn/ensemble/_weight_boosting.py
+1 −1 sklearn/externals/conftest.py
+28 −0 sklearn/feature_extraction/image.py
+19 −0 sklearn/linear_model/_coordinate_descent.py
+38 −0 sklearn/linear_model/_least_angle.py
+30 −5 sklearn/linear_model/_omp.py
+172 −49 sklearn/linear_model/_ridge.py
+64 −1 sklearn/linear_model/_stochastic_gradient.py
+11 −0 sklearn/linear_model/tests/test_omp.py
+10 −0 sklearn/linear_model/tests/test_passive_aggressive.py
+2 −2 sklearn/linear_model/tests/test_ridge.py
+15 −2 sklearn/linear_model/tests/test_sgd.py
+5 −8 sklearn/manifold/_barnes_hut_tsne.pyx
+1 −1 sklearn/metrics/_classification.py
+1 −1 sklearn/metrics/cluster/_supervised.py
+4 −0 sklearn/metrics/pairwise.py
+23 −0 sklearn/metrics/tests/test_classification.py
+19 −17 sklearn/model_selection/_search.py
+58 −5 sklearn/model_selection/tests/test_search.py
+9 −1 sklearn/model_selection/tests/test_successive_halving.py
+103 −21 sklearn/pipeline.py
+14 −6 sklearn/preprocessing/_data.py
+1 −1 sklearn/preprocessing/_label.py
+13 −0 sklearn/preprocessing/tests/test_data.py
+26 −2 sklearn/tests/metadata_routing_common.py
+33 −5 sklearn/tests/test_metaestimators_metadata_routing.py
+124 −5 sklearn/tests/test_pipeline.py
+7 −1 sklearn/tree/_splitter.pxd
+5 −19 sklearn/tree/_splitter.pyx
+11 −12 sklearn/tree/_tree.pyx
+27 −9 sklearn/utils/__init__.py
+1 −1 sklearn/utils/_param_validation.py
+6 −1 sklearn/utils/_testing.py
+5 −2 sklearn/utils/fixes.py
+45 −2 sklearn/utils/sparsefuncs_fast.pyx
+2 −2 sklearn/utils/tests/test_testing.py
+24 −13 sklearn/utils/tests/test_utils.py
+9 −0 sklearn/utils/validation.py
2 changes: 1 addition & 1 deletion sktree/datasets/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ python_sources = [
'hyppo.py',
]

py3.install_sources(
py.install_sources(
python_sources,
pure: false,
subdir: 'sktree/datasets'
Expand Down
2 changes: 1 addition & 1 deletion sktree/datasets/tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ python_sources = [
'test_multiview.py',
]

py3.install_sources(
py.install_sources(
python_sources,
pure: false,
subdir: 'sktree/datasets/tests'
Expand Down
2 changes: 1 addition & 1 deletion sktree/ensemble/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ python_sources = [
'_extensions.py',
]

py3.install_sources(
py.install_sources(
python_sources,
pure: false,
subdir: 'sktree/ensemble'
Expand Down
2 changes: 1 addition & 1 deletion sktree/experimental/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ python_sources = [
'monte_carlo.py',
]

py3.install_sources(
py.install_sources(
python_sources,
pure: false,
subdir: 'sktree/experimental'
Expand Down
2 changes: 1 addition & 1 deletion sktree/experimental/tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ python_sources = [
'test_monte_carlo.py',
]

py3.install_sources(
py.install_sources(
python_sources,
pure: false,
subdir: 'sktree/experimental/tests'
Expand Down
Loading
Loading