Skip to content
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
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-* cp313-*"
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 doc/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ belongs to the sink segment (i.e., the corresponding pixel has the label 0). We
now get the labels for each pixel::

# The labels should be 1 where sgm is False and 0 otherwise.
img2 = np.int_(np.logical_not(sgm))
img2 = np.int64(np.logical_not(sgm))
# Show the result.
from matplotlib import pyplot as ppl
ppl.imshow(img2)
Expand Down
2 changes: 1 addition & 1 deletion examples/binary_restoration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
sgm = g.get_grid_segments(nodeids)

# The labels should be 1 where sgm is False and 0 otherwise.
img2 = np.int_(np.logical_not(sgm))
img2 = np.int64(np.logical_not(sgm))
# Show the result.
ppl.imshow(img2, cmap=ppl.cm.gray, interpolation='nearest')
ppl.show()
2 changes: 1 addition & 1 deletion examples/layout_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
central_node = nodeids[12]
rest_of_nodes = np.hstack([nodeids[:12], nodeids[13:]])

nodeids = np.empty((2, 24), dtype=np.int_)
nodeids = np.empty((2, 24), dtype=np.int64)
nodeids[0] = central_node
nodeids[1] = rest_of_nodes

Expand Down
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
4 changes: 2 additions & 2 deletions maxflow/fastmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def abswap_grid(unary, binary, max_cycles=None, labels=None):
if num_labels <= 127:
labels = np.int8(unary.argmin(axis=-1))
else:
labels = np.int_(unary.argmin(axis=-1))
labels = np.int64(unary.argmin(axis=-1))
else:
if labels.min() < 0:
raise ValueError("Values of labels must be non-negative")
Expand Down Expand Up @@ -182,7 +182,7 @@ def aexpansion_grid(unary, binary, max_cycles=None, labels=None):
if num_labels <= 127:
labels = np.int8(unary.argmin(axis=-1))
else:
labels = np.int_(unary.argmin(axis=-1))
labels = np.int64(unary.argmin(axis=-1))
else:
if labels.min() < 0:
raise ValueError("Values of labels must be non-negative")
Expand Down
4 changes: 2 additions & 2 deletions maxflow/src/_maxflow.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ cdef public class GraphInt [object PyObject_GraphInt, type GraphInt]:
"""
num_nodes = np.prod(shape)
first = self.thisptr.add_node(int(num_nodes))
nodes = np.arange(first, first+num_nodes, dtype=np.int_)
nodes = np.arange(first, first+num_nodes, dtype=np.int64)
return np.reshape(nodes, shape)
def add_edge(self, int i, int j, long capacity, long rcapacity):
"""
Expand Down Expand Up @@ -639,7 +639,7 @@ cdef public class GraphFloat [object PyObject_GraphFloat, type GraphFloat]:
"""
num_nodes = np.prod(shape)
first = self.thisptr.add_node(int(num_nodes))
nodes = np.arange(first, first+num_nodes, dtype=np.int_)
nodes = np.arange(first, first+num_nodes, dtype=np.int64)
return np.reshape(nodes, shape)
def add_edge(self, int i, int j, double capacity, double rcapacity):
"""
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="pablo.marquez@unibe.ch",
Expand Down Expand Up @@ -82,5 +82,5 @@ def extensions():
],
packages=["maxflow"],
ext_modules=extensions(),
install_requires=['numpy']
install_requires=['numpy>=1.26']
)
8 changes: 4 additions & 4 deletions test_maxflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_fastmin_edge_cases():

# Array with 0 spatial dimensions
unary = np.zeros((0, 0, 3))
binary = np.ones((3, 3), dtype=np.float_) - np.eye(3, dtype=np.float_)
binary = np.ones((3, 3), dtype=np.float64) - np.eye(3, dtype=np.float64)
labels = maxflow.aexpansion_grid(unary, binary)
assert labels.shape == (0, 0)

Expand Down Expand Up @@ -203,7 +203,7 @@ def test_fastmin_edge_cases():
# Shape of initial labels do not match the shape of the unary array
unary = np.zeros((3, 3, 3))
binary = np.zeros((3, 3))
labels = np.ones((4, 4), dtype=np.int_)
labels = np.ones((4, 4), dtype=np.int64)
with pytest.raises(Exception):
maxflow.aexpansion_grid(unary, binary, labels=labels)
with pytest.raises(Exception):
Expand All @@ -212,7 +212,7 @@ def test_fastmin_edge_cases():
# Initial labels contain values larger than num_labels
unary = np.zeros((3, 3, 3))
binary = np.zeros((3, 3))
labels = np.full((3, 3), 5, dtype=np.int_)
labels = np.full((3, 3), 5, dtype=np.int64)
with pytest.raises(ValueError):
maxflow.aexpansion_grid(unary, binary, labels=labels)
with pytest.raises(ValueError):
Expand All @@ -221,7 +221,7 @@ def test_fastmin_edge_cases():
# Initial labels contain negative values
unary = np.zeros((3, 3, 3))
binary = np.zeros((3, 3))
labels = np.full((3, 3), -1, dtype=np.int_)
labels = np.full((3, 3), -1, dtype=np.int64)
with pytest.raises(ValueError):
maxflow.aexpansion_grid(unary, binary, labels=labels)
with pytest.raises(ValueError):
Expand Down
Loading