Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions build_tools/azure/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ python_environment_install_and_activate() {
echo "Installing development dependency wheels"
dev_anaconda_url=https://pypi.anaconda.org/scipy-wheels-nightly/simple
pip install --pre --upgrade --timeout=60 --extra-index $dev_anaconda_url numpy pandas scipy
echo "Installing Cython from PyPI enabling pre-releases"
pip install --pre cython
echo "Installing joblib master"
echo "Installing Cython from latest sources"
pip install https://github.com/cython/cython/archive/master.zip
echo "Installing joblib from latest sources"
pip install https://github.com/joblib/joblib/archive/master.zip
echo "Installing pillow master"
echo "Installing pillow from latest sources"
pip install https://github.com/python-pillow/Pillow/archive/main.zip
fi
}
Expand Down
34 changes: 26 additions & 8 deletions sklearn/_build_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def cythonize_extensions(extension):
"""Check that a recent Cython is available and cythonize extensions"""
_check_cython_version()
from Cython.Build import cythonize
import Cython

# Fast fail before cythonization if compiler fails compiling basic test
# code even without OpenMP
Expand Down Expand Up @@ -70,20 +71,37 @@ def cythonize_extensions(extension):
os.environ.get("SKLEARN_ENABLE_DEBUG_CYTHON_DIRECTIVES", "0") != "0"
)

compiler_directives = {
"language_level": 3,
"boundscheck": cython_enable_debug_directives,
"wraparound": False,
"initializedcheck": False,
"nonecheck": False,
"cdivision": True,
}

# TODO: once Cython 3 is released and we require Cython>=3 we should get
# rid of the `legacy_implicit_noexcept` directive.
# This should mostly consist in:
#
# - ensuring nogil is at the end of function signature,
# e.g. replace "nogil except -1" by "except -1 nogil".
#
# - "noexcept"-qualifying Cython and externalized C interfaces
# which aren't raising nor propagating exceptions.
# See: https://cython.readthedocs.io/en/latest/src/userguide/language_basics.html#error-return-values # noqa
#
# See: https://github.com/cython/cython/issues/5088 for more details
if parse(Cython.__version__) > parse("3.0.0a11"):
compiler_directives["legacy_implicit_noexcept"] = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this flag will be removed in the future, may we include a TODO comment here that links to cython/cython#5088 and states that we need to fix this?


return cythonize(
extension,
nthreads=n_jobs,
compile_time_env={
"SKLEARN_OPENMP_PARALLELISM_ENABLED": sklearn._OPENMP_SUPPORTED
},
compiler_directives={
"language_level": 3,
"boundscheck": cython_enable_debug_directives,
"wraparound": False,
"initializedcheck": False,
"nonecheck": False,
"cdivision": True,
},
compiler_directives=compiler_directives,
)


Expand Down
2 changes: 1 addition & 1 deletion sklearn/neighbors/_binary_tree.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ cdef class BinaryTree:
# with numbers of points between leaf_size and 2 * leaf_size
self.n_levels = int(
np.log2(fmax(1, (n_samples - 1) / self.leaf_size)) + 1)
self.n_nodes = (2 ** self.n_levels) - 1
self.n_nodes = <int> (2 ** self.n_levels) - 1

# allocate arrays for storage
self.idx_array = np.arange(n_samples, dtype=ITYPE)
Expand Down
2 changes: 1 addition & 1 deletion sklearn/neighbors/_quad_tree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cdef class _QuadTree:
# Parameters of the tree
self.n_dimensions = n_dimensions
self.verbose = verbose
self.n_cells_per_cell = 2 ** self.n_dimensions
self.n_cells_per_cell = <int> (2 ** self.n_dimensions)

# Inner structures
self.max_depth = 0
Expand Down
2 changes: 1 addition & 1 deletion sklearn/tree/_tree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ cdef class DepthFirstTreeBuilder(TreeBuilder):
cdef int init_capacity

if tree.max_depth <= 10:
init_capacity = (2 ** (tree.max_depth + 1)) - 1
init_capacity = <int> (2 ** (tree.max_depth + 1)) - 1
else:
init_capacity = 2047

Expand Down