def _transform(
        self, x: "torch.Tensor", y: "torch.Tensor" | list[dict[str, "torch.Tensor"]] | None, **kwargs
    ) -> tuple["torch.Tensor", "torch.Tensor" | list[dict[str, "torch.Tensor"]] | None]:
        """
        Transformation of an image with randomly sampled zoom blur.

        :param x: Input samples.
        :param y: Label of the samples `x`.
        :return: Transformed samples and labels.
        """
        import torch
        import torchvision

        nb_zooms = 10
        x_blur = torch.zeros_like(x)
        max_zoom_i = np.random.uniform(low=self.zoom_range[0], high=self.zoom_range[1])
        zooms = np.arange(start=1.0, stop=max_zoom_i, step=(max_zoom_i - 1.0) / nb_zooms)

        height = x.shape[1]
        width = x.shape[2]

        x_nchw = x.permute(0, 3, 1, 2)

        for zoom in zooms:
            size = [int(a * zoom) for a in x.shape[1:3]]
            x_resized = torchvision.transforms.functional.resize(
                img=x_nchw, size=size, interpolation=torchvision.transforms.InterpolationMode.BILINEAR
            ).permute(0, 2, 3, 1)

            trim_top = (x_resized.shape[1] - height) // 2
            trim_left = (x_resized.shape[2] - width) // 2

            x_blur += x_resized[0:1, trim_top : trim_top + height, trim_left : trim_left + width, :]

        x_out = (x + x_blur) / (nb_zooms + 1)
        return torch.clamp(x_out, min=self.clip_values[0], max=self.clip_values[1]), y

        Transformation of an image with randomly sampled zoom blur.

        :param x: Input samples.
        :param y: Label of the samples `x`.
        :return: Transformed samples and labels.
        
art/preprocessing/expectation_over_transformation/natural_corruptions/zoom_blur/pytorch.py