






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


if is_torch_available():
      import torch

if is_vision_available():
      from PIL import Image

      from transformers import ChineseCLIPImageProcessor




class     A    (      unittest.TestCase						):






 """simple docstring"""





 def __init__(							self			,     __lowerCAmelCase			,     __lowerCAmelCase=7			,     __lowerCAmelCase=3			,     __lowerCAmelCase=18			,     __lowerCAmelCase=30			,     __lowerCAmelCase=4_00			,     __lowerCAmelCase=True			,     __lowerCAmelCase=None			,     __lowerCAmelCase=True			,     __lowerCAmelCase=None			,     __lowerCAmelCase=True			,     __lowerCAmelCase=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]			,     __lowerCAmelCase=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]			,     __lowerCAmelCase=True			,     ):
       UpperCamelCase_				:   List[Any]					    =							size if size is not None else {"""height""": 2_24, """width""": 2_24}
       UpperCamelCase_				:   Union[str, Any]					    =							crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
       UpperCamelCase_				:   Any					    =							parent
       UpperCamelCase_				:   List[Any]					    =							batch_size
       UpperCamelCase_				:   List[str]					    =							num_channels
       UpperCamelCase_				:   Tuple					    =							image_size
       UpperCamelCase_				:   Optional[Any]					    =							min_resolution
       UpperCamelCase_				:   str					    =							max_resolution
       UpperCamelCase_				:   Any					    =							do_resize
       UpperCamelCase_				:   Tuple					    =							size
       UpperCamelCase_				:   Tuple					    =							do_center_crop
       UpperCamelCase_				:   Union[str, Any]					    =							crop_size
       UpperCamelCase_				:   Dict					    =							do_normalize
       UpperCamelCase_				:   Dict					    =							image_mean
       UpperCamelCase_				:   Any					    =							image_std
       UpperCamelCase_				:   Any					    =							do_convert_rgb
 def   _UpperCAmelCase       (							self ):
       return {
           "do_resize": self.do_resize,
           "size": self.size,
           "do_center_crop": self.do_center_crop,
           "crop_size": self.crop_size,
           "do_normalize": self.do_normalize,
           "image_mean": self.image_mean,
           "image_std": self.image_std,
           "do_convert_rgb": self.do_convert_rgb,
       }





 def   _UpperCAmelCase       (							self			,     __lowerCAmelCase=False			,     __lowerCAmelCase=False			,     __lowerCAmelCase=False ):
       assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

       if equal_resolution:
             UpperCamelCase_				:   Union[str, Any]					    =							[]
             for i in range(self.batch_size ):
                   image_inputs.append(
                       np.random.randint(
                           2_55			,     size=(self.num_channels, self.max_resolution, self.max_resolution)			,     dtype=np.uinta ) )
       else:
             UpperCamelCase_				:   Union[str, Any]					    =							[]
             for i in range(self.batch_size ):
                   UpperCamelCase_    ,			UpperCamelCase_				:   List[Any]					    =							np.random.choice(np.arange(self.min_resolution			,     self.max_resolution )			,     2 )
                   image_inputs.append(np.random.randint(2_55			,     size=(self.num_channels, width, height)			,     dtype=np.uinta ) )

       if not numpify and not torchify:
             # PIL expects the channel dimension as last dimension
             UpperCamelCase_				:   int					    =							[Image.fromarray(np.moveaxis(__lowerCAmelCase			,     0			,     -1 ) ) for x in image_inputs]

       if torchify:
             UpperCamelCase_				:   List[Any]					    =							[torch.from_numpy(__lowerCAmelCase ) for x in image_inputs]

       return image_inputs






