Skip to content

BLD Always use NumPy 1.7 C API for all compiled extensions #25793

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

Merged
Merged
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
91 changes: 7 additions & 84 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,85 +55,6 @@

VERSION = sklearn.__version__

# See: https://numpy.org/doc/stable/reference/c-api/deprecations.html
DEFINE_MACRO_NUMPY_C_API = (
"NPY_NO_DEPRECATED_API",
"NPY_1_7_API_VERSION",
)

# XXX: add new extensions to this list when they
# are not using the old NumPy C API (i.e. version 1.7)
# TODO: when Cython>=3.0 is used, make sure all Cython extensions
# use the newest NumPy C API by `#defining` `NPY_NO_DEPRECATED_API` to be
# `NPY_1_7_API_VERSION`, and remove this list.
# See: https://github.com/cython/cython/blob/1777f13461f971d064bd1644b02d92b350e6e7d1/docs/src/userguide/migrating_to_cy30.rst#numpy-c-api # noqa
USE_NEWEST_NUMPY_C_API = (
"sklearn.__check_build._check_build",
"sklearn._loss._loss",
"sklearn._isotonic",
"sklearn.cluster._dbscan_inner",
"sklearn.cluster._hierarchical_fast",
"sklearn.cluster._k_means_common",
"sklearn.cluster._k_means_lloyd",
"sklearn.cluster._k_means_elkan",
"sklearn.cluster._k_means_minibatch",
"sklearn.datasets._svmlight_format_fast",
"sklearn.decomposition._cdnmf_fast",
"sklearn.decomposition._online_lda_fast",
"sklearn.ensemble._gradient_boosting",
"sklearn.ensemble._hist_gradient_boosting._gradient_boosting",
"sklearn.ensemble._hist_gradient_boosting.histogram",
"sklearn.ensemble._hist_gradient_boosting.splitting",
"sklearn.ensemble._hist_gradient_boosting._binning",
"sklearn.ensemble._hist_gradient_boosting._predictor",
"sklearn.ensemble._hist_gradient_boosting._bitset",
"sklearn.ensemble._hist_gradient_boosting.common",
"sklearn.ensemble._hist_gradient_boosting.utils",
"sklearn.feature_extraction._hashing_fast",
"sklearn.linear_model._cd_fast",
"sklearn.linear_model._sag_fast",
"sklearn.linear_model._sgd_fast",
"sklearn.manifold._barnes_hut_tsne",
"sklearn.manifold._utils",
"sklearn.metrics.cluster._expected_mutual_info_fast",
"sklearn.metrics._dist_metrics",
"sklearn.metrics._pairwise_distances_reduction._datasets_pair",
"sklearn.metrics._pairwise_distances_reduction._middle_term_computer",
"sklearn.metrics._pairwise_distances_reduction._base",
"sklearn.metrics._pairwise_distances_reduction._argkmin",
"sklearn.metrics._pairwise_distances_reduction._radius_neighbors",
"sklearn.metrics._pairwise_fast",
"sklearn.neighbors._ball_tree",
"sklearn.neighbors._kd_tree",
"sklearn.neighbors._partition_nodes",
"sklearn.neighbors._quad_tree",
"sklearn.preprocessing._csr_polynomial_expansion",
"sklearn.svm._liblinear",
"sklearn.svm._libsvm",
"sklearn.svm._libsvm_sparse",
"sklearn.svm._newrand",
"sklearn.tree._criterion",
"sklearn.tree._splitter",
"sklearn.tree._tree",
"sklearn.tree._utils",
"sklearn.utils._cython_blas",
"sklearn.utils._fast_dict",
"sklearn.utils._heap",
"sklearn.utils._isfinite",
"sklearn.utils._logistic_sigmoid",
"sklearn.utils._openmp_helpers",
"sklearn.utils._random",
"sklearn.utils._seq_dataset",
"sklearn.utils._sorting",
"sklearn.utils._typedefs",
"sklearn.utils._vector_sentinel",
"sklearn.utils._weight_vector",
"sklearn.utils.arrayfuncs",
"sklearn.utils.murmurhash",
"sklearn.utils.sparsefuncs_fast",
)


# Custom clean command to remove build artifacts


Expand Down Expand Up @@ -196,12 +117,14 @@ def finalize_options(self):
def build_extensions(self):
from sklearn._build_utils.openmp_helpers import get_openmp_flag

# Always use NumPy 1.7 C API for all compiled extensions.
# See: https://numpy.org/doc/stable/reference/c-api/deprecations.html
DEFINE_MACRO_NUMPY_C_API = (
"NPY_NO_DEPRECATED_API",
"NPY_1_7_API_VERSION",
)
for ext in self.extensions:
if ext.name in USE_NEWEST_NUMPY_C_API:
print(f"Using newest NumPy C API for extension {ext.name}")
ext.define_macros.append(DEFINE_MACRO_NUMPY_C_API)
else:
print(f"Using old NumPy C API (version 1.7) for extension {ext.name}")
ext.define_macros.append(DEFINE_MACRO_NUMPY_C_API)

if sklearn._OPENMP_SUPPORTED:
openmp_flag = get_openmp_flag()
Expand Down