This document is relevant for: Trn2, Trn3

Pad Kernel API Reference#

Pad a tensor with constant, replicate, reflect, or circular mode.

Equivalent to torch.nn.functional.pad(x, padding, mode=mode, value=value).

Background#

The pad kernel pads a tensor using one of four modes: constant, replicate, reflect, or circular. It follows PyTorch’s torch.nn.functional.pad semantics with innermost-first padding specification.

API Reference#

Source code for this kernel API can be found at: pad.py

pad#

nkilib.experimental.pad.pad(x_ref, padding, mode='replicate', value=0)#

Pad a tensor with constant, replicate, reflect, or circular mode.

Parameters:
  • x_ref – Input tensor (any number of batch dims + up to 3 spatial dims).

  • padding – Padding amounts in PyTorch convention (innermost-first).

  • mode"constant", "replicate", "reflect", or "circular".

  • value – Fill value for constant mode (default 0, ignored for other modes).

This document is relevant for: Trn2, Trn3