


'''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 MobileNetVaImageProcessor
class   __lowerCAmelCase						(unittest.TestCase					):





      '''simple docstring'''






      def __init__(self   :   List[Any]       ,						UpperCamelCase   :   Union[str, Any]       ,						UpperCamelCase   :   List[Any]=7       ,						UpperCamelCase   :   Optional[int]=3       ,						UpperCamelCase   :   Dict=18       ,						UpperCamelCase   :   int=30       ,						UpperCamelCase   :   List[str]=400       ,						UpperCamelCase   :   Optional[int]=True       ,						UpperCamelCase   :   int=None       ,						UpperCamelCase   :   Any=True       ,						UpperCamelCase   :   Optional[Any]=None       ,						):

             '''simple docstring'''







             lowercase__				      =			size if size is not None else {"""shortest_edge""": 20}
             lowercase__				      =			crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
             lowercase__				      =			parent
             lowercase__				      =			batch_size
             lowercase__				      =			num_channels
             lowercase__				      =			image_size
             lowercase__				      =			min_resolution
             lowercase__				      =			max_resolution
             lowercase__				      =			do_resize
             lowercase__				      =			size
             lowercase__				      =			do_center_crop
             lowercase__				      =			crop_size






      def 				UpperCamelCase__		(self   :   Any			):

             '''simple docstring'''







             return {
                 "do_resize": self.do_resize,
                 "size": self.size,
                 "do_center_crop": self.do_center_crop,
                 "crop_size": self.crop_size,
             }






@require_torch
@require_vision
class   __lowerCAmelCase						(UpperCAmelCase__  ,					unittest.TestCase					):





      '''simple docstring'''






      lowerCAmelCase__ :					Tuple   =							MobileNetVaImageProcessor if is_vision_available() else None



      def 				UpperCamelCase__		(self   :   Any			):

             '''simple docstring'''







             lowercase__				      =			MobileNetVaImageProcessingTester(self			)



      @property
      def 				UpperCamelCase__		(self   :   List[Any]			):

             '''simple docstring'''







             return self.image_processor_tester.prepare_image_processor_dict()



      def 				UpperCamelCase__		(self   :   Tuple			):

             '''simple docstring'''







             lowercase__				      =			self.image_processing_class(**self.image_processor_dict			)
             self.assertTrue(hasattr(UpperCamelCase       ,						'''do_resize'''			)			)
             self.assertTrue(hasattr(UpperCamelCase       ,						'''size'''			)			)
             self.assertTrue(hasattr(UpperCamelCase       ,						'''do_center_crop'''			)			)
             self.assertTrue(hasattr(UpperCamelCase       ,						'''center_crop'''			)			)



      def 				UpperCamelCase__		(self   :   Optional[Any]			):

             '''simple docstring'''







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

             lowercase__				      =			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   :   Optional[Any]			):

             '''simple docstring'''







             pass



      def 				UpperCamelCase__		(self   :   int			):

             '''simple docstring'''







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

             # Test not batched input
             lowercase__				      =			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
             lowercase__				      =			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   :   Dict			):

             '''simple docstring'''







             lowercase__				      =			self.image_processing_class(**self.image_processor_dict			)
             # create random numpy tensors
             lowercase__				      =			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
             lowercase__				      =			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
             lowercase__				      =			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   :   List[str]			):

             '''simple docstring'''







             lowercase__				      =			self.image_processing_class(**self.image_processor_dict			)
             # create random PyTorch tensors
             lowercase__				      =			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
             lowercase__				      =			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
             lowercase__				      =			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'''],
                 )       ,						)








'''simple docstring'''

def _SCREAMING_SNAKE_CASE				(A	)	->	list:






       """simple docstring"""







       lowercase__				      =			len(A	)

       # Set the gap value to be decreased by a factor of 1.3
       # after each iteration
       lowercase__				      =			1.3

       # Continue sorting until the gap is 1
       while gap > 1:
              # Decrease the gap value
              lowercase__				      =			int(gap / shrink	)

              # Sort the elements using insertion sort
              for i in range(A  ,			len(A	)	):
                     lowercase__				      =			collection[i]
                     lowercase__				      =			i
                     while j >= gap and collection[j - gap] > temp:
                            lowercase__				      =			collection[j - gap]
                            j -= gap
                     lowercase__				      =			temp

       return collection


if __name__ == "__main__":
 import doctest

 doctest.testmod()




