tidy3d.plugins.autograd.invdes.symmetrize_mirror

tidy3d.plugins.autograd.invdes.symmetrize_mirror#

class symmetrize_mirror[source]#

Bases:

Symmetrizes the parameter array by averaging the mirrored parts of the array. The axis argument specifies the symmetry axis.

Parameters:
  • array (NDArray) – The input array to be symmetrized.

  • axis (int | tuple[int, int]) – The symmetry axis. This can either be a single axis (x=0 or y=1) or a tuple of both axes.

Returns:

The array after applying the mirror symmetrization.

Return type:

NDArray

Example

>>> import autograd.numpy as np
>>> from tidy3d.plugins.autograd.invdes.symmetries import symmetrize_mirror
>>> arr = np.asarray([
...     [1, 2],
...     [3, 4]
... ])
>>> res_x = symmetrize_mirror(arr, axis=0)
>>> res_y = symmetrize_mirror(arr, axis=1)
>>> assert np.all(np.isclose(res_x, np.asarray([
...     [2, 3],
...     [2, 3]
... ])))
>>> assert np.all(np.isclose(res_y, np.asarray([
...     [1.5, 1.5],
...     [3.5, 3.5]
... ])))

Inherited Common Usage