Skip to content
Open
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
22 changes: 0 additions & 22 deletions .github/workflows/build-sdist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ name: build-sdist

on:
workflow_call:
inputs:
mock:
required: false
type: boolean
default: false
upload_artifacts:
required: false
type: boolean
default: false

env:
MODULE_NAME: imops
Expand All @@ -22,31 +13,18 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Mock sdist
if: ${{ inputs.mock }}
run: |
mkdir -p dist
echo "Create mock sdist" > "dist/mock_sdist.tar.gz"

- name: Set up Python 3.9
if: ${{ inputs.mock == false }}
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Build
if: ${{ inputs.mock == false }}
run: |
pip install build wheel
python -m build --sdist

- name: Upload sdist
if: ${{ inputs.upload_artifacts }}
uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz

- name: Cleanup all local files
if: ${{ inputs.mock }}
run: rm -rf dist
34 changes: 5 additions & 29 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ on:
required: false
type: string
default: ""
mock:
required: false
type: boolean
default: false
upload_artifacts:
required: false
type: boolean
default: false

env:
MODULE_NAME: imops
Expand All @@ -26,43 +18,34 @@ jobs:
build_wheels:
strategy:
matrix:
os: [ ubuntu-22.04, windows-2022, macOS-13 ]
os: [ ubuntu-22.04, windows-2022, macOS-15 ]
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Mock wheels
if: ${{ inputs.mock }}
run: |
New-Item -ItemType Directory -Force -Path wheelhouse | Out-Null
"Create mock wheels" | Out-File -Encoding ascii "wheelhouse/mock_wheels_${{ matrix.os }}.whl"
shell: pwsh

- name: Set up Python 3.9
if: ${{ inputs.mock == false }}
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Install cibuildwheel
if: ${{ inputs.mock == false }}
run: python -m pip install cibuildwheel==2.17.0

- name: Install llvm for mac
if: ${{ matrix.os == 'macOS-13' && inputs.mock == false }}
if: ${{ matrix.os == 'macOS-15' }}
run: |
brew install llvm

- name: Install g++-11 for ubuntu
if: ${{ matrix.os == 'ubuntu-22.04' && inputs.mock == false }}
if: ${{ matrix.os == 'ubuntu-22.04' }}
id: install_cc
uses: rlalik/setup-cpp-compiler@master
with:
compiler: g++-11

- name: Check compilers for ubuntu
if: ${{ matrix.os == 'ubuntu-22.04' && inputs.mock == false }}
if: ${{ matrix.os == 'ubuntu-22.04' }}
run: |
ls /usr/bin/gcc*
ls /usr/bin/g++*
Expand All @@ -72,7 +55,6 @@ jobs:
gcc --version

- name: Build wheels
if: ${{ inputs.mock == false }}
run: |
python -m pip install --upgrade pip
python -m pip install build wheel
Expand All @@ -88,13 +70,7 @@ jobs:
fi

- name: Upload wheels
if: ${{ inputs.upload_artifacts }}
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: ./wheelhouse/*.whl

- name: Cleanup all local files
if: ${{ inputs.mock }}
run: Remove-Item -Recurse -Force wheelhouse
shell: pwsh
path: ./wheelhouse/*.whl
13 changes: 9 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ jobs:
needs: [ check_version ]
with:
cibw_build: cp37-* cp38-* cp39-* cp310-* cp311-* cp312-*
upload_artifacts: true

build_sdist:
uses: ./.github/workflows/build-sdist.yml
needs: [ check_version ]
with:
upload_artifacts: true

release:
needs: [ build_wheels, build_sdist ]
Expand All @@ -53,7 +50,15 @@ jobs:
with:
path: dist

- name: Flatten dist directory
run: |
shopt -s globstar
mkdir -p flat
cp dist/**/* flat/ || true
rm -rf dist
mv flat dist

- name: Publish to PyPi
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
40 changes: 40 additions & 0 deletions .github/workflows/test-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test release

on: [ pull_request ]

env:
MODULE_NAME: imops

jobs:
build_wheels:
uses: ./.github/workflows/build-wheels.yml
with:
cibw_build: cp37-* cp39-* cp312-*
cibw_skip: "*manylinux_x86_64 *musllinux_x86_64"

build_sdist:
uses: ./.github/workflows/build-sdist.yml

publish_testpypi:
needs: [ build_wheels, build_sdist ]
runs-on: ubuntu-latest

steps:
- uses: actions/download-artifact@v4
with:
path: dist

- name: Flatten dist directory
run: |
shopt -s globstar
mkdir -p flat
cp dist/**/* flat/ || true
rm -rf dist
mv flat dist

- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
skip-existing: true
40 changes: 0 additions & 40 deletions .github/workflows/test_artifacts_io.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/test_build.yml

This file was deleted.

6 changes: 2 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ jobs:

- name: Test with pytest
run: |
pytest tests -m "not nonumba" --junitxml=reports/junit-${{ matrix.python-version }}.xml --cov="$MODULE_PARENT/$MODULE_NAME" --cov-report=xml --cov-branch
pip uninstall numba -y
pytest tests/test_backend.py -m nonumba
pytest tests -n 2 --junitxml=reports/junit-${{ matrix.python-version }}.xml --cov="$MODULE_PARENT/$MODULE_NAME" --cov-report=xml --cov-branch
- name: Generate coverage report
run: |
coverage xml -o reports/coverage-${{ matrix.python-version }}.xml --omit=imops/src/_numba_zoom.py
coverage xml -o reports/coverage-${{ matrix.python-version }}.xml
sed -i -e "s|$MODULE_PARENT/||g" reports/coverage-${{ matrix.python-version }}.xml
sed -i -e "s|$(echo $MODULE_PARENT/ | tr "/" .)||g" reports/coverage-${{ matrix.python-version }}.xml

