def forward(
        self, x: "torch.Tensor", y: "torch.Tensor" | None = None
    ) -> tuple["torch.Tensor", "torch.Tensor" | None]:
        """
        Apply Cutout data augmentation to sample `x`.

        :param x: Sample to cut out with shape of `NCHW`, `NHWC`, `NCFHW` or `NFHWC`.
                  `x` values are expected to be in the data range [0, 1] or [0, 255].
        :param y: Labels of the sample `x`. This function does not affect them in any way.
        :return: Data augmented sample.
        """
        import torch  # lgtm [py/repeated-import]

        x_ndim = len(x.shape)

        # NHWC/NCFHW/NFHWC --> NCHW.
        if x_ndim == 4:
            if self.channels_first:
                # NCHW
                x_nchw = x
            else:
                # NHWC --> NCHW
                x_nchw = x.permute(0, 3, 1, 2)
        elif x_ndim == 5:
            if self.channels_first:
                # NCFHW --> NFCHW --> NCHW
                nb_clips, channels, clip_size, height, width = x.shape
                x_nchw = x.permute(0, 2, 1, 3, 4).reshape(nb_clips * clip_size, channels, height, width)
            else:
                # NFHWC --> NHWC --> NCHW
                nb_clips, clip_size, height, width, channels = x.shape
                x_nchw = x.reshape(nb_clips * clip_size, height, width, channels).permute(0, 3, 1, 2)
        else:
            raise ValueError("Unrecognized input dimension. Cutout can only be applied to image and video data.")

        n, _, height, width = x_nchw.shape
        x_nchw = x_nchw.clone()

        # generate a random bounding box per image
        for idx in trange(n, desc="Cutout", disable=not self.verbose):
            # uniform sampling
            center_x = torch.randint(0, height, (1,))
            center_y = torch.randint(0, width, (1,))
            bby1 = torch.clamp(center_y - self.length // 2, 0, height)
            bbx1 = torch.clamp(center_x - self.length // 2, 0, width)
            bby2 = torch.clamp(center_y + self.length // 2, 0, height)
            bbx2 = torch.clamp(center_x + self.length // 2, 0, width)

            # zero out the bounding box
            x_nchw[idx, :, bbx1:bbx2, bby1:bby2] = 0  # type: ignore

        # NHWC/NCFHW/NFHWC <-- NCHW.
        if x_ndim == 4:
            if self.channels_first:
                # NCHW
                x_aug = x_nchw
            else:
                # NHWC <-- NCHW
                x_aug = x_nchw.permute(0, 2, 3, 1)
        elif x_ndim == 5:  # lgtm [py/redundant-comparison]
            if self.channels_first:
                # NCFHW <-- NFCHW <-- NCHW
                x_nfchw = x_nchw.reshape(nb_clips, clip_size, channels, height, width)
                x_aug = x_nfchw.permute(0, 2, 1, 3, 4)
            else:
                # NFHWC <-- NHWC <-- NCHW
                x_nhwc = x_nchw.permute(0, 2, 3, 1)
                x_aug = x_nhwc.reshape(nb_clips, clip_size, height, width, channels)

        return x_aug, y

        Apply Cutout data augmentation to sample `x`.

        :param x: Sample to cut out with shape of `NCHW`, `NHWC`, `NCFHW` or `NFHWC`.
                  `x` values are expected to be in the data range [0, 1] or [0, 255].
        :param y: Labels of the sample `x`. This function does not affect them in any way.
        :return: Data augmented sample.
        
art/defences/preprocessor/cutout/cutout_pytorch.py