

'''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 MobileViTImageProcessor


class 					A__      (      unittest.TestCase			):



    def __init__(					self		,				UpperCamelCase__		,				UpperCamelCase__=7		,				UpperCamelCase__=3		,				UpperCamelCase__=18		,				UpperCamelCase__=30		,				UpperCamelCase__=400		,				UpperCamelCase__=True		,				UpperCamelCase__=None		,				UpperCamelCase__=True		,				UpperCamelCase__=None		,				UpperCamelCase__=True		,				)						->      Dict:





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







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





           '''simple docstring'''
           return {
               "do_resize": self.do_resize,
               "size": self.size,
               "do_center_crop": self.do_center_crop,
               "crop_size": self.crop_size,
               "do_flip_channel_order": self.do_flip_channel_order,
           }


@require_torch
@require_vision
class 					A__      (      _snake_case						,						unittest.TestCase			):
    lowercase						=		MobileViTImageProcessor if is_vision_available() else None



    def 					snake_case_			(					self       )						->      Tuple:





           '''simple docstring'''
           A_						=      MobileViTImageProcessingTester(self       )



    @property
    def 					snake_case_			(					self       )						->      Union[str, Any]:





           '''simple docstring'''
           return self.image_processor_tester.prepare_image_processor_dict()



    def 					snake_case_			(					self       )						->      Tuple:





           '''simple docstring'''
           A_						=      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"""       )       )
           self.assertTrue(hasattr(UpperCamelCase__		,				"""do_flip_channel_order"""       )       )



    def 					snake_case_			(					self       )						->      Tuple:





           '''simple docstring'''
           A_						=      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}       )

           A_						=      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       )						->      List[Any]:





           '''simple docstring'''
           pass



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





           '''simple docstring'''
           A_						=      self.image_processing_class(**self.image_processor_dict       )
           # create random PIL images
           A_						=      prepare_image_inputs(self.image_processor_tester		,				equal_resolution=UpperCamelCase__       )
           for image in image_inputs:
                  self.assertIsInstance(UpperCamelCase__		,				Image.Image       )

           # Test not batched input
           A_						=      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_						=      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]:





           '''simple docstring'''
           A_						=      self.image_processing_class(**self.image_processor_dict       )
           # create random numpy tensors
           A_						=      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
           A_						=      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_						=      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       )						->      Dict:





           '''simple docstring'''
           A_						=      self.image_processing_class(**self.image_processor_dict       )
           # create random PyTorch tensors
           A_						=      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
           A_						=      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_						=      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       UpperCAmelCase__    (      UpperCAmelCase__,       UpperCAmelCase__,       UpperCAmelCase__ = 0,       UpperCAmelCase__ = 0				)			->			int:
       A_						=      right or len(UpperCAmelCase__				) - 1
       if left > right:
              return -1
       elif list_data[left] == key:
              return left
       elif list_data[right] == key:
              return right
       else:
              return search(UpperCAmelCase__,       UpperCAmelCase__,       left + 1,       right - 1				)


if __name__ == "__main__":
      import doctest

      doctest.testmod()
