






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 			_UpperCamelCase(       unittest.TestCase		):

		def __init__(					self		:    Union[str, Any]    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]=7    ,       SCREAMING_SNAKE_CASE__		:    Tuple=3    ,       SCREAMING_SNAKE_CASE__		:    int=3_0    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]=4_0_0    ,       SCREAMING_SNAKE_CASE__		:    List[Any]=True    ,       SCREAMING_SNAKE_CASE__		:    List[Any]=None    ,       SCREAMING_SNAKE_CASE__		:    Tuple=0.9    ,       SCREAMING_SNAKE_CASE__		:    List[Any]=None    ,       SCREAMING_SNAKE_CASE__		:    Optional[int]=True    ,       SCREAMING_SNAKE_CASE__		:    str=[0.5, 0.5, 0.5]    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]=[0.5, 0.5, 0.5]    ,       ):



					'''simple docstring'''



					__a						:  List[str]									=     size if size is not None else {'shortest_edge': 3_0}
					__a						:  Tuple									=     crop_size if crop_size is not None else {'height': 3_0, 'width': 3_0}
					__a						:  List[str]									=     parent
					__a						:  List[Any]									=     batch_size
					__a						:  Tuple									=     num_channels
					__a						:  List[Any]									=     min_resolution
					__a						:  int									=     max_resolution
					__a						:  int									=     do_resize_and_center_crop
					__a						:  List[str]									=     size
					__a						:  Optional[Any]									=     crop_pct
					__a						:  Optional[Any]									=     crop_size
					__a						:  List[str]									=     do_normalize
					__a						:  List[str]									=     image_mean
					__a						:  Optional[int]									=     image_std



		def    __lowerCAmelCase  (					self		:    Optional[int]    ):



					'''simple docstring'''



					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 			_UpperCamelCase(       __SCREAMING_SNAKE_CASE		,				unittest.TestCase		):
		__SCREAMING_SNAKE_CASE  :       Optional[Any]							=							PoolFormerImageProcessor if is_vision_available() else None

		def    __lowerCAmelCase  (					self		:    Optional[Any]    ):



					'''simple docstring'''



					__a						:  List[str]									=     PoolFormerImageProcessingTester(self    )

		@property
		def    __lowerCAmelCase  (					self		:    Union[str, Any]    ):



					'''simple docstring'''



					return self.image_processor_tester.prepare_image_processor_dict()

		def    __lowerCAmelCase  (					self		:    List[str]    ):



					'''simple docstring'''



					__a						:  Any									=     self.image_processing_class(**self.image_processor_dict    )
					self.assertTrue(hasattr(__lowerCamelCase    ,       'do_resize_and_center_crop'    )    )
					self.assertTrue(hasattr(__lowerCamelCase    ,       'size'    )    )
					self.assertTrue(hasattr(__lowerCamelCase    ,       'crop_pct'    )    )
					self.assertTrue(hasattr(__lowerCamelCase    ,       'do_normalize'    )    )
					self.assertTrue(hasattr(__lowerCamelCase    ,       'image_mean'    )    )
					self.assertTrue(hasattr(__lowerCamelCase    ,       'image_std'    )    )

		def    __lowerCAmelCase  (					self		:    List[Any]    ):



					'''simple docstring'''



					__a						:  Optional[Any]									=     self.image_processing_class.from_dict(self.image_processor_dict    )
					self.assertEqual(image_processor.size    ,       {'shortest_edge': 3_0}    )
					self.assertEqual(image_processor.crop_size    ,       {'height': 3_0, 'width': 3_0}    )

					__a						:  int									=     self.image_processing_class.from_dict(self.image_processor_dict    ,       size=4_2    ,       crop_size=8_4    )
					self.assertEqual(image_processor.size    ,       {'shortest_edge': 4_2}    )
					self.assertEqual(image_processor.crop_size    ,       {'height': 8_4, 'width': 8_4}    )

		def    __lowerCAmelCase  (					self		:    Dict    ):



					'''simple docstring'''



					pass

		def    __lowerCAmelCase  (					self		:    Tuple    ):



					'''simple docstring'''



					__a						:  Optional[Any]									=     self.image_processing_class(**self.image_processor_dict    )
					# create random PIL images
					__a						:  Tuple									=     prepare_image_inputs(self.image_processor_tester    ,       equal_resolution=__lowerCamelCase    )
					for image in image_inputs:
								self.assertIsInstance(__lowerCamelCase    ,       Image.Image    )

					# Test not batched input
					__a						:  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
					__a						:  List[Any]									=     image_processing(__lowerCamelCase    ,       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  (					self		:    Tuple    ):



					'''simple docstring'''



					__a						:  Any									=     self.image_processing_class(**self.image_processor_dict    )
					# create random numpy tensors
					__a						:  Union[str, Any]									=     prepare_image_inputs(self.image_processor_tester    ,       equal_resolution=__lowerCamelCase    ,       numpify=__lowerCamelCase    )
					for image in image_inputs:
								self.assertIsInstance(__lowerCamelCase    ,       np.ndarray    )

					# Test not batched input
					__a						:  str									=     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
					__a						:  Union[str, Any]									=     image_processing(__lowerCamelCase    ,       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  (					self		:    Optional[int]    ):



					'''simple docstring'''



					__a						:  Optional[Any]									=     self.image_processing_class(**self.image_processor_dict    )
					# create random PyTorch tensors
					__a						:  Optional[int]									=     prepare_image_inputs(self.image_processor_tester    ,       equal_resolution=__lowerCamelCase    ,       torchify=__lowerCamelCase    )
					for image in image_inputs:
								self.assertIsInstance(__lowerCamelCase    ,       torch.Tensor    )

					# Test not batched input
					__a						:  str									=     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
					__a						:  str									=     image_processing(__lowerCamelCase    ,       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'],
					    )    ,       )










"""simple docstring"""






def 			snake_case		(		lowerCAmelCase_  ,						lowerCAmelCase_	)						->				int:
  return 1 if input_a == input_a else 0




def 			snake_case		(		)						->				None:
  assert xnor_gate(0  ,						0	) == 1
  assert xnor_gate(0  ,						1	) == 0
  assert xnor_gate(1  ,						0	) == 0
  assert xnor_gate(1  ,						1	) == 1


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





