diff options
author | Sam James <sam@gentoo.org> | 2023-06-27 11:55:23 +0100 |
---|---|---|
committer | Sam James <sam@gentoo.org> | 2023-06-27 11:55:41 +0100 |
commit | 07a7407c3e3ffd6ef563eee05ace9a3c40cdbddb (patch) | |
tree | 0082b7ccfaf09231b0cb5343d189ec1e1fe11f7a /dev-python/scipy | |
parent | media-gfx/geeqie: add 2.1 (diff) | |
download | gentoo-07a7407c3e3ffd6ef563eee05ace9a3c40cdbddb.tar.gz gentoo-07a7407c3e3ffd6ef563eee05ace9a3c40cdbddb.tar.bz2 gentoo-07a7407c3e3ffd6ef563eee05ace9a3c40cdbddb.zip |
dev-python/scipy: backport det(1x1) fix
Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'dev-python/scipy')
-rw-r--r-- | dev-python/scipy/files/scipy-1.11.0-determinant-1x1-matrix.patch | 69 | ||||
-rw-r--r-- | dev-python/scipy/scipy-1.11.0-r1.ebuild | 128 |
2 files changed, 197 insertions, 0 deletions
diff --git a/dev-python/scipy/files/scipy-1.11.0-determinant-1x1-matrix.patch b/dev-python/scipy/files/scipy-1.11.0-determinant-1x1-matrix.patch new file mode 100644 index 000000000000..248ee5299f2c --- /dev/null +++ b/dev-python/scipy/files/scipy-1.11.0-determinant-1x1-matrix.patch @@ -0,0 +1,69 @@ +https://github.com/scipy/scipy/issues/18759 +https://github.com/scipy/scipy/pull/18763 +https://github.com/scipy/scipy/commit/61d892c9faa543ad80bd5e2d0bf69821188487e0 + +From 61d892c9faa543ad80bd5e2d0bf69821188487e0 Mon Sep 17 00:00:00 2001 +From: Ilhan Polat <ilhanpolat@gmail.com> +Date: Tue, 27 Jun 2023 12:00:38 +0200 +Subject: [PATCH] MAINT:linalg.det:Return scalars for singleton inputs (#18763) + +--- a/scipy/linalg/_basic.py ++++ b/scipy/linalg/_basic.py +@@ -1001,7 +1001,8 @@ def det(a, overwrite_a=False, check_finite=True): + det : (...) float or complex + Determinant of `a`. For stacked arrays, a scalar is returned for each + (m, m) slice in the last two dimensions of the input. For example, an +- input of shape (p, q, m, m) will produce a result of shape (p, q). ++ input of shape (p, q, m, m) will produce a result of shape (p, q). If ++ all dimensions are 1 a scalar is returned regardless of ndim. + + Notes + ----- +@@ -1066,11 +1067,17 @@ def det(a, overwrite_a=False, check_finite=True): + + # Scalar case + if a1.shape[-2:] == (1, 1): +- if a1.dtype.char in 'dD': +- return np.squeeze(a1) ++ # Either ndarray with spurious singletons or a single element ++ if max(*a1.shape) > 1: ++ temp = np.squeeze(a1) ++ if a1.dtype.char in 'dD': ++ return temp ++ else: ++ return (temp.astype('d') if a1.dtype.char == 'f' else ++ temp.astype('D')) + else: +- return (np.squeeze(a1).astype('d') if a1.dtype.char == 'f' else +- np.squeeze(a1).astype('D')) ++ return (np.float64(a1.item()) if a1.dtype.char in 'fd' else ++ np.complex128(a1.item())) + + # Then check overwrite permission + if not _datacopied(a1, a): # "a" still alive through "a1" +--- a/scipy/linalg/tests/test_basic.py ++++ b/scipy/linalg/tests/test_basic.py +@@ -930,6 +930,23 @@ class TestDet: + def setup_method(self): + self.rng = np.random.default_rng(1680305949878959) + ++ def test_1x1_all_singleton_dims(self): ++ a = np.array([[1]]) ++ deta = det(a) ++ assert deta.dtype.char == 'd' ++ assert np.isscalar(deta) ++ assert deta == 1. ++ a = np.array([[[[1]]]], dtype='f') ++ deta = det(a) ++ assert deta.dtype.char == 'd' ++ assert np.isscalar(deta) ++ assert deta == 1. ++ a = np.array([[[1 + 3.j]]], dtype=np.complex64) ++ deta = det(a) ++ assert deta.dtype.char == 'D' ++ assert np.isscalar(deta) ++ assert deta == 1.+3.j ++ + def test_1by1_stacked_input_output(self): + a = self.rng.random([4, 5, 1, 1], dtype=np.float32) + deta = det(a) diff --git a/dev-python/scipy/scipy-1.11.0-r1.ebuild b/dev-python/scipy/scipy-1.11.0-r1.ebuild new file mode 100644 index 000000000000..f3c49aa6ef84 --- /dev/null +++ b/dev-python/scipy/scipy-1.11.0-r1.ebuild @@ -0,0 +1,128 @@ +# Copyright 1999-2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +FORTRAN_NEEDED=fortran +DISTUTILS_EXT=1 +DISTUTILS_USE_PEP517=meson-python +PYTHON_COMPAT=( python3_{10..11} ) +PYTHON_REQ_USE="threads(+)" + +inherit fortran-2 distutils-r1 multiprocessing + +DESCRIPTION="Scientific algorithms library for Python" +HOMEPAGE=" + https://scipy.org/ + https://github.com/scipy/scipy/ + https://pypi.org/project/scipy/ +" + +if [[ ${PV} == *9999* ]] ; then + inherit git-r3 + + # Need submodules, so git for now. + EGIT_REPO_URI="https://github.com/scipy/scipy" + EGIT_BRANCH="maintenance/$(ver_cut 1-2).x" + EGIT_SUBMODULES=( '*' ) +else + inherit pypi + + # Upstream is often behind with doc updates + DOC_PV=${PV} + + SRC_URI+=" + doc? ( + https://docs.scipy.org/doc/${PN}-${DOC_PV}/${PN}-html-${DOC_PV}.zip + )" + + if [[ ${PV} != *rc* ]] ; then + KEYWORDS="~amd64 ~arm ~arm64 -hppa ~ia64 ~loong ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86" + fi +fi + +LICENSE="BSD LGPL-2" +SLOT="0" +IUSE="doc +fortran test-rust" + +# umfpack is technically optional but it's preferred to have it available. +DEPEND=" + >=dev-python/numpy-1.21.6[lapack,${PYTHON_USEDEP}] + sci-libs/arpack:= + sci-libs/umfpack + virtual/cblas + >=virtual/lapack-3.8 +" +RDEPEND=" + ${DEPEND} + dev-python/pillow[${PYTHON_USEDEP}] +" +BDEPEND=" + dev-lang/swig + >=dev-python/cython-0.29.35[${PYTHON_USEDEP}] + >=dev-python/meson-python-0.12.1[${PYTHON_USEDEP}] + >=dev-python/pybind11-2.10.4[${PYTHON_USEDEP}] + >=dev-util/meson-1.1.0 + dev-util/patchelf + virtual/pkgconfig + doc? ( app-arch/unzip ) + fortran? ( dev-python/pythran[${PYTHON_USEDEP}] ) + test? ( + dev-python/pytest-xdist[${PYTHON_USEDEP}] + ) + test-rust? ( + dev-python/pooch[${PYTHON_USEDEP}] + ) +" + +distutils_enable_tests pytest + +PATCHES=( + "${FILESDIR}"/${P}-determinant-1x1-matrix.patch +) + +src_unpack() { + default + + if use doc; then + unzip -qo "${DISTDIR}"/${PN}-html-${DOC_PV}.zip -d html || die + fi +} + +python_configure_all() { + DISTUTILS_ARGS=( + -Dblas=blas + -Dlapack=lapack + -Duse-pythran=$(usex fortran true false) + ) +} + +python_test() { + cd "${BUILD_DIR}/install$(python_get_sitedir)" || die + + local EPYTEST_DESELECT=( + # Network + scipy/datasets/tests/test_data.py::TestDatasets::test_existence_all + scipy/datasets/tests/test_data.py::TestDatasets::test_ascent + scipy/datasets/tests/test_data.py::TestDatasets::test_face + scipy/datasets/tests/test_data.py::TestDatasets::test_electrocardiogram + + # Precision issue with diff. blas? + scipy/optimize/tests/test__basinhopping.py::Test_Metropolis::test_gh7799 + ) + local EPYTEST_IGNORE=() + + if ! has_version -b "dev-python/pooch[${PYTHON_USEDEP}]" ; then + EPYTEST_IGNORE+=( + scipy/datasets/tests/test_data.py + ) + fi + + epytest -n "$(makeopts_jobs)" scipy +} + +python_install_all() { + use doc && local HTML_DOCS=( "${WORKDIR}"/html/. ) + + distutils-r1_python_install_all +} |