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