

"""simple docstring"""
import unittest

import numpy as np
import PIL
import torch

from diffusers.image_processor import VaeImageProcessor

class        _UpperCamelCase	(						unittest.TestCase	):


  """simple docstring"""





  @property
  def 							_UpperCAmelCase      ( self					: Optional[Any]      )	->			Any:


         '''simple docstring'''





         __magic_name__			:		str        =     1
         __magic_name__			:		List[str]        =     3
         __magic_name__			:		str        =     8
         __magic_name__			:		Union[str, Any]        =     8

         __magic_name__			:		Dict        =     torch.rand((batch_size, num_channels, height, width)      )

         return sample



  def 							_UpperCAmelCase      ( self					: Optional[Any]       ,       snake_case					: str      )	->			List[Any]:


         '''simple docstring'''





         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 							_UpperCAmelCase      ( self					: List[Any]      )	->			Tuple:


         '''simple docstring'''





         __magic_name__			:		List[Any]        =     VaeImageProcessor(do_resize=snake_case       ,       do_normalize=snake_case      )

         __magic_name__			:		Optional[Any]        =     self.dummy_sample
         __magic_name__			:		Union[str, Any]        =     self.to_np(snake_case      )

         for output_type in ["pt", "np", "pil"]:
                __magic_name__			:		str        =     image_processor.postprocess(
                    image_processor.preprocess(snake_case      )       ,       output_type=snake_case       ,       )
                __magic_name__			:		Tuple        =     self.to_np(snake_case      )
                __magic_name__			:		Dict        =     (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 							_UpperCAmelCase      ( self					: Any      )	->			Dict:


         '''simple docstring'''





         __magic_name__			:		Tuple        =     VaeImageProcessor(do_resize=snake_case       ,       do_normalize=snake_case      )
         __magic_name__			:		Any        =     self.dummy_sample.cpu().numpy().transpose(0       ,       2       ,       3       ,       1      )

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

                __magic_name__			:		int        =     self.to_np(snake_case      )
                __magic_name__			:		List[Any]        =     (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 							_UpperCAmelCase      ( self					: Any      )	->			str:


         '''simple docstring'''





         __magic_name__			:		str        =     VaeImageProcessor(do_resize=snake_case       ,       do_normalize=snake_case      )

         __magic_name__			:		List[Any]        =     self.dummy_sample.cpu().numpy().transpose(0       ,       2       ,       3       ,       1      )
         __magic_name__			:		List[Any]        =     image_processor.numpy_to_pil(snake_case      )

         for output_type in ["pt", "np", "pil"]:
                __magic_name__			:		int        =     image_processor.postprocess(image_processor.preprocess(snake_case      )       ,       output_type=snake_case      )
                for i, o in zip(snake_case       ,       snake_case      ):
                       __magic_name__			:		Tuple        =     np.array(snake_case      )
                       __magic_name__			:		List[Any]        =     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 							_UpperCAmelCase      ( self					: Union[str, Any]      )	->			str:


         '''simple docstring'''





         __magic_name__			:		List[Any]        =     VaeImageProcessor(do_resize=snake_case       ,       do_normalize=snake_case      )

         __magic_name__			:		Optional[Any]        =     self.dummy_sample
         __magic_name__			:		int        =     input_pt_ad.squeeze(0      )

         __magic_name__			:		Dict        =     image_processor.postprocess(
             image_processor.preprocess(snake_case      )       ,       output_type='''np'''       ,       )
         __magic_name__			:		List[Any]        =     image_processor.postprocess(
             image_processor.preprocess(snake_case      )       ,       output_type='''np'''       ,       )

         __magic_name__			:		str        =     self.to_np(self.dummy_sample      )
         __magic_name__			:		Dict        =     input_np_ad.squeeze(0      )

         __magic_name__			:		Any        =     image_processor.postprocess(
             image_processor.preprocess(snake_case      )       ,       output_type='''np'''       ,       )
         __magic_name__			:		Optional[Any]        =     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 							_UpperCAmelCase      ( self					: Optional[int]      )	->			Any:


         '''simple docstring'''





         __magic_name__			:		Any        =     VaeImageProcessor(do_resize=snake_case       ,       do_normalize=snake_case      )

         __magic_name__			:		Optional[Any]        =     self.dummy_sample
         __magic_name__			:		Tuple        =     list(snake_case      )

         __magic_name__			:		Dict        =     image_processor.postprocess(
             image_processor.preprocess(snake_case      )       ,       output_type='''np'''       ,       )

         __magic_name__			:		Union[str, Any]        =     image_processor.postprocess(
             image_processor.preprocess(snake_case      )       ,       output_type='''np'''       ,       )

         __magic_name__			:		Dict        =     self.to_np(self.dummy_sample      )
         list(snake_case      )

         __magic_name__			:		List[Any]        =     image_processor.postprocess(
             image_processor.preprocess(snake_case      )       ,       output_type='''np'''       ,       )

         __magic_name__			:		Tuple        =     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




'''simple docstring'''



import re




def       _a      (		_lowercase   :      List[Any]    ):





     '''simple docstring'''






     def docstring_decorator(_lowercase   :      str    ):
          __UpperCAmelCase      :					Tuple    				=     fn.__doc__
          __UpperCAmelCase      :					Tuple    				=     func_doc.split('''\n'''    )
          __UpperCAmelCase      :					Optional[Any]    				=     0
          while i < len(_lowercase    ) and re.search(R'''^\s*Examples?:\s*$'''     ,   lines[i]    ) is None:
               i += 1
          if i < len(_lowercase    ):
               __UpperCAmelCase      :					Optional[int]    				=     example_docstring
               __UpperCAmelCase      :					Tuple    				=     '''\n'''.join(_lowercase    )
          else:
               raise ValueError(
                   F'The function {fn} should have an empty \'Examples:\' in its docstring as placeholder, '
                   F'current docstring is:\n{func_doc}'    )
          __UpperCAmelCase      :					Tuple    				=     func_doc
          return fn

     return docstring_decorator