util.py

Collection of utility routines.

class util.ExtractUnitCell2d
__init__()

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'util'
extra_repr()

Displays some of the information associated with the module.

forward(input)

Computes the periodic padding of the input.

class util.ExtractUnitCell2dFunc

Extracts the 2d unit cell from periodic tiling.

__module__ = 'util'
static backward(ctx, grad_output)

Compute df/dx from df/dy using the Chain Rule df/dx = df/dx*dy/dx. For periodic padding we use df/dx = sum_{y_i ~ x} df/dy_i, where the y_i ~ x are all points y_i that are equivalent to x under the periodic extension.

For extracting from periodic tiling the unit cell, the derivatives dy/dx are zero unless x is within the unit cell. The block matrix is dy/dx = [[Z,Z,Z],[Z,W,Z],[Z,Z,Z]], where W is the derivative values in the unit cell (df/dy) and Z is the zero matrix.

static forward(ctx, input, pad=None)

Extracts the 2d unit cell from periodic tiling.

Parameters

input (Tensor) – Tensor of size [nbatch,nchannel,nx,ny] or [nx,ny].

Returns

The Tensor of size [nbatch,nchannel,nx/3,ny/3] or [nx/3,ny/3].

Return type

Tensor

class util.PeriodicPad2d(flag_coords=False)
__init__(flag_coords=False)

Setup for computing the periodic tiling.

__module__ = 'util'
extra_repr()

Displays some of the information associated with the module.

forward(input)

Compute the periodic padding of the input.

class util.PeriodicPad2dFunc

Performs periodic padding/tiling of a 2d lattice.

__module__ = 'util'
static backward(ctx, grad_output)

Compute df/dx from df/dy using the Chain Rule df/dx = df/dx*dy/dx. For periodic padding we use df/dx = sum_{y_i ~ x} df/dy_i, where the y_i ~ x are all points y_i that are equivalent to x under the periodic extension.

static forward(ctx, input, pad=None, flag_coords=False)

Periodically tiles the input into a 2d array for 3x3 repeat pattern. This allows for a quick way for handling periodic boundary conditions on the units cell.

Parameters
  • input (Tensor) – A tensor of size [nbatch,nchannel,nx,ny] or [nx,ny].

  • pad (float) – The pad value to use.

  • flag_coord (bool) – If beginning components are coordinates (x,y,z,…,u).

We then adjust (x,y,u) –> (x + i, y + j, u) for image (i,j).

Returns

A tensor of the same size [nbatch,nchannel,3*nx,3*ny] or [3*nx,3*ny].

Return type

output (Tensor)