Skip to content

Commit

Permalink
Added support for Neon instructions in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cykooz committed May 15, 2024
1 parent 2475c31 commit f026ff5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
18 changes: 8 additions & 10 deletions tests/test_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
Checksum(1091845751, 1090022383, 1061212976, 2282335752),
),
(CpuExtensions.avx2, Checksum(1091845751, 1090022383, 1061212976, 2282335752)),
(CpuExtensions.neon, Checksum(1091845751, 1090022383, 1061212976, 2282335752)),
],
ids=[
'wo forced SIMD',
'sse4.1',
'avx2',
'neon',
],
)
@pytest.mark.parametrize(
Expand All @@ -43,12 +45,9 @@ def test_multiply_alpha_pil(
checksum: int,
):
mul_div = AlphaMulDiv()
if (
cpu_extensions == CpuExtensions.avx2
and mul_div.cpu_extensions != CpuExtensions.avx2
):
raise pytest.skip('AVX2 instruction not supported by CPU')
mul_div.cpu_extensions = cpu_extensions
if mul_div.cpu_extensions != cpu_extensions:
raise pytest.skip(f'{cpu_extensions} instruction not supported by CPU')

image = source_image.copy()
assert get_image_checksum(image.tobytes('raw')) == Checksum(
Expand Down Expand Up @@ -81,11 +80,13 @@ def test_multiply_alpha_pil(
Checksum(1093712480, 1091645363, 1062623655, 2282335752),
),
(CpuExtensions.avx2, Checksum(1093712480, 1091645363, 1062623655, 2282335752)),
(CpuExtensions.neon, Checksum(1093712480, 1091645363, 1062623655, 2282335752)),
],
ids=[
'wo forced SIMD',
'sse4.1',
'avx2',
'neon',
],
)
@pytest.mark.parametrize(
Expand All @@ -103,12 +104,9 @@ def test_divide_alpha_pil(
checksum: int,
):
mul_div = AlphaMulDiv()
if (
cpu_extensions == CpuExtensions.avx2
and mul_div.cpu_extensions != CpuExtensions.avx2
):
raise pytest.skip('AVX2 instruction not supported by CPU')
mul_div.cpu_extensions = cpu_extensions
if mul_div.cpu_extensions != cpu_extensions:
raise pytest.skip(f'{cpu_extensions} instruction not supported by CPU')

image = source_image.copy()
if image.mode != 'RGBa':
Expand Down
16 changes: 6 additions & 10 deletions tests/test_resizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ def test_resizer_cpu_extensions():
(CpuExtensions.none, Checksum(3037693, 3015698, 2922607, 6122718)),
(CpuExtensions.sse4_1, Checksum(3037693, 3015698, 2922607, 6122718)),
(CpuExtensions.avx2, Checksum(3037693, 3015698, 2922607, 6122718)),
(CpuExtensions.neon, Checksum(3037693, 3015698, 2922607, 6122718)),
],
ids=[
'wo forced SIMD',
'sse4.1',
'avx2',
'neon',
],
)
@pytest.mark.parametrize(
Expand Down Expand Up @@ -90,12 +92,9 @@ def _resize_raw(
assert get_image_checksum(dst_image.get_buffer()) == Checksum(0, 0, 0, 0)

resizer = Resizer()
if (
cpu_extensions == CpuExtensions.avx2
and resizer.cpu_extensions != CpuExtensions.avx2
):
raise pytest.skip('AVX2 instruction not supported by CPU')
resizer.cpu_extensions = cpu_extensions
if resizer.cpu_extensions != cpu_extensions:
raise pytest.skip(f'{cpu_extensions} instruction not supported by CPU')

resizer.resize(
src_image,
Expand Down Expand Up @@ -123,12 +122,9 @@ def _resize_pil(
assert get_image_checksum(dst_image.tobytes('raw')) == Checksum(0, 0, 0, 0)

resizer = Resizer()
if (
cpu_extensions == CpuExtensions.avx2
and resizer.cpu_extensions != CpuExtensions.avx2
):
raise pytest.skip('AVX2 instruction not supported by CPU')
resizer.cpu_extensions = cpu_extensions
if resizer.cpu_extensions != cpu_extensions:
raise pytest.skip(f'{cpu_extensions} instruction not supported by CPU')

resizer.resize_pil(
src_image,
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def print_table(self):


def save_result(image: Image.Image, rel_path: Path, file_name):
if not os.environ.get('DONT_SAVE_RESULT', ''):
if os.environ.get('SAVE_RESULT', ''):
data_dir = Path(__file__).parent / 'data'
result_dir = data_dir / 'result' / rel_path
result_dir.mkdir(parents=True, exist_ok=True)
Expand Down

0 comments on commit f026ff5

Please sign in to comment.