Skip to content

Commit

Permalink
Add support for NumPy 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pmneila committed Nov 25, 2024
1 parent deefd7e commit 53a32a2
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 81 deletions.
81 changes: 14 additions & 67 deletions .github/workflows/maxflow-ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
name: PyMaxflow CI
name: PyMaxflow tests

on: [push]
on:
push:
branches: [master]
pull_request:

jobs:
test:
name: Build and test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
Expand All @@ -18,76 +21,20 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools cython oldest-supported-numpy
- name: Build the package
python -m pip install --upgrade pip
- name: Install the package
run: |
python setup.py build_ext --inplace
- name: Test and coverage
python -m pip install -e .
- name: Install dependencies for test
run: |
python -m pip install imageio networkx
python -m pip install pytest>=7.2.0 pytest-cov>=4.0 codecov
python -m pip install imageio networkx
- name: Test and coverage
run: |
mkdir output
python -m pytest --cov=maxflow --cov-report=xml
codecov
- name: Flake8
run: |
python -m pip install flake8
flake8 .
deploy-sdist:
name: Deploy source distribution
runs-on: ubuntu-latest
needs: test
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI }}
if: github.ref == 'refs/heads/master'

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install cibuildwheel
run: |
python -m pip install --upgrade pip
python -m pip install build
- name: Build sdist
run: python -m build --sdist
- name: Deploy sdist
run: |
python3 -m pip install twine
python3 -m twine upload --skip-existing dist/*
deploy-wheels:
name: Deploy wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: test
env:
CIBW_ARCHS: "auto64"
CIBW_BUILD: "cp37-* cp38-* cp39-* cp310-* cp311-* pp*"
CIBW_SKIP: "*musllinux* pp*-win* pp*-macosx*"
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI }}
if: github.ref == 'refs/heads/master'

strategy:
matrix:
os: [ubuntu-20.04, windows-2019, macOS-11]

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install cibuildwheel
run: |
python -m pip install --upgrade pip
python -m pip install cibuildwheel==2.11.4
- name: Build wheels
run: python3 -m cibuildwheel --output-dir wheelhouse
- name: Deploy
run: |
python3 -m pip install twine
python3 -m twine upload --skip-existing wheelhouse/*.whl
61 changes: 61 additions & 0 deletions .github/workflows/maxflow-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: PyMaxflow deployment

on:
push:
tags: 'v[0-9]+*'

jobs:
deploy-sdist:
name: Deploy source distribution
runs-on: ubuntu-latest
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI }}

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install cibuildwheel
run: |
python -m pip install --upgrade pip
python -m pip install build
- name: Build sdist
run: python -m build --sdist
- name: Deploy sdist
run: |
python3 -m pip install twine
python3 -m twine upload --skip-existing dist/*
deploy-wheels:
name: Deploy wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
CIBW_ARCHS: "auto64"
CIBW_BUILD: "cp39-* cp310-* cp311-* cp312-*"
CIBW_SKIP: "*musllinux* pp*-win* pp*-macosx* pp*"
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install cibuildwheel
run: |
python -m pip install --upgrade pip
python -m pip install cibuildwheel
- name: Build wheels
run: python3 -m cibuildwheel --output-dir wheelhouse
- name: Deploy
run: |
python3 -m pip install twine
python3 -m twine upload --skip-existing wheelhouse/*.whl
2 changes: 1 addition & 1 deletion maxflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import numpy as np
from . import _maxflow
from ._maxflow import GraphInt, GraphFloat, moore_structure, vonNeumann_structure
from .version import __version__, __version_str__, __version_core__
from .version import __version__, __version_core__
from .fastmin import aexpansion_grid, abswap_grid

Graph = {int: GraphInt, float: GraphFloat}
Expand Down
13 changes: 7 additions & 6 deletions maxflow/src/grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ std::vector<T> getVector(PyArrayObject* arr, int length)
return std::vector<T>(length, value);
}

// add_ndim == 1
// arr_ndim == 1
if(arr_shape[0] < length)
throw std::runtime_error("the length of `periodic` must be equal to the number of dimensions of `nodeids`");

Expand Down Expand Up @@ -149,11 +149,11 @@ void Graph<captype,tcaptype,flowtype>::add_grid_edges(PyArrayObject* _nodeids,
}
catch(std::exception& e)
{
Py_DECREF(periodicArr);
Py_DECREF(structureArr);
Py_DECREF(weights);
Py_DECREF(nodeids);
throw e;
Py_DECREF(periodicArr);
Py_DECREF(structureArr);
Py_DECREF(weights);
Py_DECREF(nodeids);
throw e;
}

// Create the edges
Expand All @@ -168,6 +168,7 @@ void Graph<captype,tcaptype,flowtype>::add_grid_edges(PyArrayObject* _nodeids,

if(iter == NULL)
{
Py_DECREF(periodicArr);
Py_DECREF(structureArr);
Py_DECREF(weights);
Py_DECREF(nodeids);
Expand Down
3 changes: 1 addition & 2 deletions maxflow/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- encoding:utf-8 -*-

__version__ = (1, 3, 0)
__version_str__ = ".".join(map(str, __version__))
__version__ = "1.3.2"
__version_core__ = (3, 0, 4)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools", "wheel", "Cython", "oldest-supported-numpy"]
requires = ["setuptools", "wheel", "Cython", "numpy~=2.0"]
build-backend = "setuptools.build_meta"
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from Cython.Build import cythonize

# Get the version number.
__version_str__ = runpy.run_path("maxflow/version.py")["__version_str__"]
__version__ = runpy.run_path("maxflow/version.py")["__version__"]


def extensions():
Expand Down Expand Up @@ -44,7 +44,7 @@ def extensions():

setup(
name="PyMaxflow",
version=__version_str__,
version=__version__,
description="A mincut/maxflow package for Python",
author="Pablo Márquez Neila",
author_email="[email protected]",
Expand Down Expand Up @@ -82,5 +82,5 @@ def extensions():
],
packages=["maxflow"],
ext_modules=extensions(),
install_requires=['numpy']
install_requires=['numpy>=1.26']
)

0 comments on commit 53a32a2

Please sign in to comment.