Skip to content

Commit 19f34ea

Browse files
committed
remove scipy dependency from benchmarking, as that's hammering builds
1 parent a767f74 commit 19f34ea

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

pyproject.toml

+4-8
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@ write_to = "src/qoi/_version.py"
1313
write_to_template = "__version__ = \"{version}\""
1414

1515
[tool.cibuildwheel]
16-
test-requires = "pytest scikit-image"
16+
test-requires = "pytest"
1717
test-command = "pytest {project}/tests"
1818
build = "cp37-* cp38-* cp39-* cp310-*"
19-
# arm64 is experimental on windows apparently, skip musl, and cp310-win32 fails so ignore for now, and ignore the non-standard linux builds (as they slow it down a lot!)
20-
skip = "*win_arm64* *-musllinux_* *s390x* *ppc64le* *aarch64* *i686*"
19+
# skip musl and ignore the non-standard linux builds
20+
skip = "*-musllinux_* *s390x* *ppc64le*"
2121
build-frontend = "build"
2222
environment = "USE_CYTHON=1"
23-
build-verbosity = 3
24-
25-
[tool.cibuildwheel.linux]
26-
# Install stuff for scipy:
27-
before-all = "apt-get -y install gfortran libopenblas-dev liblapack-dev || yum -y install blas-devel lapack-devel"
23+
build-verbosity = 3

src/qoi/benchmark.py

+26-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typing import List, OrderedDict
88

99
import numpy as np
10-
from skimage.metrics import structural_similarity
1110

1211
import qoi
1312

@@ -17,7 +16,12 @@
1716

1817
OPENCV_AVAILABLE = True
1918
except ImportError:
20-
warnings.warn("Couldn't find OpenCV - you can still run this, but OpenCV tests will be disabled.")
19+
warnings.warn(
20+
(
21+
"Couldn't find OpenCV - you can still run this, but OpenCV tests/functionality will be disabled, including"
22+
" lossy qoi (which uses OpenCV to resize the image)"
23+
)
24+
)
2125

2226
PIL_AVAILABLE = False
2327
try:
@@ -27,6 +31,18 @@
2731
except ImportError:
2832
warnings.warn("Couldn't find PIL - you can still run this, but PIL tests will be disabled.")
2933

34+
try:
35+
from skimage.metrics import structural_similarity as img_similarity
36+
37+
similarity_name = "SSIM"
38+
except ImportError:
39+
warnings.warn("Couldn't find skimage.metrics.structural_similarity so using MSE.")
40+
41+
def img_similarity(a, b, channel_axis=None):
42+
return ((a - b) ** 2).mean()
43+
44+
similarity_name = "MSE"
45+
3046

3147
@dataclass
3248
class TestResult:
@@ -37,7 +53,7 @@ class TestResult:
3753
encode_ms: float
3854
encode_size: float
3955
decode_ms: float
40-
ssim: float
56+
img_similarity: float
4157

4258

4359
def timeit(f, warmup=3, tests=10):
@@ -61,7 +77,7 @@ def bench_qoi(rgb, test_name, warmup=3, tests=10):
6177
encode_ms=encode_ms,
6278
encode_size=len(bites),
6379
decode_ms=decode_ms,
64-
ssim=structural_similarity(rgb, decoded, channel_axis=2),
80+
img_similarity=img_similarity(rgb, decoded, channel_axis=2),
6581
)
6682

6783

@@ -83,7 +99,7 @@ def decode():
8399
encode_ms=encode_ms,
84100
encode_size=len(bites),
85101
decode_ms=decode_ms,
86-
ssim=structural_similarity(rgb, decoded, channel_axis=2),
102+
img_similarity=img_similarity(rgb, decoded, channel_axis=2),
87103
)
88104

89105

@@ -124,7 +140,7 @@ def encode():
124140
encode_ms=encode_ms,
125141
encode_size=len(bites),
126142
decode_ms=decode_ms,
127-
ssim=structural_similarity(rgb, decoded, channel_axis=2),
143+
img_similarity=img_similarity(rgb, decoded, channel_axis=2),
128144
)
129145

130146

@@ -161,7 +177,7 @@ def encode():
161177
encode_ms=encode_ms,
162178
encode_size=len(bites),
163179
decode_ms=decode_ms,
164-
ssim=structural_similarity(rgb, decoded, channel_axis=2),
180+
img_similarity=img_similarity(rgb, decoded, channel_axis=2),
165181
)
166182

167183

@@ -185,7 +201,7 @@ def bench_methods(
185201
)
186202
if qoi and (implementations is None or "qoi" in implementations):
187203
yield from bench_qoi(rgb, test_name=name, warmup=warmup, tests=tests)
188-
if qoi and (implementations is None or "qoi-lossy" in implementations):
204+
if qoi and (implementations is None or "qoi-lossy" in implementations) and OPENCV_AVAILABLE:
189205
yield from bench_qoi_lossy(rgb, test_name=name, warmup=warmup, tests=tests, scale=qoi_lossy_scale)
190206

191207

@@ -202,7 +218,7 @@ def totable(results: List[TestResult]):
202218
encode_ms="Encode (ms)",
203219
encode_size="Encode (kb)",
204220
decode_ms="Decode (ms)",
205-
ssim="SSIM",
221+
img_similarity=similarity_name,
206222
)
207223

208224
# Convert to dicts of strings
@@ -212,7 +228,7 @@ def totable(results: List[TestResult]):
212228
for k in fields(res):
213229
name = k.name
214230
v = getattr(res, name)
215-
if name == "ssim" or name.endswith("_ms"):
231+
if name == "img_similarity" or name.endswith("_ms"):
216232
v = f"{v:.2f}"
217233
elif name.endswith("_size"):
218234
v = f"{v/1024:.1f}"

0 commit comments

Comments
 (0)