tidy3d.plugins.autograd.functions.pad

Contents

tidy3d.plugins.autograd.functions.pad#

class pad[source]#

Bases:

Pad an array along a specified axis with a given mode and padding width.

Parameters:
  • array (NDArray) โ€“ The input array to pad.

  • pad_width (Union[int, Tuple[int, int]]) โ€“ The number of values padded to the edges of each axis. If an integer is provided, it is used for both the left and right sides. If a tuple is provided, it specifies the padding for the left and right sides respectively.

  • mode (_pad_modes, optional) โ€“ The padding mode to use. Default is โ€œconstantโ€.

  • axis (Union[int, Iterable[int], None], optional) โ€“ The axis or axes along which to pad. If None, padding is applied to all axes. Default is None.

  • constant_value (float, optional) โ€“ The value to set the padded values for โ€œconstantโ€ mode. Default is 0.0.

Returns:

The padded array.

Return type:

NDArray

Raises:
  • ValueError โ€“ If the padding width has more than two elements or if padding is negative.

  • NotImplementedError โ€“ If padding larger than the input size is requested.

  • KeyError โ€“ If an unsupported padding mode is specified.

  • IndexError โ€“ If an axis is out of range for the array dimensions.

Examples

>>> import numpy as np
>>> from tidy3d.plugins.autograd.functions import pad
>>> array = np.array([[1, 2], [3, 4]])
>>> pad(array, (1, 1), mode="constant", constant_value=0)
array([[0, 0, 0, 0],
       [0, 1, 2, 0],
       [0, 3, 4, 0],
       [0, 0, 0, 0]])
>>> pad(array, 1, mode="reflect")
array([[4, 3, 4, 3],
       [2, 1, 2, 1],
       [4, 3, 4, 3],
       [2, 1, 2, 1]])

Inherited Common Usage