def homogenize_points(xy):
    """
    Parameters
    ----------
    xy: Tensor
        xy coordinates. shape=(N, ..., 2)
        E.g., (N, 2) or (N, K, 2) or (N, H, W, 2)

    Returns
    -------
    Tensor:
        1. is appended to the last dimension. shape=(N, ..., 3)
        E.g, (N, 3) or (N, K, 3) or (N, H, W, 3).
    """
    # NOTE: this seems to work for arbitrary number of dimensions of input
    pad = torch.nn.ConstantPad1d(padding=(0, 1), value=1.)
    return pad(xy)

    Parameters
    ----------
    xy: Tensor
        xy coordinates. shape=(N, ..., 2)
        E.g., (N, 2) or (N, K, 2) or (N, H, W, 2)

    Returns
    -------
    Tensor:
        1. is appended to the last dimension. shape=(N, ..., 3)
        E.g, (N, 3) or (N, K, 3) or (N, H, W, 3).
    
tridet/utils/geometry.py