Skip to content

NaN tests + Workflow + README fixes #114

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 7 commits into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
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
89 changes: 48 additions & 41 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -194,54 +194,61 @@ 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')

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 TestPyPI
uses: pypa/[email protected]

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
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.ACCESS_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.ACCESS_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 }}
35 changes: 20 additions & 15 deletions quaddtype/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,38 +23,41 @@ 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
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

# 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
```

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,
```
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
```

12 changes: 10 additions & 2 deletions quaddtype/reinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 4 additions & 0 deletions quaddtype/tests/test_quaddtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down