Guard against divide by zero and out-of-bounds

pull/4722/head
awsr 2026-03-29 01:25:22 -07:00
parent eeb9b6291b
commit 59b9ca50ee
No known key found for this signature in database
1 changed files with 2 additions and 2 deletions

View File

@ -51,9 +51,9 @@ def get_grid_size(imgs: list, batch_size=1, rows: int | None = None, cols: int |
return rows_int, cols_int
# Set limits
if rows is not None:
rows_int = min(rows, len(imgs))
rows_int = max(min(rows, len(imgs)), 1)
if cols is not None:
cols_int = min(cols, len(imgs))
cols_int = max(min(cols, len(imgs)), 1)
# Calculate
if rows is None:
rows_int = math.ceil(len(imgs) / cols_int)