@require_torch
@require_vision
class     A    (      SCREAMING_SNAKE_CASE__,   unittest.TestCase						):






 """simple docstring"""





 __a			:						List[Any]      =						ChineseCLIPImageProcessor if is_vision_available() else None
 def   _UpperCAmelCase       (							self ):
       UpperCamelCase_				:   List[Any]					    =							ChineseCLIPImageProcessingTester(self			,     do_center_crop=__lowerCAmelCase )
 @property
 def   _UpperCAmelCase       (							self ):
       return self.image_processor_tester.prepare_image_processor_dict()
 def   _UpperCAmelCase       (							self ):
       UpperCamelCase_				:   Optional[Any]					    =							self.image_processing_class(**self.image_processor_dict )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """do_resize""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """size""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """do_center_crop""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """center_crop""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """do_normalize""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """image_mean""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """image_std""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """do_convert_rgb""" ) )
 def   _UpperCAmelCase       (							self ):
       UpperCamelCase_				:   Union[str, Any]					    =							self.image_processing_class.from_dict(self.image_processor_dict )
       self.assertEqual(image_processor.size			,     {"""height""": 2_24, """width""": 2_24} )
       self.assertEqual(image_processor.crop_size			,     {"""height""": 18, """width""": 18} )

       UpperCamelCase_				:   Union[str, 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   _UpperCAmelCase       (							self ):
       pass
 def   _UpperCAmelCase       (							self ):
       # Initialize image_processing
       UpperCamelCase_				:   Tuple					    =							self.image_processing_class(**self.image_processor_dict )
       # create random PIL images
       UpperCamelCase_				:   Optional[int]					    =							self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCAmelCase )
       for image in image_inputs:
             self.assertIsInstance(__lowerCAmelCase			,     Image.Image )

       # Test not batched input
       UpperCamelCase_				:   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
       UpperCamelCase_				:   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   _UpperCAmelCase       (							self ):
       # Initialize image_processing
       UpperCamelCase_				:   Any					    =							self.image_processing_class(**self.image_processor_dict )
       # create random numpy tensors
       UpperCamelCase_				:   Any					    =							self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCAmelCase			,     numpify=__lowerCAmelCase )
       for image in image_inputs:
             self.assertIsInstance(__lowerCAmelCase			,     np.ndarray )

       # Test not batched input
       UpperCamelCase_				:   List[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
       UpperCamelCase_				:   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   _UpperCAmelCase       (							self ):
       # Initialize image_processing
       UpperCamelCase_				:   Dict					    =							self.image_processing_class(**self.image_processor_dict )
       # create random PyTorch tensors
       UpperCamelCase_				:   Tuple					    =							self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCAmelCase			,     torchify=__lowerCAmelCase )
       for image in image_inputs:
             self.assertIsInstance(__lowerCAmelCase			,     torch.Tensor )

       # Test not batched input
       UpperCamelCase_				:   List[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
       UpperCamelCase_				:   List[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"""],
           )			,     )






@require_torch
@require_vision
class     A    (      SCREAMING_SNAKE_CASE__,   unittest.TestCase						):






 """simple docstring"""





 __a			:						Optional[Any]      =						ChineseCLIPImageProcessor if is_vision_available() else None
 def   _UpperCAmelCase       (							self ):
       UpperCamelCase_				:   List[Any]					    =							ChineseCLIPImageProcessingTester(self			,     num_channels=4			,     do_center_crop=__lowerCAmelCase )
       UpperCamelCase_				:   Tuple					    =							3
 @property
 def   _UpperCAmelCase       (							self ):
       return self.image_processor_tester.prepare_image_processor_dict()
 def   _UpperCAmelCase       (							self ):
       UpperCamelCase_				:   Optional[Any]					    =							self.image_processing_class(**self.image_processor_dict )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """do_resize""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """size""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """do_center_crop""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """center_crop""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """do_normalize""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """image_mean""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """image_std""" ) )
       self.assertTrue(hasattr(__lowerCAmelCase			,     """do_convert_rgb""" ) )
 def   _UpperCAmelCase       (							self ):
       pass





 def   _UpperCAmelCase       (							self ):
       # Initialize image_processing
       UpperCamelCase_				:   List[str]					    =							self.image_processing_class(**self.image_processor_dict )
       # create random PIL images
       UpperCamelCase_				:   Dict					    =							self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCAmelCase )
       for image in image_inputs:
             self.assertIsInstance(__lowerCAmelCase			,     Image.Image )

       # Test not batched input
       UpperCamelCase_				:   Optional[Any]					    =							image_processing(image_inputs[0]			,     return_tensors="""pt""" ).pixel_values
       self.assertEqual(
           encoded_images.shape			,     (
               1,
               self.expected_encoded_image_num_channels,
               self.image_processor_tester.crop_size["""height"""],
               self.image_processor_tester.crop_size["""width"""],
           )			,     )

       # Test batched
       UpperCamelCase_				:   Optional[int]					    =							image_processing(__lowerCAmelCase			,     return_tensors="""pt""" ).pixel_values
       self.assertEqual(
           encoded_images.shape			,     (
               self.image_processor_tester.batch_size,
               self.expected_encoded_image_num_channels,
               self.image_processor_tester.crop_size["""height"""],
               self.image_processor_tester.crop_size["""width"""],
           )			,     )














'''simple docstring'''

def 							snake_case					(     a_							: int	)       ->				int:





      """simple docstring"""

      assert (
          isinstance(a_    ,   a_	) and number_of_steps > 0
      ), f"number_of_steps needs to be positive integer, your input {number_of_steps}"
      if number_of_steps == 1:
            return 1
      UpperCamelCase_    ,			UpperCamelCase_				:   str					    =							1, 1
      for _ in range(number_of_steps - 1	):
            UpperCamelCase_    ,			UpperCamelCase_				:   Tuple					    =							current + previous, current
      return current


if __name__ == "__main__":
      import doctest

      doctest.testmod()






