This commit is contained in:
Gerben Jan Dijkman 2023-11-03 14:23:23 +01:00
parent ff0d29c038
commit ad96d34a44
4 changed files with 0 additions and 1740 deletions

View File

@ -1 +0,0 @@
DIST scikit-learn-1.3.2.gh.tar.gz 7650823 BLAKE2B 170699917f46d6d3f4b9ebc314bc1ec45687dad0a4aec5d2cee6e288b5dbe508bad6dd80406501f289a33593c6482067393e9dc28155f85a4872a34523bf4199 SHA512 a3799e9b39b755a50ba225f836904a378f7d83a08274c614d0485e4d4d4a7b0c7adba2dbb6612f2ccb4e5167f872214a2853eff69d767dc70f52369bda7a230b

View File

@ -1,107 +0,0 @@
From eb85684feb0505694e66365ba9f4d10a409f8f0b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20du=20Boisberranger?=
<34657725+jeremiedbb@users.noreply.github.com>
Date: Wed, 11 Oct 2023 11:43:47 +0200
Subject: [PATCH] MAINT Follow cython performance hints (#27521)
---
.../_middle_term_computer.pyx.tp | 2 +-
.../preprocessing/_csr_polynomial_expansion.pyx | 2 +-
sklearn/tree/_splitter.pyx | 2 +-
sklearn/tree/_utils.pxd | 2 +-
sklearn/tree/_utils.pyx | 14 ++++++--------
5 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/sklearn/metrics/_pairwise_distances_reduction/_middle_term_computer.pyx.tp b/sklearn/metrics/_pairwise_distances_reduction/_middle_term_computer.pyx.tp
index f2d89ed65909c..bfe465394c4d2 100644
--- a/sklearn/metrics/_pairwise_distances_reduction/_middle_term_computer.pyx.tp
+++ b/sklearn/metrics/_pairwise_distances_reduction/_middle_term_computer.pyx.tp
@@ -82,7 +82,7 @@ cdef void _middle_term_sparse_dense_{{name_suffix}}(
intp_t Y_end,
bint c_ordered_middle_term,
float64_t * dist_middle_terms,
-) nogil:
+) noexcept nogil:
# This routine assumes that dist_middle_terms is a pointer to the first element
# of a buffer filled with zeros of length at least equal to n_X × n_Y, conceptually
# representing a 2-d C-ordered of F-ordered array.
diff --git a/sklearn/preprocessing/_csr_polynomial_expansion.pyx b/sklearn/preprocessing/_csr_polynomial_expansion.pyx
index 90f81c0399a6e..017af83f035b2 100644
--- a/sklearn/preprocessing/_csr_polynomial_expansion.pyx
+++ b/sklearn/preprocessing/_csr_polynomial_expansion.pyx
@@ -166,7 +166,7 @@ cpdef void _csr_polynomial_expansion(
INDEX_B_t[:] result_indptr, # OUT
FLAG_t interaction_only,
FLAG_t degree
-) nogil:
+):
"""
Perform a second or third degree polynomial or interaction expansion on a
compressed sparse row (CSR) matrix. The method used only takes products of
diff --git a/sklearn/tree/_splitter.pyx b/sklearn/tree/_splitter.pyx
index a9d3a169ec84a..81cd61ed22631 100644
--- a/sklearn/tree/_splitter.pyx
+++ b/sklearn/tree/_splitter.pyx
@@ -263,7 +263,7 @@ cdef inline void shift_missing_values_to_left_if_required(
SplitRecord* best,
intp_t[::1] samples,
intp_t end,
-) nogil:
+) noexcept nogil:
cdef intp_t i, p, current_end
# The partitioner partitions the data such that the missing values are in
# samples[-n_missing:] for the criterion to consume. If the missing values
diff --git a/sklearn/tree/_utils.pxd b/sklearn/tree/_utils.pxd
index 4167230bfbf4d..b59d18879ca94 100644
--- a/sklearn/tree/_utils.pxd
+++ b/sklearn/tree/_utils.pxd
@@ -39,7 +39,7 @@ ctypedef fused realloc_ptr:
(Cell*)
(Node**)
-cdef realloc_ptr safe_realloc(realloc_ptr* p, size_t nelems) except * nogil
+cdef int safe_realloc(realloc_ptr* p, size_t nelems) except -1 nogil
cdef cnp.ndarray sizet_ptr_to_ndarray(intp_t* data, intp_t size)
diff --git a/sklearn/tree/_utils.pyx b/sklearn/tree/_utils.pyx
index 3c0c312b25fbe..b6115d4f21d18 100644
--- a/sklearn/tree/_utils.pyx
+++ b/sklearn/tree/_utils.pyx
@@ -22,22 +22,20 @@ from ..utils._random cimport our_rand_r
# Helper functions
# =============================================================================
-cdef realloc_ptr safe_realloc(realloc_ptr* p, size_t nelems) except * nogil:
+cdef int safe_realloc(realloc_ptr* p, size_t nelems) except -1 nogil:
# sizeof(realloc_ptr[0]) would be more like idiomatic C, but causes Cython
# 0.20.1 to crash.
cdef size_t nbytes = nelems * sizeof(p[0][0])
if nbytes / sizeof(p[0][0]) != nelems:
# Overflow in the multiplication
- with gil:
- raise MemoryError("could not allocate (%d * %d) bytes"
- % (nelems, sizeof(p[0][0])))
+ raise MemoryError(f"could not allocate ({nelems} * {sizeof(p[0][0])}) bytes")
+
cdef realloc_ptr tmp = <realloc_ptr>realloc(p[0], nbytes)
if tmp == NULL:
- with gil:
- raise MemoryError("could not allocate %d bytes" % nbytes)
+ raise MemoryError(f"could not allocate {nbytes} bytes")
p[0] = tmp
- return tmp # for convenience
+ return 0
def _realloc_test():
@@ -111,7 +109,7 @@ cdef class WeightedPQueue:
or 0 otherwise.
"""
self.array_ptr = 0
- # Since safe_realloc can raise MemoryError, use `except *`
+ # Since safe_realloc can raise MemoryError, use `except -1`
safe_realloc(&self.array_, self.capacity)
return 0

