diff options
| author | root <root@alpha.trunkmasters.com> | 2026-09-19 19:27:39 -0500 |
|---|---|---|
| committer | root <root@alpha.trunkmasters.com> | 2026-09-19 19:27:39 -0500 |
| commit | 47516b9667518dacb1efd6d257f7b3e6a481ec93 (patch) | |
| tree | 15968af203a3ff5970f912ab816b33e3a8648196 /dev-python/gfloat | |
| parent | 1e827c97be50f4e8e4da3697da898689b2bde9d5 (diff) | |
| download | baldeagleos-repo-47516b9667518dacb1efd6d257f7b3e6a481ec93.tar.gz baldeagleos-repo-47516b9667518dacb1efd6d257f7b3e6a481ec93.tar.xz baldeagleos-repo-47516b9667518dacb1efd6d257f7b3e6a481ec93.zip | |
Adding metadata
Diffstat (limited to 'dev-python/gfloat')
| -rw-r--r-- | dev-python/gfloat/files/gfloat-0.5.2-signed-zero-overflow.patch | 51 | ||||
| -rw-r--r-- | dev-python/gfloat/gfloat-0.5.2-r1.ebuild | 6 | ||||
| -rw-r--r-- | dev-python/gfloat/gfloat-0.5.2-r2.ebuild | 79 |
3 files changed, 133 insertions, 3 deletions
diff --git a/dev-python/gfloat/files/gfloat-0.5.2-signed-zero-overflow.patch b/dev-python/gfloat/files/gfloat-0.5.2-signed-zero-overflow.patch new file mode 100644 index 000000000000..fd011671ecfe --- /dev/null +++ b/dev-python/gfloat/files/gfloat-0.5.2-signed-zero-overflow.patch @@ -0,0 +1,51 @@ +From 575ceff2babe3e54795ec4ce441ec8e981462f9b Mon Sep 17 00:00:00 2001 +From: Andrew Fitzgibbon <awf@fitzgibbon.ie> +Date: Fri, 18 Sep 2026 15:58:51 +0100 +Subject: [PATCH] Fix binary64 ndarray encoding overflow for signed zero + +--- + src/gfloat/encode_ndarray.py | 5 ++++- + test/test_encode.py | 17 +++++++++++++++++ + 2 files changed, 21 insertions(+), 1 deletion(-) + +diff --git a/src/gfloat/encode_ndarray.py b/src/gfloat/encode_ndarray.py +index af883e4..3d5981c 100644 +--- a/src/gfloat/encode_ndarray.py ++++ b/src/gfloat/encode_ndarray.py +@@ -51,7 +51,10 @@ def encode_ndarray(fi: FormatInfo, v: npt.NDArray) -> npt.NDArray: + + if fi.has_zero: + if fi.has_nz: +- code[v == 0] = np.where(sign[v == 0], fi.code_of_negzero, fi.code_of_zero) ++ # binary64's negative-zero code exceeds the signed int64 range. ++ code[v == 0] = np.where( ++ sign[v == 0], np.uint64(fi.code_of_negzero), np.uint64(fi.code_of_zero) ++ ) + else: + code[v == 0] = fi.code_of_zero + +diff --git a/test/test_encode.py b/test/test_encode.py +index efdaa1f..8ab344f 100644 +--- a/test/test_encode.py ++++ b/test/test_encode.py +@@ -62,3 +62,20 @@ def test_encode_edges(fi: FormatInfo, enc: Callable) -> None: + if fi.domain == Domain.Extended + else fi.code_of_nan if fi.num_nans > 0 else fi.code_of_min + ) ++ ++ ++@pytest.mark.parametrize( ++ "values", ++ [ ++ [0.0, -0.0], ++ [[-0.0, 0.0], [1.0, -1.0]], ++ [1.0, -1.0], # The zero selection is empty, as in issue #63. ++ [], ++ ], ++) ++def test_encode_binary64_signed_zero(values: npt.ArrayLike) -> None: ++ v = np.array(values, dtype=np.float64) ++ codes = encode_ndarray(format_info_binary64, v) ++ assert codes.dtype == np.dtype(np.uint64) ++ assert codes.shape == v.shape ++ np.testing.assert_array_equal(codes, v.view(np.uint64)) diff --git a/dev-python/gfloat/gfloat-0.5.2-r1.ebuild b/dev-python/gfloat/gfloat-0.5.2-r1.ebuild index b545ecf5f33e..bf081ec3b862 100644 --- a/dev-python/gfloat/gfloat-0.5.2-r1.ebuild +++ b/dev-python/gfloat/gfloat-0.5.2-r1.ebuild @@ -26,16 +26,16 @@ RDEPEND=" " BDEPEND=" test? ( + dev-python/jinja2[${PYTHON_USEDEP}] dev-python/matplotlib[${PYTHON_USEDEP}] dev-python/ml-dtypes[${PYTHON_USEDEP}] dev-python/tabulate[${PYTHON_USEDEP}] test-rust? ( dev-python/nbval[${PYTHON_USEDEP}] ) - !arm? ( - dev-python/jinja2[${PYTHON_USEDEP}] + !arm? ( !x86? ( dev-python/pandas[${PYTHON_USEDEP}] - ) + ) ) ) " diff --git a/dev-python/gfloat/gfloat-0.5.2-r2.ebuild b/dev-python/gfloat/gfloat-0.5.2-r2.ebuild new file mode 100644 index 000000000000..52a0a20c2d05 --- /dev/null +++ b/dev-python/gfloat/gfloat-0.5.2-r2.ebuild @@ -0,0 +1,79 @@ +# Copyright 2024-2026 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +DISTUTILS_USE_PEP517=setuptools +PYTHON_COMPAT=( python3_{13..14} ) + +inherit distutils-r1 pypi + +DESCRIPTION="Generic floating-point types in Python" +HOMEPAGE=" + https://github.com/graphcore-research/gfloat/ + https://pypi.org/project/gfloat/ +" + +LICENSE="MIT" +SLOT="0" +KEYWORDS="~amd64 ~arm ~arm64 ~riscv ~x86" +IUSE="test-rust" + +RDEPEND=" + dev-python/array-api-compat[${PYTHON_USEDEP}] + dev-python/more-itertools[${PYTHON_USEDEP}] + dev-python/numpy[${PYTHON_USEDEP}] +" +BDEPEND=" + test? ( + dev-python/jinja2[${PYTHON_USEDEP}] + dev-python/matplotlib[${PYTHON_USEDEP}] + dev-python/ml-dtypes[${PYTHON_USEDEP}] + dev-python/tabulate[${PYTHON_USEDEP}] + test-rust? ( + dev-python/nbval[${PYTHON_USEDEP}] + ) + !arm? ( !x86? ( + dev-python/pandas[${PYTHON_USEDEP}] + ) ) + ) +" + +EPYTEST_PLUGINS=() +distutils_enable_tests pytest + +PATCHES=( + # https://github.com/graphcore-research/gfloat/pull/60 + "${FILESDIR}/${P}-32bit.patch" + # https://github.com/graphcore-research/gfloat/pull/64 + "${FILESDIR}/${P}-signed-zero-overflow.patch" +) + +python_test() { + local EPYTEST_IGNORE=( + # requires array-api-strict (probably not very valuable downstream) + test/test_array_api.py + # require jax + docs/source/03-value-tables.ipynb + docs/source/04-benchmark.ipynb + test/test_jax.py + # requires mx (possibly git version), torch + test/test_microxcaling.py + # requires torch + test/test_torch.py + ) + + if ! has_version "dev-python/jinja2[${PYTHON_USEDEP}]" || + ! has_version "dev-python/pandas[${PYTHON_USEDEP}]" + then + EPYTEST_IGNORE+=( + docs/source + ) + fi + + if has_version "dev-python/nbval[${PYTHON_USEDEP}]"; then + epytest -p nbval + else + epytest -o addopts= + fi +} |
