Skip to content

Commit c629bd5

Browse files
committed
ruff format
1 parent 36824d1 commit c629bd5

File tree

10 files changed

+57
-42
lines changed

10 files changed

+57
-42
lines changed

example/dataset_statistics_demo.ipynb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,14 @@
329329
"source": [
330330
"# compute dataset statistics on all samples\n",
331331
"# (in this case we should really use the non-overlapping tiles as samples in dataset_for_initial_statistics)\n",
332-
"with create_prediction_pipeline(\n",
333-
" bioimageio_model=model_resource,\n",
334-
" dataset_for_initial_statistics=dataset,\n",
335-
" update_dataset_stats_for_n_samples=0, # if you call the prediciton pipeline more then len(dataset)\n",
336-
" # times you might want to set this to zero to avoid further updates to the dataset statistics\n",
337-
") as pp:\n",
332+
"with (\n",
333+
" create_prediction_pipeline(\n",
334+
" bioimageio_model=model_resource,\n",
335+
" dataset_for_initial_statistics=dataset,\n",
336+
" update_dataset_stats_for_n_samples=0, # if you call the prediciton pipeline more then len(dataset)\n",
337+
" # times you might want to set this to zero to avoid further updates to the dataset statistics\n",
338+
" ) as pp\n",
339+
"):\n",
338340
" only_init_dataset_stats = process_dataset(pp, dataset)"
339341
]
340342
},

example/model_usage.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
" Mapping[str, NDArray[Any]], Mapping[TensorId, Union[Tensor, NDArray[Any]]]\n",
112112
" ],\n",
113113
") -> None:\n",
114-
"\n",
115114
" for title, image in images.items():\n",
116115
" if isinstance(image, Tensor):\n",
117116
" input_array = image.data.data\n",

src/bioimageio/core/_magic_tensor_ops.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ def __ge__(self, other: _Compatible) -> Self:
7171

7272
def __eq__(self, other: _Compatible) -> Self: # type: ignore[override]
7373
return self._binary_op(
74-
other, nputils.array_eq # pyright: ignore[reportUnknownArgumentType]
74+
other,
75+
nputils.array_eq, # pyright: ignore[reportUnknownArgumentType]
7576
)
7677

7778
def __ne__(self, other: _Compatible) -> Self: # type: ignore[override]
7879
return self._binary_op(
79-
other, nputils.array_ne # pyright: ignore[reportUnknownArgumentType]
80+
other,
81+
nputils.array_ne, # pyright: ignore[reportUnknownArgumentType]
8082
)
8183

8284
# When __eq__ is defined but __hash__ is not, then an object is unhashable,
@@ -171,22 +173,30 @@ def __invert__(self) -> Self:
171173

172174
def round(self, *args: Any, **kwargs: Any) -> Self:
173175
return self._unary_op(
174-
ops.round_, *args, **kwargs # pyright: ignore[reportUnknownArgumentType]
176+
ops.round_,
177+
*args,
178+
**kwargs, # pyright: ignore[reportUnknownArgumentType]
175179
)
176180

177181
def argsort(self, *args: Any, **kwargs: Any) -> Self:
178182
return self._unary_op(
179-
ops.argsort, *args, **kwargs # pyright: ignore[reportUnknownArgumentType]
183+
ops.argsort,
184+
*args,
185+
**kwargs, # pyright: ignore[reportUnknownArgumentType]
180186
)
181187

182188
def conj(self, *args: Any, **kwargs: Any) -> Self:
183189
return self._unary_op(
184-
ops.conj, *args, **kwargs # pyright: ignore[reportUnknownArgumentType]
190+
ops.conj,
191+
*args,
192+
**kwargs, # pyright: ignore[reportUnknownArgumentType]
185193
)
186194

187195
def conjugate(self, *args: Any, **kwargs: Any) -> Self:
188196
return self._unary_op(
189-
ops.conjugate, *args, **kwargs # pyright: ignore[reportUnknownArgumentType]
197+
ops.conjugate,
198+
*args,
199+
**kwargs, # pyright: ignore[reportUnknownArgumentType]
190200
)
191201

192202
__add__.__doc__ = operator.add.__doc__