Expand Down
54 changes: 25 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@ Efficient parallelizable algorithms for multidimensional arrays to speed up your

```shell
pip install imops # default install with Cython backend
pip install imops[numba] # additionally install Numba backend
```

# How fast is it?

Time comparisons (ms) for Intel(R) Xeon(R) Silver 4114 CPU @ 2.20GHz using 8 threads. All inputs are C-contiguous NumPy arrays. For morphology functions `bool` dtype is used and `float64` for all others.
| function / backend | Scipy() | Cython(fast=False) | Cython(fast=True) | Numba() |
|:----------------------:|:-----------:|:----------------------:|:---------------------:|:-----------:|
| `zoom(..., order=0)` | 2072 | 1114 | **867** | 3590 |
| `zoom(..., order=1)` | 6527 | 596 | **575** | 3757 |
| `interp1d` | 780 | 149 | **146** | 420 |
| `radon` | 59711 | 5982 | **4837** | - |
| `inverse_radon` | 52928 | 8254 | **6535** | - |
| `binary_dilation` | 2207 | 310 | **298** | - |
| `binary_erosion` | 2296 | 326 | **304** | - |
| `binary_closing` | 4158 | 544 | **469** | - |
| `binary_opening` | 4410 | 567 | **522** | - |
| `center_of_mass` | 2237 | **64** | **64** | - |
| function / backend | Scipy() | Cython(fast=False) | Cython(fast=True) |
|:----------------------:|:-----------:|:----------------------:|:---------------------:|
| `zoom(..., order=0)` | 2072 | 1114 | **867** |
| `zoom(..., order=1)` | 6527 | 596 | **575** |
| `interp1d` | 780 | 149 | **146** |
| `radon` | 59711 | 5982 | **4837** |
| `inverse_radon` | 52928 | 8254 | **6535** |
| `binary_dilation` | 2207 | 310 | **298** |
| `binary_erosion` | 2296 | 326 | **304** |
| `binary_closing` | 4158 | 544 | **469** |
| `binary_opening` | 4410 | 567 | **522** |
| `center_of_mass` | 2237 | **64** | **64** |

We use [`airspeed velocity`](https://asv.readthedocs.io/en/stable/) to benchmark our code. For detailed results visit [benchmark page](https://neuro-ml.github.io/imops/benchmarks/).

Expand Down Expand Up @@ -121,36 +120,33 @@ labeled, num_components = label(x, background=1, return_num=True)
# Backends
For all heavy image routines except `label` you can specify which backend to use. Backend can be specified by a string or by an instance of `Backend` class. The latter allows you to customize some backend options:
```python
from imops import Cython, Numba, Scipy, zoom
from imops import Cython, Scipy, zoom

y = zoom(x, 2, backend='Cython')
y = zoom(x, 2, backend=Cython(fast=False)) # same as previous
y = zoom(x, 2, backend=Cython(fast=True)) # -ffast-math compiled cython backend
y = zoom(x, 2, backend=Scipy()) # use scipy original implementation
y = zoom(x, 2, backend='Numba')
y = zoom(x, 2, backend=Numba(parallel=True, nogil=True, cache=True)) # same as previous
```
Also backend can be specified globally or locally:
```python
from imops import imops_backend, set_backend, zoom

set_backend('Numba') # sets Numba as default backend
set_backend('Scipy') # sets Scipy as default backend
with imops_backend('Cython'): # sets Cython backend via context manager
zoom(x, 2)
```
Note that for `Numba` backend setting `num_threads` argument has no effect for now and you should use `NUMBA_NUM_THREADS` environment variable.
Available backends:
| function / backend | Scipy | Cython | Numba |
|:-------------------:|:---------:|:---------:|:---------:|
| `zoom` | ✓ | ✓ | ✓ |
| `interp1d` | ✓ | ✓ | ✓ |
| `radon` | ✗ | ✓ | ✗ |
| `inverse_radon` | ✗ | ✓ | ✗ |
| `binary_dilation` | ✓ | ✓ | ✗ |
| `binary_erosion` | ✓ | ✓ | ✗ |
| `binary_closing` | ✓ | ✓ | ✗ |
| `binary_opening` | ✓ | ✓ | ✗ |
| `center_of_mass` | ✓ | ✓ | ✗ |
| function / backend | Scipy | Cython |
|:-------------------:|:---------:|:---------:|
| `zoom` | ✓ | ✓ |
| `interp1d` | ✓ | ✓ |
| `radon` | ✗ | ✓ |
| `inverse_radon` | ✗ | ✓ |
| `binary_dilation` | ✓ | ✓ |
| `binary_erosion` | ✓ | ✓ |
| `binary_closing` | ✓ | ✓ |
| `binary_opening` | ✓ | ✓ |
| `center_of_mass` | ✓ | ✓ |

# Acknowledgements

Expand Down
4 changes: 1 addition & 3 deletions asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
"Cython": ["3.0.10"],
"scipy": [],
"scikit-image": [],
"numba": [],
"pip+connected-components-3d": [],
"pip+fastremap": [],
"pybind11": []
},
"env_nobuild": {
"OMP_NUM_THREADS": "8",
"NUMBA_NUM_THREADS": "8"
"OMP_NUM_THREADS": "8"
}
},
"env_dir": ".asv/env",
Expand Down
Loading
Loading