

import unittest

import numpy as np
import PIL
import torch

from diffusers.image_processor import VaeImageProcessor



class 		a_	(							unittest.TestCase					):



      """simple docstring"""







      @property
      def 	_lowerCAmelCase					(				self					:							Optional[Any]    ):
           SCREAMING_SNAKE_CASE										=1
           SCREAMING_SNAKE_CASE										=3
           SCREAMING_SNAKE_CASE										=8
           SCREAMING_SNAKE_CASE										=8

           SCREAMING_SNAKE_CASE										=torch.rand((batch_size, num_channels, height, width)    )

           return sample
      def 	_lowerCAmelCase					(				self					:							Union[str, Any]      ,snake_case					:							List[str]    ):
           if isinstance(image[0]      ,PIL.Image.Image    ):
                return np.stack([np.array(snake_case    ) for i in image]      ,axis=0    )
           elif isinstance(snake_case      ,torch.Tensor    ):
                return image.cpu().numpy().transpose(0      ,2      ,3      ,1    )
           return image
      def 	_lowerCAmelCase					(				self					:							int    ):
           SCREAMING_SNAKE_CASE										=VaeImageProcessor(do_resize=snake_case      ,do_normalize=snake_case    )

           SCREAMING_SNAKE_CASE										=self.dummy_sample
           SCREAMING_SNAKE_CASE										=self.to_np(snake_case    )

           for output_type in ["pt", "np", "pil"]:
                SCREAMING_SNAKE_CASE										=image_processor.postprocess(
                    image_processor.preprocess(snake_case    )      ,output_type=snake_case      ,)
                SCREAMING_SNAKE_CASE										=self.to_np(snake_case    )
                SCREAMING_SNAKE_CASE										=(input_np * 255).round() if output_type == 'pil' else input_np
                assert (
                    np.abs(in_np - out_np    ).max() < 1e-6
                ), f'decoded output does not match input for output_type {output_type}'
      def 	_lowerCAmelCase					(				self					:							Dict    ):
           SCREAMING_SNAKE_CASE										=VaeImageProcessor(do_resize=snake_case      ,do_normalize=snake_case    )
           SCREAMING_SNAKE_CASE										=self.dummy_sample.cpu().numpy().transpose(0      ,2      ,3      ,1    )

           for output_type in ["pt", "np", "pil"]:
                SCREAMING_SNAKE_CASE										=image_processor.postprocess(image_processor.preprocess(snake_case    )      ,output_type=snake_case    )

                SCREAMING_SNAKE_CASE										=self.to_np(snake_case    )
                SCREAMING_SNAKE_CASE										=(input_np * 255).round() if output_type == 'pil' else input_np
                assert (
                    np.abs(in_np - out_np    ).max() < 1e-6
                ), f'decoded output does not match input for output_type {output_type}'
      def 	_lowerCAmelCase					(				self					:							Any    ):
           SCREAMING_SNAKE_CASE										=VaeImageProcessor(do_resize=snake_case      ,do_normalize=snake_case    )

           SCREAMING_SNAKE_CASE										=self.dummy_sample.cpu().numpy().transpose(0      ,2      ,3      ,1    )
           SCREAMING_SNAKE_CASE										=image_processor.numpy_to_pil(snake_case    )

           for output_type in ["pt", "np", "pil"]:
                SCREAMING_SNAKE_CASE										=image_processor.postprocess(image_processor.preprocess(snake_case    )      ,output_type=snake_case    )
                for i, o in zip(snake_case      ,snake_case    ):
                     SCREAMING_SNAKE_CASE										=np.array(snake_case    )
                     SCREAMING_SNAKE_CASE										=self.to_np(snake_case    ) if output_type == 'pil' else (self.to_np(snake_case    ) * 255).round()
                     assert (
                         np.abs(in_np - out_np    ).max() < 1e-6
                     ), f'decoded output does not match input for output_type {output_type}'
      def 	_lowerCAmelCase					(				self					:							Optional[int]    ):
           SCREAMING_SNAKE_CASE										=VaeImageProcessor(do_resize=snake_case      ,do_normalize=snake_case    )

           SCREAMING_SNAKE_CASE										=self.dummy_sample
           SCREAMING_SNAKE_CASE										=input_pt_ad.squeeze(0    )

           SCREAMING_SNAKE_CASE										=image_processor.postprocess(
               image_processor.preprocess(snake_case    )      ,output_type='np'      ,)
           SCREAMING_SNAKE_CASE										=image_processor.postprocess(
               image_processor.preprocess(snake_case    )      ,output_type='np'      ,)

           SCREAMING_SNAKE_CASE										=self.to_np(self.dummy_sample    )
           SCREAMING_SNAKE_CASE										=input_np_ad.squeeze(0    )

           SCREAMING_SNAKE_CASE										=image_processor.postprocess(
               image_processor.preprocess(snake_case    )      ,output_type='np'      ,)
           SCREAMING_SNAKE_CASE										=image_processor.postprocess(
               image_processor.preprocess(snake_case    )      ,output_type='np'      ,)

           assert np.abs(out_pt_ad - out_pt_ad    ).max() < 1e-6
           assert np.abs(out_np_ad - out_np_ad    ).max() < 1e-6


      def 	_lowerCAmelCase					(				self					:							List[Any]    ):
           SCREAMING_SNAKE_CASE										=VaeImageProcessor(do_resize=snake_case      ,do_normalize=snake_case    )

           SCREAMING_SNAKE_CASE										=self.dummy_sample
           SCREAMING_SNAKE_CASE										=list(snake_case    )

           SCREAMING_SNAKE_CASE										=image_processor.postprocess(
               image_processor.preprocess(snake_case    )      ,output_type='np'      ,)

           SCREAMING_SNAKE_CASE										=image_processor.postprocess(
               image_processor.preprocess(snake_case    )      ,output_type='np'      ,)

           SCREAMING_SNAKE_CASE										=self.to_np(self.dummy_sample    )
           list(snake_case    )

           SCREAMING_SNAKE_CASE										=image_processor.postprocess(
               image_processor.preprocess(snake_case    )      ,output_type='np'      ,)

           SCREAMING_SNAKE_CASE										=image_processor.postprocess(
               image_processor.preprocess(snake_case    )      ,output_type='np'      ,)

           assert np.abs(out_pt_ad - out_pt_list    ).max() < 1e-6
           assert np.abs(out_np_ad - out_np_list    ).max() < 1e-6




def       snake_case__    (       lowerCAmelCase_,   lowerCAmelCase_,   lowerCAmelCase_      ):





     """simple docstring"""







     if power < 0:
          return -1
     base %= mod
     SCREAMING_SNAKE_CASE										=1

     while power > 0:
          if power & 1:
               SCREAMING_SNAKE_CASE										=(result * base) % mod
          SCREAMING_SNAKE_CASE										=power >> 1
          SCREAMING_SNAKE_CASE										=(base * base) % mod

     return result







def       snake_case__    (       ):





     """simple docstring"""







     print(modular_exponential(3,   200,   13      )      )


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 main()

