From 7a5a4bf541cdab93eaf3b9fd0f649566e50bf1e0 Mon Sep 17 00:00:00 2001 From: SwayamInSync Date: Thu, 3 Jul 2025 17:55:15 +0000 Subject: [PATCH 1/7] updated readme and tests as per sleef 3.8 --- quaddtype/README.md | 28 ++++++++++++---------------- quaddtype/tests/test_quaddtype.py | 4 ++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/quaddtype/README.md b/quaddtype/README.md index bd06738..19bb048 100644 --- a/quaddtype/README.md +++ b/quaddtype/README.md @@ -1,10 +1,12 @@ # Numpy-QuadDType +A cross-platform Quad (128-bit) float Data-Type for NumPy. + ## Installation -``` -pip install numpy==2.1.0 -pip install -i https://test.pypi.org/simple/ quaddtype +```bash +pip install numpy +pip install numpy-quaddtype ``` ## Usage @@ -21,7 +23,7 @@ np.array([1,2,3], dtype=QuadPrecDType("sleef")) np.array([1,2,3], dtype=QuadPrecDType("longdouble")) ``` -## Install from source +## Installation from source The code needs the quad precision pieces of the sleef library, which is not available on most systems by default, so we have to generate @@ -29,30 +31,24 @@ that first. The below assumes one has the required pieces to build sleef (cmake and libmpfr-dev), and that one is in the package directory locally. -``` -git clone https://github.com/shibatch/sleef.git +```bash +git clone --branch 3.8 https://github.com/shibatch/sleef.git cd sleef cmake -S . -B build -DSLEEF_BUILD_QUAD:BOOL=ON -DSLEEF_BUILD_SHARED_LIBS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON cmake --build build/ --clean-first -j cd .. ``` -In principle, one can now install this system-wide, but easier would -seem to use the version that was just created, as follows: -``` +Building the `numpy-quaddtype` package from locally installed sleef: +```bash export SLEEF_DIR=$PWD/sleef/build export LIBRARY_PATH=$SLEEF_DIR/lib export C_INCLUDE_PATH=$SLEEF_DIR/include export CPLUS_INCLUDE_PATH=$SLEEF_DIR/include -python3 -m venv temp -source temp/bin/activate + +# Install the package pip install meson-python numpy pytest pip install -e . -v --no-build-isolation export LD_LIBRARY_PATH=$SLEEF_DIR/lib ``` -Here, we created an editable install on purpose, so one can just work -from the package directory if needed, e.g., to run the tests with, -``` -python -m pytest -``` diff --git a/quaddtype/tests/test_quaddtype.py b/quaddtype/tests/test_quaddtype.py index 71dcb70..bf0762f 100644 --- a/quaddtype/tests/test_quaddtype.py +++ b/quaddtype/tests/test_quaddtype.py @@ -70,6 +70,10 @@ def test_unary_ops(op, val, expected): assert result == expected_val, f"{op}({val}) should be {expected}, but got {result}" +def test_inf(): + assert QuadPrecision("inf") > QuadPrecision("1e1000") + assert QuadPrecision("-inf") < QuadPrecision("-1e1000") + def test_dtype_creation(): dtype = QuadPrecDType() From 07b00f9d01a6f6f038b851584fbc83fb7a490e47 Mon Sep 17 00:00:00 2001 From: SwayamInSync Date: Thu, 3 Jul 2025 18:26:01 +0000 Subject: [PATCH 2/7] switching to pypi from testpypi --- .github/workflows/build_wheels.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 3ab23ff..0fcb70a 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -194,8 +194,8 @@ jobs: path: ./quaddtype/wheelhouse/*.whl name: wheels-windows-${{ matrix.architecture }} - publish_to_testpypi: - name: Publish to TestPyPI + publish_to_pypi: + name: Publish to PyPI needs: [build_wheels_linux, build_wheels_macos, build_wheels_windows] runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/quaddtype-v') @@ -204,12 +204,11 @@ jobs: uses: actions/download-artifact@v4 with: path: dist - - name: Publish to TestPyPI + - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@v1.9.0 with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} - repository-url: https://test.pypi.org/legacy/ packages-dir: dist/* create_release: From d171dd65e906f9bd6d4fa4aedbb43c7b69d3b6e3 Mon Sep 17 00:00:00 2001 From: SwayamInSync Date: Fri, 4 Jul 2025 11:22:48 +0000 Subject: [PATCH 3/7] switching to trusted publishing --- .github/workflows/build_wheels.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 0fcb70a..91be73a 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -199,16 +199,23 @@ jobs: needs: [build_wheels_linux, build_wheels_macos, build_wheels_windows] runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/quaddtype-v') + + environment: + name: quadtype_release + url: https://pypi.org/p/numpy-quaddtype + + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + steps: - name: Download all workflow run artifacts uses: actions/download-artifact@v4 with: path: dist + - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@v1.9.0 + uses: pypa/gh-action-pypi-publish@release/v1 with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} packages-dir: dist/* create_release: From 31294c70110174105a1fce73e10ebb7b1c598d48 Mon Sep 17 00:00:00 2001 From: SwayamInSync Date: Fri, 4 Jul 2025 11:36:28 +0000 Subject: [PATCH 4/7] changing release token --- .github/workflows/build_wheels.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 91be73a..dd232ef 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -237,7 +237,7 @@ jobs: id: create_release uses: actions/create-release@v1 env: - GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ secrets.QUADDTYPE_GITHUB_TOKEN }} with: tag_name: ${{ github.ref }} release_name: Release ${{ github.ref }} @@ -250,4 +250,4 @@ jobs: with: files: ./artifacts/**/*.whl env: - GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ secrets.QUADDTYPE_GITHUB_TOKEN }} From 662112e8def743fd1f36bdeb90a0e06012064d74 Mon Sep 17 00:00:00 2001 From: SwayamInSync Date: Fri, 4 Jul 2025 16:35:04 +0000 Subject: [PATCH 5/7] commenting github specific release for now --- .github/workflows/build_wheels.yml | 67 +++++++++++++++--------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index dd232ef..e8be2b9 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -218,36 +218,37 @@ jobs: with: packages-dir: dist/* - create_release: - name: Create Release - needs: [build_wheels_linux, build_wheels_macos, build_wheels_windows] - runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/quaddtype-v') - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Download all workflow run artifacts - uses: actions/download-artifact@v4 - with: - path: artifacts - - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.QUADDTYPE_GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - draft: false - prerelease: false - - - name: Upload Release Assets - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') - with: - files: ./artifacts/**/*.whl - env: - GITHUB_TOKEN: ${{ secrets.QUADDTYPE_GITHUB_TOKEN }} + # With the current setup, we are not creating a release on GitHub. + # create_release: + # name: Create Release + # needs: [build_wheels_linux, build_wheels_macos, build_wheels_windows] + # runs-on: ubuntu-latest + # if: startsWith(github.ref, 'refs/tags/quaddtype-v') + + # steps: + # - name: Checkout code + # uses: actions/checkout@v2 + + # - name: Download all workflow run artifacts + # uses: actions/download-artifact@v4 + # with: + # path: artifacts + + # - name: Create Release + # id: create_release + # uses: actions/create-release@v1 + # env: + # GITHUB_TOKEN: ${{ secrets.QUADDTYPE_GITHUB_TOKEN }} + # with: + # tag_name: ${{ github.ref }} + # release_name: Release ${{ github.ref }} + # draft: false + # prerelease: false + + # - name: Upload Release Assets + # uses: softprops/action-gh-release@v1 + # if: startsWith(github.ref, 'refs/tags/') + # with: + # files: ./artifacts/**/*.whl + # env: + # GITHUB_TOKEN: ${{ secrets.QUADDTYPE_GITHUB_TOKEN }} From 930a8e20fd0052f147e90c5fe4ae52472cae867d Mon Sep 17 00:00:00 2001 From: SwayamInSync Date: Fri, 4 Jul 2025 17:27:54 +0000 Subject: [PATCH 6/7] turning off parallel cmake build in windows --- .github/workflows/build_wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index e8be2b9..2d1d4d5 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -148,7 +148,7 @@ jobs: git clone --branch 3.8 https://github.com/shibatch/sleef.git cd sleef cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture == 'x86' && 'Win32' || 'x64' }} -DSLEEF_BUILD_QUAD:BOOL=ON -DSLEEF_BUILD_SHARED_LIBS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON - cmake --build build --config Release --parallel + cmake --build build --config Release cmake --install build --prefix "C:/sleef" --config Release - name: Setup build environment From bd90748fa486e1a536dca7b6f891ab3c086f07db Mon Sep 17 00:00:00 2001 From: SwayamInSync Date: Fri, 4 Jul 2025 18:23:44 +0000 Subject: [PATCH 7/7] updating readme --- quaddtype/README.md | 13 +++++++++++-- quaddtype/reinstall.sh | 12 ++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/quaddtype/README.md b/quaddtype/README.md index 19bb048..614a3c2 100644 --- a/quaddtype/README.md +++ b/quaddtype/README.md @@ -46,9 +46,18 @@ export LIBRARY_PATH=$SLEEF_DIR/lib export C_INCLUDE_PATH=$SLEEF_DIR/include export CPLUS_INCLUDE_PATH=$SLEEF_DIR/include +# setup the virtual env +python3 -m venv temp +source temp/bin/activate + # Install the package pip install meson-python numpy pytest -pip install -e . -v --no-build-isolation -export LD_LIBRARY_PATH=$SLEEF_DIR/lib + +export LDFLAGS="-Wl,-rpath,$SLEEF_DIR/lib" +python -m pip install . -v --no-build-isolation -Cbuilddir=build -C'compile-args=-v' + +# Run the tests +cd .. +python -m pytest ``` diff --git a/quaddtype/reinstall.sh b/quaddtype/reinstall.sh index 5131f15..1c08f84 100755 --- a/quaddtype/reinstall.sh +++ b/quaddtype/reinstall.sh @@ -7,7 +7,15 @@ then rm -r build fi -#meson setup build -Db_sanitize=address,undefined +export CC=clang +export CXX=clang++ +export SLEEF_DIR=$PWD/sleef/build +export LIBRARY_PATH=$SLEEF_DIR/lib +export C_INCLUDE_PATH=$SLEEF_DIR/include +export CPLUS_INCLUDE_PATH=$SLEEF_DIR/include + +# Set RPATH via LDFLAGS +export LDFLAGS="-Wl,-rpath,$SLEEF_DIR/lib" + python -m pip uninstall -y numpy_quaddtype -# python -m pip install . -v --no-build-isolation -Cbuilddir=build -C'compile-args=-v' -Csetup-args="-Dbuildtype=debug" python -m pip install . -v --no-build-isolation -Cbuilddir=build -C'compile-args=-v' \ No newline at end of file