






'''simple docstring'''







import unittest

import numpy as np
import PIL
import torch

from diffusers.image_processor import VaeImageProcessor




class      __SCREAMING_SNAKE_CASE					(unittest.TestCase					):


  """simple docstring"""


  @property
  def       _a					( self  ):






         """simple docstring"""


         a_	    = 1
         a_	    = 3
         a_	    = 8
         a_	    = 8

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

         return sample







  def       _a					( self      ,  UpperCamelCase__  ):






         """simple docstring"""


         if isinstance(image[0]      ,  PIL.Image.Image  ):
                return np.stack([np.array(UpperCamelCase__  ) for i in image]      ,  axis=0  )
         elif isinstance(UpperCamelCase__      ,  torch.Tensor  ):
                return image.cpu().numpy().transpose(0      ,  2      ,  3      ,  1  )
         return image







  def       _a					( self  ):






         """simple docstring"""


         a_	    = VaeImageProcessor(do_resize=UpperCamelCase__      ,  do_normalize=UpperCamelCase__  )

         a_	    = self.dummy_sample
         a_	    = self.to_np(UpperCamelCase__  )

         for output_type in ["pt", "np", "pil"]:
                a_	    = image_processor.postprocess(
                    image_processor.preprocess(UpperCamelCase__  )      ,  output_type=UpperCamelCase__      ,  )
                a_	    = self.to_np(UpperCamelCase__  )
                a_	    = (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       _a					( self  ):






         """simple docstring"""


         a_	    = VaeImageProcessor(do_resize=UpperCamelCase__      ,  do_normalize=UpperCamelCase__  )
         a_	    = self.dummy_sample.cpu().numpy().transpose(0      ,  2      ,  3      ,  1  )

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

                a_	    = self.to_np(UpperCamelCase__  )
                a_	    = (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       _a					( self  ):






         """simple docstring"""


         a_	    = VaeImageProcessor(do_resize=UpperCamelCase__      ,  do_normalize=UpperCamelCase__  )

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

         for output_type in ["pt", "np", "pil"]:
                a_	    = image_processor.postprocess(image_processor.preprocess(UpperCamelCase__  )      ,  output_type=UpperCamelCase__  )
                for i, o in zip(UpperCamelCase__      ,  UpperCamelCase__  ):
                       a_	    = np.array(UpperCamelCase__  )
                       a_	    = self.to_np(UpperCamelCase__  ) if output_type == 'pil' else (self.to_np(UpperCamelCase__  ) * 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       _a					( self  ):






         """simple docstring"""


         a_	    = VaeImageProcessor(do_resize=UpperCamelCase__      ,  do_normalize=UpperCamelCase__  )

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

         a_	    = image_processor.postprocess(
             image_processor.preprocess(UpperCamelCase__  )      ,  output_type='np'      ,  )
         a_	    = image_processor.postprocess(
             image_processor.preprocess(UpperCamelCase__  )      ,  output_type='np'      ,  )

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

         a_	    = image_processor.postprocess(
             image_processor.preprocess(UpperCamelCase__  )      ,  output_type='np'      ,  )
         a_	    = image_processor.postprocess(
             image_processor.preprocess(UpperCamelCase__  )      ,  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       _a					( self  ):






         """simple docstring"""


         a_	    = VaeImageProcessor(do_resize=UpperCamelCase__      ,  do_normalize=UpperCamelCase__  )

         a_	    = self.dummy_sample
         a_	    = list(UpperCamelCase__  )

         a_	    = image_processor.postprocess(
             image_processor.preprocess(UpperCamelCase__  )      ,  output_type='np'      ,  )

         a_	    = image_processor.postprocess(
             image_processor.preprocess(UpperCamelCase__  )      ,  output_type='np'      ,  )

         a_	    = self.to_np(self.dummy_sample  )
         list(UpperCamelCase__  )

         a_	    = image_processor.postprocess(
             image_processor.preprocess(UpperCamelCase__  )      ,  output_type='np'      ,  )

         a_	    = image_processor.postprocess(
             image_processor.preprocess(UpperCamelCase__  )      ,  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'''







def 			__UpperCamelCase				(			lowercase_					:     int      ,					lowercase_					:     int      ):
       """simple docstring"""




       return (input_a, input_a).count(0      ) % 2


def 			__UpperCamelCase				(			):
       """simple docstring"""




       assert xor_gate(0      ,					0      ) == 0
       assert xor_gate(0      ,					1      ) == 1
       assert xor_gate(1      ,					0      ) == 1
       assert xor_gate(1      ,					1      ) == 0


if __name__ == "__main__":
  print(xor_gate(0, 0))
  print(xor_gate(0, 1))




