


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 PoolFormerImageProcessor

class        a	(unittest.TestCase   ):




       """simple docstring"""


       def __init__(							self :						Dict					,			lowerCamelCase :						List[str]					,			lowerCamelCase :						List[Any]=7					,			lowerCamelCase :						Union[str, Any]=3					,			lowerCamelCase :						List[str]=30					,			lowerCamelCase :						List[Any]=400					,			lowerCamelCase :						Union[str, Any]=True					,			lowerCamelCase :						Optional[Any]=None					,			lowerCamelCase :						Optional[Any]=0.9					,			lowerCamelCase :						Any=None					,			lowerCamelCase :						Any=True					,			lowerCamelCase :						Optional[Any]=[0.5, 0.5, 0.5]					,			lowerCamelCase :						Dict=[0.5, 0.5, 0.5]					,			)			->					Any:
              __snake_case	:    str											=     size if size is not None else {"shortest_edge": 30}
              __snake_case	:    Union[str, Any]											=     crop_size if crop_size is not None else {"height": 30, "width": 30}
              __snake_case	:    Dict											=     parent
              __snake_case	:    List[Any]											=     batch_size
              __snake_case	:    Tuple											=     num_channels
              __snake_case	:    Tuple											=     min_resolution
              __snake_case	:    Tuple											=     max_resolution
              __snake_case	:    Union[str, Any]											=     do_resize_and_center_crop
              __snake_case	:    Dict											=     size
              __snake_case	:    str											=     crop_pct
              __snake_case	:    List[Any]											=     crop_size
              __snake_case	:    Any											=     do_normalize
              __snake_case	:    str											=     image_mean
              __snake_case	:    str											=     image_std






       def 					__snake_case      (							self :						Any       )			->					Union[str, Any]:
              return {
                  "size": self.size,
                  "do_resize_and_center_crop": self.do_resize_and_center_crop,
                  "crop_pct": self.crop_pct,
                  "crop_size": self.crop_size,
                  "do_normalize": self.do_normalize,
                  "image_mean": self.image_mean,
                  "image_std": self.image_std,
              }

@require_torch
@require_vision
class        a	(__snake_case  ,       unittest.TestCase   ):




       """simple docstring"""


       __UpperCAmelCase					:							Union[str, Any]  						=						PoolFormerImageProcessor if is_vision_available() else None

       def 					__snake_case      (							self :						Dict       )			->					Union[str, Any]:
              __snake_case	:    Any											=     PoolFormerImageProcessingTester(self       )

       @property
       def 					__snake_case      (							self :						Optional[int]       )			->					Tuple:
              return self.image_processor_tester.prepare_image_processor_dict()

       def 					__snake_case      (							self :						Union[str, Any]       )			->					int:
              __snake_case	:    List[Any]											=     self.image_processing_class(**self.image_processor_dict       )
              self.assertTrue(hasattr(__UpperCamelCase					,			"do_resize_and_center_crop"       )       )
              self.assertTrue(hasattr(__UpperCamelCase					,			"size"       )       )
              self.assertTrue(hasattr(__UpperCamelCase					,			"crop_pct"       )       )
              self.assertTrue(hasattr(__UpperCamelCase					,			"do_normalize"       )       )
              self.assertTrue(hasattr(__UpperCamelCase					,			"image_mean"       )       )
              self.assertTrue(hasattr(__UpperCamelCase					,			"image_std"       )       )

       def 					__snake_case      (							self :						Optional[int]       )			->					int:
              __snake_case	:    List[str]											=     self.image_processing_class.from_dict(self.image_processor_dict       )
              self.assertEqual(image_processor.size					,			{"shortest_edge": 30}       )
              self.assertEqual(image_processor.crop_size					,			{"height": 30, "width": 30}       )

              __snake_case	:    Any											=     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 					__snake_case      (							self :						int       )			->					List[str]:
              pass

       def 					__snake_case      (							self :						Dict       )			->					Union[str, Any]:
              __snake_case	:    int											=     self.image_processing_class(**self.image_processor_dict       )
              # create random PIL images
              __snake_case	:    str											=     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	:    Dict											=     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	:    str											=     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 					__snake_case      (							self :						Tuple       )			->					Union[str, Any]:
              __snake_case	:    List[str]											=     self.image_processing_class(**self.image_processor_dict       )
              # create random numpy tensors
              __snake_case	:    List[str]											=     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	:    Union[str, Any]											=     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	:    Union[str, Any]											=     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 					__snake_case      (							self :						List[str]       )			->					int:
              __snake_case	:    Any											=     self.image_processing_class(**self.image_processor_dict       )
              # create random PyTorch tensors
              __snake_case	:    Tuple											=     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	:    int											=     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	:    int											=     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_  (      __lowerCamelCase							,			__lowerCamelCase			):
							return int((input_a, input_a).count(0			) == 0			)







def        lowerCAmelCase_  (      ):
							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))

