Skip to content

Computer vision examples #20

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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
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
132 changes: 45 additions & 87 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,116 +20,74 @@ defaults:
shell: bash -l {0}

jobs:
style:
name: Style
code_style:
name: ${{ matrix.check.name }}
runs-on: ubuntu-latest

strategy:
matrix:
check:
- name: Code Formatting | black
command: black --check .
- name: Import Ordering | isort
command: isort --check .
- name: Linting | flake8
command: flake8 .
- name: Type Checking | mypy
command: mypy . --cache-dir=/dev/null
steps:
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}

- name: Install requirements
run: |
grep -E '^black' dev-requirements.txt | xargs pip install
- name: Cache Python Environment
uses: actions/cache@v2
with:
path: .venv
key: ${{ runner.os }}-pyenv-${{ hashFiles('dev-requirements.txt') }}
restore-keys: |
${{ runner.os }}-pyenv-

- name: Debug info
- name: Install Development Requirements
run: |
pip freeze
python -m venv .venv
source .venv/bin/activate
pip install -r dev-requirements.txt

- name: Run black
- name: Run Code Style Check
run: |
black --check .

checks:
name: ${{ matrix.task.name }}
runs-on: ${{ matrix.task.runs_on }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
task:
- name: Lint
runs_on: ubuntu-latest
coverage_report: false
platform: cpu
run: |
make flake8
make import-sort
make typecheck

- name: CPU Tests
runs_on: ubuntu-latest
coverage_report: true
platform: cpu
run: make tests
source .venv/bin/activate
${{ matrix.check.command }}

unit_tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: conda-incubator/setup-miniconda@v2

- name: Setup Python
uses: actions/setup-python@v4
with:
miniconda-version: "latest"
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}

- name: Set build variables
run: |
# Get the exact Python version to use in the cache key.
echo "PYTHON_VERSION=$(python --version)" >> $GITHUB_ENV
echo "RUNNER_ARCH=$(uname -m)" >> $GITHUB_ENV
# Use week number in cache key so we can refresh the cache weekly.
echo "WEEK_NUMBER=$(date +%V)" >> $GITHUB_ENV

- uses: actions/cache@v3
id: virtualenv-cache
- name: Cache Python Environment
uses: actions/cache@v2
with:
path: .venv
key: >
${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-
${{ env.PYTHON_VERSION }}-${{ matrix.task.platform }}-${{ hashFiles('setup.py') }}-
${{ hashFiles('*requirements.txt') }}

- name: Setup virtual environment (no cache hit)
if: steps.virtualenv-cache.outputs.cache-hit != 'true'
run: |
python${{ env.DEFAULT_PYTHON_VERSION }} -m venv .venv
source .venv/bin/activate
make install

- name: Setup virtual environment (cache hit)
if: steps.virtualenv-cache.outputs.cache-hit == 'true'
run: |
source .venv/bin/activate
pip install --no-deps -e .[all]

- name: Debug info
run: |
source .venv/bin/activate
pip freeze
key: ${{ runner.os }}-pyenv-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pyenv-

- name: ${{ matrix.task.name }}
- name: Install Development Requirements
run: |
python -m venv .venv
source .venv/bin/activate
${{ matrix.task.run }}

- name: Prepare coverage report
if: matrix.task.coverage_report
run: |
mkdir coverage
mv coverage.xml coverage/

- name: Save coverage report
if: matrix.task.coverage_report
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.task.name }}-coverage
path: ./coverage
pip install -r requirements.txt

- name: Clean up
if: always()
- name: Run Tests
run: |
source .venv/bin/activate
pip uninstall --yes arrayfire
make tests

3 changes: 0 additions & 3 deletions .isort.cfg

This file was deleted.

25 changes: 8 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,17 @@ endif
version :
@python -c 'from arrayfire.version import VERSION; print(f"ArrayFire Python v{VERSION}")'

.PHONY : install
install :
pip install --upgrade pip
pip install pip-tools
pip-compile requirements.in -o final_requirements.txt --allow-unsafe --rebuild --verbose
pip install -e . -r final_requirements.txt
.PHONY : build
build :
@python -m build

# Testing

.PHONY : flake8
flake8 :
flake8 arrayfire tests examples
# Dev

.PHONY : import-sort
import-sort :
isort arrayfire tests examples
.PHONY : pre-commit
pre-commit :
black --check . && isort --check . && flake8 . && mypy . --cache-dir=/dev/null

.PHONY : typecheck
typecheck :
mypy arrayfire tests examples --cache-dir=/dev/null
# Testing

.PHONY : tests
tests :
Expand Down
40 changes: 16 additions & 24 deletions arrayfire/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"shift",
"tile",
"transpose",
"lookup",
]

from arrayfire.library.array_functions import (
Expand All @@ -110,6 +111,7 @@
isnan,
iszero,
join,
lookup,
lower,
moddims,
pad,
Expand All @@ -124,7 +126,7 @@
upper,
)

__all__ += ["gloh", "orb", "sift", "dog", "fast", "harris", "susan", "hamming_matcher", "nearest_neighbour"]
__all__ += ["gloh", "orb", "sift", "dog", "fast", "harris", "susan", "hamming_matcher", "nearest_neighbour", "match_template"]

from arrayfire.library.computer_vision import (
dog,
Expand All @@ -133,6 +135,7 @@
hamming_matcher,
harris,
nearest_neighbour,
match_template,
orb,
sift,
susan,
Expand All @@ -158,7 +161,6 @@
"Interp",
"IterativeDeconv",
"Pad",
"pi",
]

from arrayfire.library.constants import (
Expand All @@ -181,7 +183,6 @@
TopK,
VarianceBias,
YCCStd,
pi,
)

__all__ += [
Expand Down Expand Up @@ -550,6 +551,7 @@
"fft_convolve1",
"fft_convolve2",
"fft_convolve3",
"convolve2",
"ifft",
"ifft2",
"ifft3",
Expand All @@ -560,13 +562,23 @@
"approx1_uniform",
"approx2",
"approx2_uniform",
"convolve1",
"convolve2",
"convolve2_nn",
"convolve2_separable",
"convolve3",
]

from arrayfire.library.signal_processing import (
approx1,
approx1_uniform,
approx2,
approx2_uniform,
convolve1,
convolve2,
convolve2_nn,
convolve2_separable,
convolve3,
fft,
fft2,
fft2_c2r,
Expand All @@ -578,6 +590,7 @@
fft_convolve1,
fft_convolve2,
fft_convolve3,
convolve2,
fft_r2c,
fir,
ifft,
Expand All @@ -591,27 +604,6 @@

from arrayfire.library.statistics import corrcoef, cov, mean, median, stdev, topk, var

# TODO
# Temp solution. Remove when arrayfire-binary-python-wrapper is finalized

# __all__ += [
# "get_active_backend",
# "get_available_backends",
# "get_backend_count",
# "get_backend_id",
# "get_device_id",
# "set_backend",
# ]

# from arrayfire.library.unified_api_functions import (
# get_active_backend,
# get_available_backends,
# get_backend_count,
# get_backend_id,
# get_device_id,
# set_backend,
# )

__all__ += [
"accum",
"scan",
Expand Down
Loading