Skip to content

Commit 65b5ccd

Browse files
authored
Array API Implementation (#12)
* Add fixed array-api code * Add Device support * Add docs * Fix bugs * Add tags * Update requirements * Fix missing dependencies. * Fix CI and Makefile * Move setup.py and configs to pyproject.toml
1 parent 6f133f3 commit 65b5ccd

34 files changed

+6113
-339
lines changed

.github/workflows/ci.yml

Lines changed: 45 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -20,116 +20,74 @@ defaults:
2020
shell: bash -l {0}
2121

2222
jobs:
23-
style:
24-
name: Style
23+
code_style:
24+
name: ${{ matrix.check.name }}
2525
runs-on: ubuntu-latest
26-
26+
strategy:
27+
matrix:
28+
check:
29+
- name: Code Formatting | black
30+
command: black --check .
31+
- name: Import Ordering | isort
32+
command: isort --check .
33+
- name: Linting | flake8
34+
command: flake8 .
35+
- name: Type Checking | mypy
36+
command: mypy . --cache-dir=/dev/null
2737
steps:
2838
- uses: actions/checkout@v3
29-
39+
3040
- name: Setup Python
3141
uses: actions/setup-python@v4
3242
with:
3343
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
3444

35-
- name: Install requirements
36-
run: |
37-
grep -E '^black' dev-requirements.txt | xargs pip install
45+
- name: Cache Python Environment
46+
uses: actions/cache@v2
47+
with:
48+
path: .venv
49+
key: ${{ runner.os }}-pyenv-${{ hashFiles('dev-requirements.txt') }}
50+
restore-keys: |
51+
${{ runner.os }}-pyenv-
3852
39-
- name: Debug info
53+
- name: Install Development Requirements
4054
run: |
41-
pip freeze
55+
python -m venv .venv
56+
source .venv/bin/activate
57+
pip install -r dev-requirements.txt
4258
43-
- name: Run black
59+
- name: Run Code Style Check
4460
run: |
45-
black --check .
46-
47-
checks:
48-
name: ${{ matrix.task.name }}
49-
runs-on: ${{ matrix.task.runs_on }}
50-
timeout-minutes: 30
51-
strategy:
52-
fail-fast: false
53-
matrix:
54-
task:
55-
- name: Lint
56-
runs_on: ubuntu-latest
57-
coverage_report: false
58-
platform: cpu
59-
run: |
60-
make flake8
61-
make import-sort
62-
make typecheck
63-
64-
- name: CPU Tests
65-
runs_on: ubuntu-latest
66-
coverage_report: true
67-
platform: cpu
68-
run: make tests
61+
source .venv/bin/activate
62+
${{ matrix.check.command }}
6963
64+
unit_tests:
65+
name: Unit Tests
66+
runs-on: ubuntu-latest
7067
steps:
7168
- uses: actions/checkout@v3
72-
73-
- uses: conda-incubator/setup-miniconda@v2
69+
70+
- name: Setup Python
71+
uses: actions/setup-python@v4
7472
with:
75-
miniconda-version: "latest"
7673
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
7774

78-
- name: Set build variables
79-
run: |
80-
# Get the exact Python version to use in the cache key.
81-
echo "PYTHON_VERSION=$(python --version)" >> $GITHUB_ENV
82-
echo "RUNNER_ARCH=$(uname -m)" >> $GITHUB_ENV
83-
# Use week number in cache key so we can refresh the cache weekly.
84-
echo "WEEK_NUMBER=$(date +%V)" >> $GITHUB_ENV
85-
86-
- uses: actions/cache@v3
87-
id: virtualenv-cache
75+
- name: Cache Python Environment
76+
uses: actions/cache@v2
8877
with:
8978
path: .venv
90-
key: >
91-
${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-
92-
${{ env.PYTHON_VERSION }}-${{ matrix.task.platform }}-${{ hashFiles('setup.py') }}-
93-
${{ hashFiles('*requirements.txt') }}
94-
95-
- name: Setup virtual environment (no cache hit)
96-
if: steps.virtualenv-cache.outputs.cache-hit != 'true'
97-
run: |
98-
python${{ env.DEFAULT_PYTHON_VERSION }} -m venv .venv
99-
source .venv/bin/activate
100-
make install
101-
102-
- name: Setup virtual environment (cache hit)
103-
if: steps.virtualenv-cache.outputs.cache-hit == 'true'
104-
run: |
105-
source .venv/bin/activate
106-
pip install --no-deps -e .[all]
107-
108-
- name: Debug info
109-
run: |
110-
source .venv/bin/activate
111-
pip freeze
79+
key: ${{ runner.os }}-pyenv-${{ hashFiles('requirements.txt') }}
80+
restore-keys: |
81+
${{ runner.os }}-pyenv-
11282
113-
- name: ${{ matrix.task.name }}
83+
- name: Install Development Requirements
11484
run: |
85+
python -m venv .venv
11586
source .venv/bin/activate
116-
${{ matrix.task.run }}
117-
118-
- name: Prepare coverage report
119-
if: matrix.task.coverage_report
120-
run: |
121-
mkdir coverage
122-
mv coverage.xml coverage/
123-
124-
- name: Save coverage report
125-
if: matrix.task.coverage_report
126-
uses: actions/upload-artifact@v3
127-
with:
128-
name: ${{ matrix.task.name }}-coverage
129-
path: ./coverage
87+
pip install -r requirements.txt
13088
131-
- name: Clean up
132-
if: always()
89+
- name: Run Tests
13390
run: |
13491
source .venv/bin/activate
135-
pip uninstall --yes arrayfire
92+
make tests
93+

.isort.cfg

Lines changed: 0 additions & 3 deletions
This file was deleted.

Makefile

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,13 @@ endif
1414
version :
1515
@python -c 'from arrayfire.version import VERSION; print(f"ArrayFire Python v{VERSION}")'
1616

17-
.PHONY : install
18-
install :
19-
pip install --upgrade pip
20-
pip install pip-tools
21-
pip-compile requirements.in -o final_requirements.txt --allow-unsafe --rebuild --verbose
22-
pip install -e . -r final_requirements.txt
17+
# Dev
2318

24-
# Testing
25-
26-
.PHONY : flake8
27-
flake8 :
28-
flake8 arrayfire tests examples
19+
.PHONY : pre-commit
20+
pre-commit :
21+
black --check . && isort --check . && flake8 . && mypy . --cache-dir=/dev/null
2922

30-
.PHONY : import-sort
31-
import-sort :
32-
isort arrayfire tests examples
33-
34-
.PHONY : typecheck
35-
typecheck :
36-
mypy arrayfire tests examples --cache-dir=/dev/null
23+
# Testing
3724

3825
.PHONY : tests
3926
tests :

arrayfire/__init__.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"shift",
9696
"tile",
9797
"transpose",
98+
"lookup",
9899
]
99100

100101
from arrayfire.library.array_functions import (
@@ -110,6 +111,7 @@
110111
isnan,
111112
iszero,
112113
join,
114+
lookup,
113115
lower,
114116
moddims,
115117
pad,
@@ -591,27 +593,6 @@
591593

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

594-
# TODO
595-
# Temp solution. Remove when arrayfire-binary-python-wrapper is finalized
596-
597-
# __all__ += [
598-
# "get_active_backend",
599-
# "get_available_backends",
600-
# "get_backend_count",
601-
# "get_backend_id",
602-
# "get_device_id",
603-
# "set_backend",
604-
# ]
605-
606-
# from arrayfire.library.unified_api_functions import (
607-
# get_active_backend,
608-
# get_available_backends,
609-
# get_backend_count,
610-
# get_backend_id,
611-
# get_device_id,
612-
# set_backend,
613-
# )
614-
615596
__all__ += [
616597
"accum",
617598
"scan",

0 commit comments

Comments
 (0)