bounds.types
This module defines names and aliases for different boundary conditions, as well as tools to convert between different naming conventions.
| CLASS | DESCRIPTION |
|---|---|
BoundType |
Enum type for bounds |
| ATTRIBUTE | DESCRIPTION |
|---|---|
BoundLike |
A type hint for any boundary type
|
SequenceOrScalar |
A type hint for values or sequences of values
|
| FUNCTION | DESCRIPTION |
|---|---|
to_enum |
Convert any boundary type to |
to_int |
Convert any boundary type to |
to_fourier |
Convert any boundary type to discrete transforms |
to_scipy |
Convert any boundary type to |
to_torch |
Convert any boundary type to |
SequenceOrScalar
module-attribute
Either an element or type T, or a sequence of elements of type T.
BoundLike
module-attribute
A boundary mode.
Most conventions are handled (numpy, scipy, torch, see below). Can be one of:
zero,zeros,constantorgridconstant;replicate,nearest,borderoredge;dct1ormirror;dct2,reflect,reflection,gridmirrororneumann;dst1orantimirror;dst2,antireflectordirichlet;dft,fft,wrap,gridwrap,circularorcirculant.
Each of these modes can be a BoundType value
(e.g., BoundType.mirror), or its string representation (e.g., "mirror").
The aliases dft, dct1, dct2, dst1 and dst2 exist because these
boundary modes correspond to the implicit boundary conditions of each of
these frequency transform:
- Discrete Fourier Transform (DFT)
- Discrete Cosine Transform I & II (DCT-I, DCT-II)
- Discrete Sine Transform I & II (DST-I, DST-II)
The reason why so many aliases are supported is that there is no common convention across python packages to name boundary conditions. This table contains an extensive list of aliases:
|
Fourier |
SciPy |
Numpy |
PyTorch |
PyTorch |
Other |
Description |
|---|---|---|---|---|---|---|
|
nearest |
edge |
border |
replicate |
repeat |
|
|
|
constant, |
constant |
constant |
zeros |
zero |
|
|
|
dct1 |
mirror |
reflect |
reflect |
reflection |
|
|
|
dct2 |
reflect, |
symmetric |
reflection |
neumann |
|
|
|
dst1 |
antimirror |
|
||||
|
dst2 |
antireflect, |
|
||||
|
dft |
grid-wrap |
wrap |
circular |
circulant |
|
|
|
wrap |
|
|||||
|
linear_ramp |
||||||
|
minimum, |
Some of these conventions are inconsistant with each other. For example
"wrap" in scipy.ndimage is different from "wrap" in numpy.pad,
which corresponds to "grid-wrap" in scipy.ndimage. Also, "reflect"
in numpy.pad and torch.pad is different from "reflect" in scipy.ndimage,
which correspond to "symmetric" in numpy.pad.
BoundType
Bases: Enum
An Enum type that maps boundry modes of any convention to a unique set of values.
class BoundType(Enum):
zero = zeros = constant = gridconstant = 0
replicate = repeat = nearest = border = edge = 1
dct1 = mirror = 2
dct2 = reflect = reflection = gridmirror = neumann = 3
dst1 = antimirror = 4
dst2 = antireflect = dirichlet = 5
dft = fft = wrap = gridwrap = circular = circulant = 6
nocheck = -1
to_enum
Convert boundary type to enum type.
See also
| PARAMETER | DESCRIPTION |
|---|---|
bound |
Boundary condition in any convention
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bound
|
Boundary condition
TYPE:
|
Source code in bounds/types.py
to_int
Convert boundary type to enum integer.
See also
| PARAMETER | DESCRIPTION |
|---|---|
bound |
Boundary condition in any convention
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bound
|
Boundary condition
TYPE:
|
Source code in bounds/types.py
to_fourier
Convert boundary type to discrete transforms.
| PARAMETER | DESCRIPTION |
|---|---|
bound |
Boundary condition in any convention
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bound
|
Boundary condition in terms of discrete transforms
TYPE:
|
Source code in bounds/types.py
to_scipy
Convert boundary type to SciPy's convention.
See also
| PARAMETER | DESCRIPTION |
|---|---|
bound |
Boundary condition in any convention
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bound
|
Boundary condition in SciPy's convention
TYPE:
|
Source code in bounds/types.py
to_torch
Convert boundary type to PyTorch's convention.
See also
| PARAMETER | DESCRIPTION |
|---|---|
bound |
Boundary condition in any convention
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bound
|
The first element is the boundary condition in PyTorchs's
convention, and the second element is the value of
TYPE:
|