


import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import LevitImageProcessor







class lowerCAmelCase_		(				unittest.TestCase ):

 '''simple docstring'''

 def __init__(			self	,   _UpperCAmelCase	,   _UpperCAmelCase=7	,   _UpperCAmelCase=3	,   _UpperCAmelCase=18	,   _UpperCAmelCase=30	,   _UpperCAmelCase=4_00	,   _UpperCAmelCase=True	,   _UpperCAmelCase=None	,   _UpperCAmelCase=True	,   _UpperCAmelCase=None	,   _UpperCAmelCase=True	,   _UpperCAmelCase=[0.5, 0.5, 0.5]	,   _UpperCAmelCase=[0.5, 0.5, 0.5]	,   ):
       snake_case_ =   size if size is not None else {'''shortest_edge''': 18}
       snake_case_ =   crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
       snake_case_ =   parent
       snake_case_ =   batch_size
       snake_case_ =   num_channels
       snake_case_ =   image_size
       snake_case_ =   min_resolution
       snake_case_ =   max_resolution
       snake_case_ =   do_resize
       snake_case_ =   size
       snake_case_ =   do_center_crop
       snake_case_ =   crop_size
       snake_case_ =   do_normalize
       snake_case_ =   image_mean
       snake_case_ =   image_std





 def 		UpperCamelCase__  (			self      ):
       return {
           "image_mean": self.image_mean,
           "image_std": self.image_std,
           "do_normalize": self.do_normalize,
           "do_resize": self.do_resize,
           "do_center_crop": self.do_center_crop,
           "size": self.size,
           "crop_size": self.crop_size,
       }







@require_torch
@require_vision
class lowerCAmelCase_		(				lowerCamelCase__      ,		unittest.TestCase ):

 '''simple docstring'''

 __snake_case				=						LevitImageProcessor if is_vision_available() else None



 def 		UpperCamelCase__  (			self      ):
       snake_case_ =   LevitImageProcessingTester(self      )



 @property
 def 		UpperCamelCase__  (			self      ):
       return self.image_processor_tester.prepare_image_processor_dict()



 def 		UpperCamelCase__  (			self      ):
       snake_case_ =   self.image_processing_class(**self.image_processor_dict      )
       self.assertTrue(hasattr(_UpperCAmelCase	,   '''image_mean'''      )      )
       self.assertTrue(hasattr(_UpperCAmelCase	,   '''image_std'''      )      )
       self.assertTrue(hasattr(_UpperCAmelCase	,   '''do_normalize'''      )      )
       self.assertTrue(hasattr(_UpperCAmelCase	,   '''do_resize'''      )      )
       self.assertTrue(hasattr(_UpperCAmelCase	,   '''do_center_crop'''      )      )
       self.assertTrue(hasattr(_UpperCAmelCase	,   '''size'''      )      )



 def 		UpperCamelCase__  (			self      ):
       snake_case_ =   self.image_processing_class.from_dict(self.image_processor_dict      )
       self.assertEqual(image_processor.size	,   {'''shortest_edge''': 18}      )
       self.assertEqual(image_processor.crop_size	,   {'''height''': 18, '''width''': 18}      )

       snake_case_ =   self.image_processing_class.from_dict(self.image_processor_dict	,   size=42	,   crop_size=84      )
       self.assertEqual(image_processor.size	,   {'''shortest_edge''': 42}      )
       self.assertEqual(image_processor.crop_size	,   {'''height''': 84, '''width''': 84}      )



 def 		UpperCamelCase__  (			self      ):
       pass



 def 		UpperCamelCase__  (			self      ):
       # Initialize image_processing
       snake_case_ =   self.image_processing_class(**self.image_processor_dict      )
       # create random PIL images
       snake_case_ =   prepare_image_inputs(self.image_processor_tester	,   equal_resolution=_UpperCAmelCase      )
       for image in image_inputs:
             self.assertIsInstance(_UpperCAmelCase	,   Image.Image      )

       # Test not batched input
       snake_case_ =   image_processing(image_inputs[0]	,   return_tensors='''pt'''      ).pixel_values
       self.assertEqual(
           encoded_images.shape	,   (
               1,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           )	,   )

       # Test batched
       snake_case_ =   image_processing(_UpperCAmelCase	,   return_tensors='''pt'''      ).pixel_values
       self.assertEqual(
           encoded_images.shape	,   (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           )	,   )



 def 		UpperCamelCase__  (			self      ):
       # Initialize image_processing
       snake_case_ =   self.image_processing_class(**self.image_processor_dict      )
       # create random numpy tensors
       snake_case_ =   prepare_image_inputs(self.image_processor_tester	,   equal_resolution=_UpperCAmelCase	,   numpify=_UpperCAmelCase      )
       for image in image_inputs:
             self.assertIsInstance(_UpperCAmelCase	,   np.ndarray      )

       # Test not batched input
       snake_case_ =   image_processing(image_inputs[0]	,   return_tensors='''pt'''      ).pixel_values
       self.assertEqual(
           encoded_images.shape	,   (
               1,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           )	,   )

       # Test batched
       snake_case_ =   image_processing(_UpperCAmelCase	,   return_tensors='''pt'''      ).pixel_values
       self.assertEqual(
           encoded_images.shape	,   (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           )	,   )





 def 		UpperCamelCase__  (			self      ):
       # Initialize image_processing
       snake_case_ =   self.image_processing_class(**self.image_processor_dict      )
       # create random PyTorch tensors
       snake_case_ =   prepare_image_inputs(self.image_processor_tester	,   equal_resolution=_UpperCAmelCase	,   torchify=_UpperCAmelCase      )
       for image in image_inputs:
             self.assertIsInstance(_UpperCAmelCase	,   torch.Tensor      )

       # Test not batched input
       snake_case_ =   image_processing(image_inputs[0]	,   return_tensors='''pt'''      ).pixel_values
       self.assertEqual(
           encoded_images.shape	,   (
               1,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           )	,   )

       # Test batched
       snake_case_ =   image_processing(_UpperCAmelCase	,   return_tensors='''pt'''      ).pixel_values
       self.assertEqual(
           encoded_images.shape	,   (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           )	,   )



def  __lowerCAmelCase					(SCREAMING_SNAKE_CASE      ,      SCREAMING_SNAKE_CASE      )->						int:




      """simple docstring"""

      return int((input_a, input_a).count(0      ) == 0      )






def  __lowerCAmelCase					()->						None:




      """simple docstring"""

      assert and_gate(0      ,      0      ) == 0
      assert and_gate(0      ,      1      ) == 0
      assert and_gate(1      ,      0      ) == 0
      assert and_gate(1      ,      1      ) == 1


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