def replicate(i, n, inplace=False):
    """Apply replicate (nearest/border) boundary conditions to an index

    Parameters
    ----------
    i : int                 Index
    n : int                 Length of the field of view
    inplace : bool, default=False

    Returns
    -------
    i : int                 Index that falls inside the field of view [0, n-1]
    s : {1, -1}             Sign of the transformation (always 1 for replicate)

    """
    return i.clamp_(min=0, max=n-1) if inplace else i.clamp(min=0, max=n-1), 1