






"""simple docstring"""







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 EfficientNetImageProcessor





class      UpperCamelCase_       (				unittest.TestCase     ):



  def __init__(					self       ,						snake_case__       ,						snake_case__=13       ,						snake_case__=3       ,						snake_case__=18       ,						snake_case__=30       ,						snake_case__=4_00       ,						snake_case__=True       ,						snake_case__=None       ,						snake_case__=True       ,						snake_case__=[0.5, 0.5, 0.5]       ,						snake_case__=[0.5, 0.5, 0.5]       ,						)	->	Dict:



         """simple docstring"""





         UpperCAmelCase					=	size if size is not None else {"""height""": 18, """width""": 18}
         UpperCAmelCase					=	parent
         UpperCAmelCase					=	batch_size
         UpperCAmelCase					=	num_channels
         UpperCAmelCase					=	image_size
         UpperCAmelCase					=	min_resolution
         UpperCAmelCase					=	max_resolution
         UpperCAmelCase					=	do_resize
         UpperCAmelCase					=	size
         UpperCAmelCase					=	do_normalize
         UpperCAmelCase					=	image_mean
         UpperCAmelCase					=	image_std



  def 						UpperCamelCase_ (					self )	->	int:



         """simple docstring"""





         return {
             "image_mean": self.image_mean,
             "image_std": self.image_std,
             "do_normalize": self.do_normalize,
             "do_resize": self.do_resize,
             "size": self.size,
         }





@require_torch
@require_vision
class      UpperCamelCase_       (				a_      ,    unittest.TestCase     ):
  _A				:    Optional[int] =		EfficientNetImageProcessor if is_vision_available() else None



  def 						UpperCamelCase_ (					self )	->	Tuple:



         """simple docstring"""





         UpperCAmelCase					=	EfficientNetImageProcessorTester(self )



  @property
  def 						UpperCamelCase_ (					self )	->	Optional[int]:



         """simple docstring"""





         return self.image_processor_tester.prepare_image_processor_dict()



  def 						UpperCamelCase_ (					self )	->	List[str]:



         """simple docstring"""





         UpperCAmelCase					=	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       ,						"""size""" ) )



  def 						UpperCamelCase_ (					self )	->	List[Any]:



         """simple docstring"""





         UpperCAmelCase					=	self.image_processing_class.from_dict(self.image_processor_dict )
         self.assertEqual(image_processor.size       ,						{"""height""": 18, """width""": 18} )

         UpperCAmelCase					=	self.image_processing_class.from_dict(self.image_processor_dict       ,						size=42 )
         self.assertEqual(image_processor.size       ,						{"""height""": 42, """width""": 42} )



  def 						UpperCamelCase_ (					self )	->	Tuple:



         """simple docstring"""





         UpperCAmelCase					=	self.image_processing_class(**self.image_processor_dict )
         # create random PIL images
         UpperCAmelCase					=	prepare_image_inputs(self.image_processor_tester       ,						equal_resolution=__UpperCAmelCase )
         for image in image_inputs:
                self.assertIsInstance(__UpperCAmelCase       ,						Image.Image )

         # Test not batched input
         UpperCAmelCase					=	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.size["""height"""],
                 self.image_processor_tester.size["""width"""],
             )       ,						)

         # Test batched
         UpperCAmelCase					=	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.size["""height"""],
                 self.image_processor_tester.size["""width"""],
             )       ,						)



  def 						UpperCamelCase_ (					self )	->	Union[str, Any]:



         """simple docstring"""





         UpperCAmelCase					=	self.image_processing_class(**self.image_processor_dict )
         # create random numpy tensors
         UpperCAmelCase					=	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
         UpperCAmelCase					=	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.size["""height"""],
                 self.image_processor_tester.size["""width"""],
             )       ,						)

         # Test batched
         UpperCAmelCase					=	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.size["""height"""],
                 self.image_processor_tester.size["""width"""],
             )       ,						)



  def 						UpperCamelCase_ (					self )	->	Any:



         """simple docstring"""





         UpperCAmelCase					=	self.image_processing_class(**self.image_processor_dict )
         # create random PyTorch tensors
         UpperCAmelCase					=	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
         UpperCAmelCase					=	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.size["""height"""],
                 self.image_processor_tester.size["""width"""],
             )       ,						)

         # Test batched
         UpperCAmelCase					=	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.size["""height"""],
                 self.image_processor_tester.size["""width"""],
             )       ,						)


"""simple docstring"""


from .hash_table import HashTable







class 		lowerCamelCase__					(					__magic_name__				):





			'''simple docstring'''



			def __init__(							self     ,     *__UpperCAmelCase     ,     **__UpperCAmelCase  ) ->     List[str]:
				super().__init__(*__UpperCAmelCase     ,     **__UpperCAmelCase  )



			def 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase=None  ) ->     Union[str, Any]:
				_lowerCAmelCase								=1
				_lowerCAmelCase								=self.hash_function(key + i * i  )

				while self.values[new_key] is not None and self.values[new_key] != key:
					i += 1
					_lowerCAmelCase								=(
					    self.hash_function(key + i * i  )
					    if not self.balanced_factor() >= self.lim_charge
					    else None
					)

					if new_key is None:
						break

				return new_key



