Skip to content

bounds.indexing

This module contains functions that wrap out-of-bound indices back in-bounds, according to some boundary condition.

FUNCTION DESCRIPTION
replicate

Apply replicate boundary conditions to an index. Aliases: border, nearest, repeat, edge.

dft

Apply DFT boundary conditions to an index. Aliases: wrap, gridwrap, circular, circulant.

dct1

Apply DCT-I boundary conditions to an index. Alias: mirror

dct2

Apply DCT-II boundary conditions to an index. Aliases: reflect, gridmirror, neumann.

dst1

Apply DST-I boundary conditions to an index. Alias: antimirror

dst2

Apply DST-II boundary conditions to an index. Aliases: antireflect, dirichlet.

nocheck

Do not wrap indices (assume they are inbounds)

nearest module-attribute

nearest = replicate

Alias for replicate

border module-attribute

border = replicate

Alias for replicate

repeat module-attribute

repeat = replicate

Alias for replicate

edge module-attribute

edge = replicate

Alias for replicate

reflect module-attribute

reflect = dct2

Alias for dct2

reflection module-attribute

reflection = dct2

Alias for dct2

gridmirror module-attribute

gridmirror = dct2

Alias for dct2

neumann module-attribute

neumann = dct2

Alias for dct2

mirror module-attribute

mirror = dct1

Alias for dct1

antireflect module-attribute

antireflect = dst2

Alias for dst2

dirichlet module-attribute

dirichlet = dst2

Alias for dst2

antimirror module-attribute

antimirror = dst1

Alias for dst1

wrap module-attribute

wrap = dft

Alias for dft

gridwrap module-attribute

gridwrap = dft

Alias for dft

circular module-attribute

circular = dft

Alias for dft

circulant module-attribute

circulant = dft

Alias for dft

nocheck

nocheck(i, n)

Assume all indices are inbounds

Source code in bounds/indexing.py
def nocheck(i, n):
    """Assume all indices are inbounds"""
    return i, 1

replicate

replicate(i, n)

Apply replicate (nearest/border) boundary conditions to an index

Aliases

border, nearest, repeat

PARAMETER DESCRIPTION
i

Index

TYPE: int or tensor

n

Length of the field of view

TYPE: int

RETURNS DESCRIPTION
i

Index that falls inside the field of view [0, n-1]

TYPE: int or tensor

s

Sign of the transformation (always 1 for replicate)

TYPE: {1, 0, -1}

Source code in bounds/indexing.py
def replicate(i, n):
    """Apply replicate (nearest/border) boundary conditions to an index

    !!! info "Aliases"
        [`border`][bounds.indexing.border],
        [`nearest`][bounds.indexing.nearest],
        [`repeat`][bounds.indexing.repeat]

    Parameters
    ----------
    i : int or tensor
        Index
    n : int
        Length of the field of view

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

    """
    return (replicate_script(i, n) if torch.is_tensor(i) else
            replicate_int(i, n))

dft

dft(i, n)

Apply DFT (circulant/wrap) boundary conditions to an index

Aliases

wrap, circular

PARAMETER DESCRIPTION
i

Index

TYPE: int or tensor

n

Length of the field of view

TYPE: int

RETURNS DESCRIPTION
i

Index that falls inside the field of view [0, n-1]

TYPE: int or tensor

s

Sign of the transformation (always 1 for dft)

TYPE: {1, 0, -1}

Source code in bounds/indexing.py
def dft(i, n):
    """Apply DFT (circulant/wrap) boundary conditions to an index

    !!! info "Aliases"
        [`wrap`][bounds.indexing.wrap],
        [`circular`][bounds.indexing.circular]

    Parameters
    ----------
    i : int or tensor
        Index
    n : int
        Length of the field of view

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

    """
    return dft_script(i, n) if torch.is_tensor(i) else dft_int(i, n)

dct2

dct2(i, n)

Apply DCT-II (reflect) boundary conditions to an index

Aliases

reflect, neumann

PARAMETER DESCRIPTION
i

Index

TYPE: int or tensor

n

Length of the field of view

TYPE: int

RETURNS DESCRIPTION
i

Index that falls inside the field of view [0, n-1]

TYPE: int or tensor

s

Sign of the transformation (always 1 for dct2)

TYPE: {1, 0, -1}

Source code in bounds/indexing.py
def dct2(i, n):
    """Apply DCT-II (reflect) boundary conditions to an index

    !!! info "Aliases"
        [`reflect`][bounds.indexing.reflect],
        [`neumann`][bounds.indexing.neumann]

    Parameters
    ----------
    i : int or tensor
        Index
    n : int
        Length of the field of view

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

    """
    return dct2_script(i, n) if torch.is_tensor(i) else dct2_int(i, n)

dct1

dct1(i, n)

Apply DCT-I (mirror) boundary conditions to an index

Aliases

mirror

PARAMETER DESCRIPTION
i

Index

TYPE: int or tensor

n

Length of the field of view

TYPE: int

RETURNS DESCRIPTION
i

Index that falls inside the field of view [0, n-1]

TYPE: int or tensor

s

Sign of the transformation (always 1 for dct1)

TYPE: {1, 0, -1}

Source code in bounds/indexing.py
def dct1(i, n):
    """Apply DCT-I (mirror) boundary conditions to an index

    !!! info "Aliases"
        [`mirror`][bounds.indexing.mirror]

    Parameters
    ----------
    i : int or tensor
        Index
    n : int
        Length of the field of view

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

    """
    return dct1_script(i, n) if torch.is_tensor(i) else dct1_int(i, n)

dst1

dst1(i, n)

Apply DST-I (antimirror) boundary conditions to an index

Aliases

antimirror

PARAMETER DESCRIPTION
i

Index

TYPE: int or tensor

n

Length of the field of view

TYPE: int

RETURNS DESCRIPTION
i

Index that falls inside the field of view [0, n-1]

TYPE: int or tensor

s

Sign of the transformation

TYPE: [tensor of] {1, 0, -1}

Source code in bounds/indexing.py
def dst1(i, n):
    """Apply DST-I (antimirror) boundary conditions to an index

    !!! info "Aliases"
        [`antimirror`][bounds.indexing.antimirror]

    Parameters
    ----------
    i : int or tensor
        Index
    n : int
        Length of the field of view

    Returns
    -------
    i : int or tensor
        Index that falls inside the field of view [0, n-1]
    s : [tensor of] {1, 0, -1}
        Sign of the transformation

    """
    return dst1_script(i, n) if torch.is_tensor(i) else dst1_int(i, n)

dst2

dst2(i, n)

Apply DST-II (antireflect) boundary conditions to an index

PARAMETER DESCRIPTION
i

Index

TYPE: int or tensor

n

Length of the field of view

TYPE: int

RETURNS DESCRIPTION
i

Index that falls inside the field of view [0, n-1]

TYPE: int or tensor

s

Sign of the transformation (always 1 for dct1)

TYPE: [tensor of] {1, 0, -1}

Source code in bounds/indexing.py
def dst2(i, n):
    """Apply DST-II (antireflect) boundary conditions to an index

    !!! info "Aliases"
        [`antireflect`][bounds.indexing.antireflect],
        [`dirichlet`][bounds.indexing.dirichlet]

    Parameters
    ----------
    i : int or tensor
        Index
    n : int
        Length of the field of view

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

    """
    return dst2_script(i, n) if torch.is_tensor(i) else dst2_int(i, n)