def forward(self, x: "tf.Tensor", y: "tf.Tensor" | None = None) -> tuple["tf.Tensor", "tf.Tensor" | None]:
        """
        Apply transformations to inputs `x` and labels `y`.

        :param x: Input samples.
        :param y: Label of the sample `x`. This function does not modify `y`.
        :return: Corrupted samples and labels.
        """
        import tensorflow as tf

        x_preprocess_list = []
        y_preprocess_list = []

        for i_image in range(x.shape[0]):
            for _ in range(self.nb_samples):
                x_i = x[[i_image]]
                y_i: tf.Tensor | list[dict[str, tf.Tensor]] | None
                if y is not None:
                    if isinstance(y, list):
                        y_i = [y[i_image]]
                    else:
                        y_i = y[[i_image]]
                else:
                    y_i = None
                x_preprocess, y_preprocess_i = self._transform(x_i, y_i)
                x_preprocess_list.append(tf.squeeze(x_preprocess, axis=0))

                if y is not None and y_preprocess_i is not None:
                    y_preprocess_list.append(y_preprocess_i)

        x_preprocess = tf.stack(x_preprocess_list, axis=0)
        if y is None:
            y_preprocess = y
        else:
            if isinstance(y, (tf.Tensor, np.ndarray)):
                y_preprocess = tf.stack(y_preprocess_list, axis=0)
            else:
                y_preprocess = [item for sublist in y_preprocess_list for item in sublist]

        return x_preprocess, y_preprocess

        Apply transformations to inputs `x` and labels `y`.

        :param x: Input samples.
        :param y: Label of the sample `x`. This function does not modify `y`.
        :return: Corrupted samples and labels.
        
art/preprocessing/expectation_over_transformation/tensorflow.py