Milestone 2 of 8

Generate and hand-check patch grids

Produce exact row and column origins under drop and pad policies, enumerate row first and column second, and test divisible, uneven, small, narrow, one-pixel, and overlapping cases.

The grid decides which source coordinates exist before any pixels are copied. Write the origins down first, then inspect the resulting order.

Goal

Generate exact row and column origins for drop and pad, enumerate patches in row-major order, and hand-check divisible, non-divisible, small, narrow, one-pixel, and overlapping images.

Grid contract

Let the image shape be (H, W, C), patch shape (PH, PW), and stride (SH, SW). Generate row origins first and column origins second. For each row origin, enumerate all column origins in order. This is row-major patch order.

Under drop, keep origins at 0, stride, ... only while the complete patch fits inside the image. An image smaller than either patch dimension produces no patches.

Under pad, generate each dimension independently with:

origins = [0]
while origins[-1] + patch_size < image_size:
    origins.append(origins[-1] + stride)

Padding occurs only below or to the right. Because stride is no larger than patch size, neighboring padded patches leave no gap.

Deliverables

Implement grid generation in src/grid.py. Save expected row origins, column origins, (top, left) pairs, and per-image patch counts for the tiny fixtures. Record the configured edge policy and order rule.

Checks

Hand-calculate origins for divisible and non-divisible dimensions, a smaller- than-patch image, a one-pixel image, a narrow image, and overlapping strides. Check that drop has only complete origins and pad has one origin at zero even when the image is smaller than the patch.

Check row-major order and deterministic repeated runs. Reject zero or negative dimensions, boolean parameters, strides larger than patch dimensions, rounding, resizing, and accidental column-major enumeration.

Workspace

Keep origin generation and order checks in src/grid.py. Do not copy pixels or build masks until the next milestone.

Hints

HintList rows before pairs
First write the row-origin list and the column-origin list. Then combine them as (top, left) pairs in row-major order.
HintDo not round to fit
A non-divisible image dimension is evidence for the chosen edge policy. It is not a reason to resize the image.

Review

For a 5-by-6 image with a 3-by-4 patch and strides 2 and 3, list the origins by hand under both policies. Which origin is present under pad that cannot produce a complete patch?

How to check your work

Checks compare origins, pair order, counts, and policies with the expected fixtures. The grid is a spatial contract, not an optimization choice.