src/bioimageio/core/backends/torchscript_backend.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def __init__(
4444
def _forward_impl(
4545
self, input_arrays: Sequence[Optional[NDArray[Any]]]
4646
) -> List[Optional[NDArray[Any]]]:
47-
4847
with torch.no_grad():
4948
torch_tensor = [
5049
None if a is None else torch.from_numpy(a).to(self.devices[0])
@@ -60,7 +59,9 @@ def _forward_impl(
6059
(
6160
None
6261
if r is None
63-
else r.cpu().numpy() if isinstance(r, torch.Tensor) else r
62+
else r.cpu().numpy()
63+
if isinstance(r, torch.Tensor)
64+
else r
6465
)
6566
for r in output_seq
6667
]

src/bioimageio/core/block_meta.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ def __post_init__(self):
198198
if not isinstance(self.halo, Frozen):
199199
object.__setattr__(self, "halo", Frozen(self.halo))
200200

201-
assert all(
202-
a in self.sample_shape for a in self.inner_slice
203-
), "block has axes not present in sample"
201+
assert all(a in self.sample_shape for a in self.inner_slice), (
202+
"block has axes not present in sample"
203+
)
204204

205-
assert all(
206-
a in self.inner_slice for a in self.halo
207-
), "halo has axes not present in block"
205+
assert all(a in self.inner_slice for a in self.halo), (
206+
"halo has axes not present in block"
207+
)
208208

209209
if any(s > self.sample_shape[a] for a, s in self.shape.items()):
210210
logger.warning(
@@ -343,9 +343,9 @@ def split_multiple_shapes_into_blocks(
343343
if strides is None:
344344
strides = {}
345345

346-
assert not (
347-
unknown_block := [t for t in strides if t not in block_shapes]
348-
), f"`stride` specified for tensors without block shape: {unknown_block}"
346+
assert not (unknown_block := [t for t in strides if t not in block_shapes]), (
347+
f"`stride` specified for tensors without block shape: {unknown_block}"
348+
)
349349

350350
blocks: Dict[MemberId, Iterable[BlockMeta]] = {}
351351
n_blocks: Dict[MemberId, TotalNumberOfBlocks] = {}

src/bioimageio/core/proc_ops.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ class Clip(_SimpleOperator):
237237

238238
def __post_init__(self):
239239
assert self.min is not None or self.max is not None, "missing min or max value"
240-
assert (
241-
self.min is None or self.max is None or self.min < self.max
242-
), f"expected min < max, but {self.min} !< {self.max}"
240+
assert self.min is None or self.max is None or self.min < self.max, (
241+
f"expected min < max, but {self.min} !< {self.max}"
242+
)
243243

244244
def _apply(self, x: Tensor, stat: Stat) -> Tensor:
245245
return x.clip(self.min, self.max)
@@ -321,9 +321,9 @@ def from_proc_descr(
321321
gain = xr.DataArray(np.atleast_1d(kwargs.gain), dims=axis)
322322
offset = xr.DataArray(np.atleast_1d(kwargs.offset), dims=axis)
323323
else:
324-
assert (
325-
isinstance(kwargs.gain, (float, int)) or len(kwargs.gain) == 1
326-
), kwargs.gain
324+
assert isinstance(kwargs.gain, (float, int)) or len(kwargs.gain) == 1, (
325+
kwargs.gain
326+
)
327327
gain = (
328328
kwargs.gain if isinstance(kwargs.gain, (float, int)) else kwargs.gain[0]
329329
)

src/bioimageio/core/sample.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ def split_into_blocks(
7676
pad_mode: PadMode,
7777
broadcast: bool = False,
7878
) -> Tuple[TotalNumberOfBlocks, Iterable[SampleBlockWithOrigin]]:
79-
assert not (
80-
missing := [m for m in block_shapes if m not in self.members]
81-
), f"`block_shapes` specified for unknown members: {missing}"
82-
assert not (
83-
missing := [m for m in halo if m not in block_shapes]
84-
), f"`halo` specified for members without `block_shape`: {missing}"
79+
assert not (missing := [m for m in block_shapes if m not in self.members]), (
80+
f"`block_shapes` specified for unknown members: {missing}"
81+
)
82+
assert not (missing := [m for m in halo if m not in block_shapes]), (
83+
f"`halo` specified for members without `block_shape`: {missing}"
84+
)
8585

8686
n_blocks, blocks = split_multiple_shapes_into_blocks(
8787
shapes=self.shape,

tests/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@
129129
KERAS_MODELS = (
130130
[]
131131
if keras is None
132-
else ["unet2d_keras"] if tf_major_version == 1 else ["unet2d_keras_tf2"]
132+
else ["unet2d_keras"]
133+
if tf_major_version == 1
134+
else ["unet2d_keras_tf2"]
133135
)
134136
TENSORFLOW_JS_MODELS: List[str] = [] # TODO: add a tensorflow_js example model
135137

@@ -230,7 +232,9 @@ def convert_to_onnx(request: FixtureRequest):
230232
params=(
231233
[]
232234
if tf_major_version is None
233-
else ["unet2d_keras"] if tf_major_version == 1 else ["unet2d_keras_tf2"]
235+
else ["unet2d_keras"]
236+
if tf_major_version == 1
237+
else ["unet2d_keras_tf2"]
234238
)
235239
)
236240
def unet2d_keras(request: FixtureRequest):

tests/test_prediction_pipeline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def _test_prediction_pipeline(
1818
)
1919

2020
bio_model = load_description(model_package)
21-
assert isinstance(
22-
bio_model, (ModelDescr, ModelDescr04)
23-
), bio_model.validation_summary.format()
21+
assert isinstance(bio_model, (ModelDescr, ModelDescr04)), (
22+
bio_model.validation_summary.format()
23+
)
2424
pp = create_prediction_pipeline(
2525
bioimageio_model=bio_model, weight_format=weights_format
2626
)

tests/test_tensor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
],
2424
)
2525
def test_transpose_tensor_2d(axes: Sequence[str]):
26-
2726
tensor = Tensor.from_numpy(np.random.rand(256, 256), dims=None)
2827
transposed = tensor.transpose([AxisId(a) for a in axes])
2928
assert transposed.ndim == len(axes)

0 commit comments

Comments
 (0)