Skip to content

Commit 8033056

Browse files
lesteveadrinjalali
authored andcommitted
CI Use latest Cython sources in scipy-dev build (#25300)
1 parent 55076b2 commit 8033056

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

build_tools/azure/install.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ python_environment_install_and_activate() {
8383
echo "Installing development dependency wheels"
8484
dev_anaconda_url=https://pypi.anaconda.org/scipy-wheels-nightly/simple
8585
pip install --pre --upgrade --timeout=60 --extra-index $dev_anaconda_url numpy pandas scipy
86-
echo "Installing Cython from PyPI enabling pre-releases"
87-
pip install --pre cython
88-
echo "Installing joblib master"
86+
echo "Installing Cython from latest sources"
87+
pip install https://github.com/cython/cython/archive/master.zip
88+
echo "Installing joblib from latest sources"
8989
pip install https://github.com/joblib/joblib/archive/master.zip
90-
echo "Installing pillow master"
90+
echo "Installing pillow from latest sources"
9191
pip install https://github.com/python-pillow/Pillow/archive/main.zip
9292
fi
9393
}

sklearn/_build_utils/__init__.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def cythonize_extensions(extension):
4040
"""Check that a recent Cython is available and cythonize extensions"""
4141
_check_cython_version()
4242
from Cython.Build import cythonize
43+
import Cython
4344

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

74+
compiler_directives = {
75+
"language_level": 3,
76+
"boundscheck": cython_enable_debug_directives,
77+
"wraparound": False,
78+
"initializedcheck": False,
79+
"nonecheck": False,
80+
"cdivision": True,
81+
}
82+
83+
# TODO: once Cython 3 is released and we require Cython>=3 we should get
84+
# rid of the `legacy_implicit_noexcept` directive.
85+
# This should mostly consist in:
86+
#
87+
# - ensuring nogil is at the end of function signature,
88+
# e.g. replace "nogil except -1" by "except -1 nogil".
89+
#
90+
# - "noexcept"-qualifying Cython and externalized C interfaces
91+
# which aren't raising nor propagating exceptions.
92+
# See: https://cython.readthedocs.io/en/latest/src/userguide/language_basics.html#error-return-values # noqa
93+
#
94+
# See: https://github.com/cython/cython/issues/5088 for more details
95+
if parse(Cython.__version__) > parse("3.0.0a11"):
96+
compiler_directives["legacy_implicit_noexcept"] = True
97+
7398
return cythonize(
7499
extension,
75100
nthreads=n_jobs,
76101
compile_time_env={
77102
"SKLEARN_OPENMP_PARALLELISM_ENABLED": sklearn._OPENMP_SUPPORTED
78103
},
79-
compiler_directives={
80-
"language_level": 3,
81-
"boundscheck": cython_enable_debug_directives,
82-
"wraparound": False,
83-
"initializedcheck": False,
84-
"nonecheck": False,
85-
"cdivision": True,
86-
},
104+
compiler_directives=compiler_directives,
87105
)
88106

89107

sklearn/neighbors/_binary_tree.pxi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ cdef class BinaryTree:
857857
# with numbers of points between leaf_size and 2 * leaf_size
858858
self.n_levels = int(
859859
np.log2(fmax(1, (n_samples - 1) / self.leaf_size)) + 1)
860-
self.n_nodes = (2 ** self.n_levels) - 1
860+
self.n_nodes = <int> (2 ** self.n_levels) - 1
861861

862862
# allocate arrays for storage
863863
self.idx_array_arr = np.arange(n_samples, dtype=ITYPE)

sklearn/neighbors/_quad_tree.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ cdef class _QuadTree:
5252
# Parameters of the tree
5353
self.n_dimensions = n_dimensions
5454
self.verbose = verbose
55-
self.n_cells_per_cell = 2 ** self.n_dimensions
55+
self.n_cells_per_cell = <int> (2 ** self.n_dimensions)
5656

5757
# Inner structures
5858
self.max_depth = 0

sklearn/tree/_tree.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ cdef class DepthFirstTreeBuilder(TreeBuilder):
155155
cdef int init_capacity
156156

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

0 commit comments

Comments
 (0)