View File

@ -1,69 +0,0 @@
# Copyright 2020-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
DISTUTILS_EXT=1
DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python3_{10..11} )
inherit distutils-r1
DESCRIPTION="Machine learning library for Python"
HOMEPAGE="https://scikit-learn.org/stable/"
SRC_URI="https://github.com/scikit-learn/scikit-learn/archive/${PV}.tar.gz -> ${P}.gh.tar.gz"
LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64 ~arm64 ~ppc64 ~riscv ~x86 ~arm64-macos ~x64-macos"
IUSE="examples"
# Fatal Python error: Segmentation fault
RESTRICT="test"
DEPEND="
virtual/blas:=
virtual/cblas:=
"
RDEPEND="
${DEPEND}
dev-python/wheel[${PYTHON_USEDEP}]
dev-python/joblib[${PYTHON_USEDEP}]
dev-python/numpy[${PYTHON_USEDEP}]
dev-python/scipy[${PYTHON_USEDEP}]
dev-python/threadpoolctl[${PYTHON_USEDEP}]
"
# <cython-3: https://bugs.gentoo.org/911369
BDEPEND="
dev-python/cython[${PYTHON_USEDEP}]
"
PATCHES=(
"${FILESDIR}/210550007e04a096e0e600c6586da677c33d6d90.patch"
"${FILESDIR}/eb85684feb0505694e66365ba9f4d10a409f8f0b.patch"
)
distutils_enable_tests pytest
# For some reason this wants to use urllib to fetch things from the internet
# distutils_enable_sphinx doc \
# dev-python/matplotlib \
# dev-python/memory-profiler \
# dev-python/numpydoc \
# dev-python/pandas \
# dev-python/pillow \
# dev-python/seaborn \
# dev-python/sphinx-gallery \
# dev-python/sphinx-prompt \
# sci-libs/scikit-image
python_test() {
# This needs to be run in the install dir
cd "${WORKDIR}/${P}-${EPYTHON//./_}/install/usr/lib/${EPYTHON}/site-packages/sklearn" || die
distutils-r1_python_test
}
python_install_all() {
find "${S}" -name \*LICENSE.txt -delete || die
distutils-r1_python_install_all
use examples && dodoc -r examples
}