Skip to content

Commit

Permalink
Try compiling here
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Li <adam2392@gmail.com>
  • Loading branch information
adam2392 committed Mar 13, 2024
1 parent c8b1399 commit 7c75677
Show file tree
Hide file tree
Showing 19 changed files with 162 additions and 152 deletions.
30 changes: 18 additions & 12 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ 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')

Expand All @@ -58,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/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
54 changes: 25 additions & 29 deletions sktree/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
is_windows = host_machine.system() == 'windows'
is_mingw = is_windows and cc.get_id() == 'gcc'

c_args = []
cython_c_args = []
if is_windows
# For mingw-w64, link statically against the UCRT.
Expand Down Expand Up @@ -59,22 +60,35 @@ It seems that scikit-tree cannot be built with OpenMP.
endif

# NumPy include directory - needed in all submodules
incdir_numpy = run_command(py3,
[
'-c',
'import os; os.chdir(".."); import numpy; print(numpy.get_include())'
],
check: true
).stdout().strip()
# inc_np = include_directories(incdir_numpy)
incdir_numpy = meson.get_external_property('numpy-include-dir', 'not-given')
if incdir_numpy == 'not-given'
incdir_numpy = run_command(py,
[
'-c',
'''
import os
import numpy as np
try:
incdir = os.path.relpath(np.get_include())
except Exception:
incdir = np.get_include()
print(incdir)
'''
],
check: true
).stdout().strip()
endif

inc_np = include_directories(incdir_numpy)
np_dep = declare_dependency(include_directories: inc_np)

cc = meson.get_compiler('c')

# Don't use the deprecated NumPy C API. Define this to a fixed version instead of
# NPY_API_VERSION in order not to break compilation for released versions
# when NumPy introduces a new deprecation. Use in a meson.build file::
#
# py3.extension_module('_name',
# py.extension_module('_name',
# 'source_fname',
# numpy_nodepr_api)
numpy_nodepr_api = '-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION'
Expand All @@ -92,37 +106,19 @@ scikit_learn_cython_args = [
]
cython_c_args += scikit_learn_cython_args

cython_c_args += numpy_nodepr_api
c_args += numpy_nodepr_api

python_sources = [
'__init__.py',
'neighbors.py',
'conftest.py',
]

py3.install_sources(
py.install_sources(
python_sources,
subdir: 'sktree'
)

cython_cli = find_program('_build_utils/cythoner.py')

cython_gen = generator(cython_cli,
arguments : ['@INPUT@', '@OUTPUT@'],
output : '@BASENAME@.c')

cython_gen_cpp = generator(cython_cli,
arguments : ['@INPUT@', '@OUTPUT@', '--cplus'],
output : '@BASENAME@.cpp')

c_undefined_ok = ['-Wno-maybe-uninitialized']

# Suppress warning for deprecated Numpy API.
# (Suppress warning messages emitted by #warning directives).
# Replace with numpy_nodepr_api after Cython 3.0 is out
cython_c_args += ['-Wno-cpp']
cython_cpp_args = cython_c_args

subdir('_lib')
subdir('ensemble')
subdir('experimental')
Expand Down
2 changes: 1 addition & 1 deletion sktree/stats/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ python_sources = [
'permuteforest.py',
]

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

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

py3.install_sources(
py.install_sources(
python_sources,
pure: false,
subdir: 'sktree/tests'
Expand Down
2 changes: 1 addition & 1 deletion sktree/tree/_oblique_tree.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cdef class ObliqueTree(Tree):
SplitRecord* split_node,
Node *node,
intp_t node_id
) nogil except -1
) except -1 nogil
cdef float32_t _compute_feature(
self,
const float32_t[:, :] X_ndarray,
Expand Down

0 comments on commit 7c75677

Please sign in to comment.