Skip to content

Commit

Permalink
BUILD: Add support for numpy 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zoj613 committed Jul 17, 2024
1 parent bcb062f commit 4953a6f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
os: [ ubuntu-20.04, macOS-11, windows-2019 ]
os: [ ubuntu-20.04, macOS-12, windows-2019 ]
python-version: [ '3.9', 'pypy3.9', '3.10', '3.11', '3.12' ]
fail-fast: false

Expand Down
62 changes: 31 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,39 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-20.04, macOS-11, windows-2019 ]
os: [ ubuntu-20.04, macOS-12, windows-2019 ]
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-tags: 'true'
fetch-depth: 0

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Cythonize C-extensions
run: |
python3 -m pip install --upgrade pip cython==3.0.*
python3 -m pip install --upgrade pip cibuildwheel==2.19.2
python3 -m pip install -r requirements-dev.txt
cythonize polyagamma/*.pyx
- name: Build wheels
uses: pypa/cibuildwheel@v2.15.0
uses: pypa/cibuildwheel@v2.19.2
with:
package-dir: .
output-dir: wheelhouse
config-file: "pyproject.toml"

- name: Set up Python
if: ${{ matrix.os == 'ubuntu-20.04' }}
uses: actions/[email protected]
with:
python-version: '3.9'

- name: Build source distribution
if: ${{ matrix.os == 'ubuntu-20.04' }}
run: |
Expand All @@ -65,23 +65,23 @@ jobs:
name: wheels_and_sdist
path: wheelhouse
if-no-files-found: error

upload_pypi:
needs: [ build_wheels_and_sdist ]
runs-on: ubuntu-20.04
environment:
name: pypi
url: https://pypi.org/p/polyagamma
permissions:
id-token: write
steps:
- name: Pull built wheels and sdist
uses: actions/download-artifact@v3
with:
name: wheels_and_sdist
path: wheelhouse

- name: Publish to PyPI
uses: pypa/[email protected]
with:
packages_dir: wheelhouse
#
# upload_pypi:
# needs: [ build_wheels_and_sdist ]
# runs-on: ubuntu-20.04
# environment:
# name: pypi
# url: https://pypi.org/p/polyagamma
# permissions:
# id-token: write
# steps:
# - name: Pull built wheels and sdist
# uses: actions/download-artifact@v3
# with:
# name: wheels_and_sdist
# path: wheelhouse
#
# - name: Publish to PyPI
# uses: pypa/[email protected]
# with:
# packages_dir: wheelhouse
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ requires = [
# the used version of python. This does not affect required numpy version at
# installation time; `project.dependencies` is most relevant for required numpy
# when installtng at user level.
"numpy==1.26.0; python_version=='3.12' and platform_python_implementation!='PyPy'",
"numpy==1.23.2; python_version=='3.11' and platform_python_implementation!='PyPy'",
"numpy==1.21.3; python_version=='3.10' and platform_python_implementation!='PyPy'",
"numpy==1.19.3; python_version=='3.9' and platform_python_implementation!='PyPy'",
"numpy==2.0.0; python_version=='3.12' and platform_python_implementation!='PyPy'",
"numpy==2.0.0; python_version=='3.11' and platform_python_implementation!='PyPy'",
"numpy==2.0.0; python_version=='3.10' and platform_python_implementation!='PyPy'",
"numpy==2.0.0; python_version=='3.9' and platform_python_implementation!='PyPy'",
# PyPy specific requirements
"numpy==1.25.0; python_version=='3.9' and platform_python_implementation=='PyPy'",
"numpy==2.0.0; python_version=='3.9' and platform_python_implementation=='PyPy'",
]
build-backend = "setuptools.build_meta"

Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cython==3.0.*
numpy==1.26.0
numpy==2.0.0
pre-commit==3.4.0
pytest==7.4.0
pytest-cov==4.1.0
setuptools==70.3.0
4 changes: 2 additions & 2 deletions tests/test_polyagamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_polyagamma_pdf_cdf(method, h, z):
x = random_polyagamma(h, z, size=5000, method=method, random_state=rng)
x.sort()
d = polyagamma_pdf(x, h=h, z=z)
area_under_curve = np.trapz(d, x)
area_under_curve = np.trapezoid(d, x)
# relative tolerance is set so that 0.998 can pass the tests.
assert np.isclose(1.0, area_under_curve, rtol=1e-2)

Expand All @@ -181,7 +181,7 @@ def test_polyagamma_pdf_cdf(method, h, z):
# calculate the cdf of the distribution at the mean of the samples
cdf = polyagamma_cdf(xx, h=h, z=z)
# estimate empirical cdf from the sampled and corresponding density
ecdf = np.trapz(d[mask], x[mask])
ecdf = np.trapezoid(d[mask], x[mask])
# test if the empirical cdf is equal to the distribution's to 2 decimals
assert np.allclose(ecdf, cdf, rtol=1e-2)

Expand Down

0 comments on commit 4953a6f

Please sign in to comment.