import torch


def uniformly_spaced_samples(shape,
                             xlim,
                             ylim,
                             include_boundary=(False, False)):
    """
    Provides a set of samples in 2D such that all samples are evenly spaced between each other and (optionally) the image boundaries in each dimension
    """
    H, W = shape
    xmin, xmax = xlim
    ymin, ymax = ylim
    include_boundary_x, include_boundary_y = include_boundary
    if not include_boundary_x:
        x = torch.linspace(xmin, xmax, steps=W + 2)[1:-1]
    else:
        x = torch.linspace(xmin, xmax, steps=W)
    if not include_boundary_y:
        y = torch.linspace(ymin, ymax, steps=H + 2)[1:-1]
    else:
        y = torch.linspace(ymin, ymax, steps=H)
    x = x.view(1, -1).expand(H, -1)
    y = y.view(-1, 1).expand(-1, W)
    return x, y