


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





      '''simple docstring'''






      def __init__(self    :    Dict   ,						UpperCamelCase    :    str   ,						UpperCamelCase    :    Union[str, Any]=7   ,						UpperCamelCase    :    Optional[int]=3   ,						UpperCamelCase    :    Optional[int]=18   ,						UpperCamelCase    :    List[Any]=30   ,						UpperCamelCase    :    Dict=400   ,						UpperCamelCase    :    Dict=True   ,						UpperCamelCase    :    Optional[Any]=None   ,						UpperCamelCase    :    List[Any]=True   ,						UpperCamelCase    :    int=None   ,						UpperCamelCase    :    Optional[int]=True   ,						UpperCamelCase    :    Union[str, Any]=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]   ,						UpperCamelCase    :    Union[str, Any]=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]   ,						UpperCamelCase    :    Union[str, Any]=True   ,						):

             '''simple docstring'''







             lowercase__      			= size if size is not None else {'''height''': 224, '''width''': 224}
             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
             lowercase__      			= do_normalize
             lowercase__      			= image_mean
             lowercase__      			= image_std
             lowercase__      			= do_convert_rgb



      def       UpperCamelCase__		(self    :    Optional[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_normalize": self.do_normalize,
                 "image_mean": self.image_mean,
                 "image_std": self.image_std,
                 "do_convert_rgb": self.do_convert_rgb,
             }






      def       UpperCamelCase__		(self    :    List[str]   ,						UpperCamelCase    :    Dict=False   ,						UpperCamelCase    :    Optional[int]=False   ,						UpperCamelCase    :    Tuple=False ):

             '''simple docstring'''







             assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

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

             if torchify:
                    lowercase__      			= [torch.from_numpy(UpperCamelCase ) for x in image_inputs]

             return image_inputs






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





      '''simple docstring'''






      lowerCAmelCase__					:     str  					=							ChineseCLIPImageProcessor if is_vision_available() else None



      def       UpperCamelCase__		(self    :    Tuple ):

             '''simple docstring'''







             lowercase__      			= ChineseCLIPImageProcessingTester(self   ,						do_center_crop=UpperCamelCase )



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

             '''simple docstring'''







             return self.image_processor_tester.prepare_image_processor_dict()



      def       UpperCamelCase__		(self    :    str ):

             '''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''' ) )
             self.assertTrue(hasattr(UpperCamelCase   ,						'''do_normalize''' ) )
             self.assertTrue(hasattr(UpperCamelCase   ,						'''image_mean''' ) )
             self.assertTrue(hasattr(UpperCamelCase   ,						'''image_std''' ) )
             self.assertTrue(hasattr(UpperCamelCase   ,						'''do_convert_rgb''' ) )



      def       UpperCamelCase__		(self    :    Tuple ):

             '''simple docstring'''







             lowercase__      			= self.image_processing_class.from_dict(self.image_processor_dict )
             self.assertEqual(image_processor.size   ,						{'''height''': 224, '''width''': 224} )
             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    :    Dict ):

             '''simple docstring'''







             pass



      def       UpperCamelCase__		(self    :    Any ):

             '''simple docstring'''







             lowercase__      			= self.image_processing_class(**self.image_processor_dict )
             # create random PIL images
             lowercase__      			= self.image_processor_tester.prepare_inputs(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    :    Any ):

             '''simple docstring'''







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

             '''simple docstring'''







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






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





      '''simple docstring'''






      lowerCAmelCase__					:     List[Any]  					=							ChineseCLIPImageProcessor if is_vision_available() else None



      def       UpperCamelCase__		(self    :    Optional[int] ):

             '''simple docstring'''







             lowercase__      			= ChineseCLIPImageProcessingTester(self   ,						num_channels=4   ,						do_center_crop=UpperCamelCase )
             lowercase__      			= 3



      @property
      def       UpperCamelCase__		(self    :    int ):

             '''simple docstring'''







             return self.image_processor_tester.prepare_image_processor_dict()



      def       UpperCamelCase__		(self    :    int ):

             '''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''' ) )
             self.assertTrue(hasattr(UpperCamelCase   ,						'''do_normalize''' ) )
             self.assertTrue(hasattr(UpperCamelCase   ,						'''image_mean''' ) )
             self.assertTrue(hasattr(UpperCamelCase   ,						'''image_std''' ) )
             self.assertTrue(hasattr(UpperCamelCase   ,						'''do_convert_rgb''' ) )



      def       UpperCamelCase__		(self    :    Optional[int] ):

             '''simple docstring'''







             pass






      def       UpperCamelCase__		(self    :    Tuple ):

             '''simple docstring'''







             lowercase__      			= self.image_processing_class(**self.image_processor_dict )
             # create random PIL images
             lowercase__      			= self.image_processor_tester.prepare_inputs(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.expected_encoded_image_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.expected_encoded_image_num_channels,
                     self.image_processor_tester.crop_size['''height'''],
                     self.image_processor_tester.crop_size['''width'''],
                 )   ,						)








'''simple docstring'''

from __future__ import annotations

def _SCREAMING_SNAKE_CASE      (A  , A       )       ->       list[list[int]]:






       """simple docstring"""







       lowercase__      			= []
       create_all_state(1  , A  , A  , []  , A       )
       return result

def _SCREAMING_SNAKE_CASE      (A  , A  , A  , A  , A  , )       ->       None:






       """simple docstring"""







       if level == 0:
              total_list.append(current_list[:]       )
              return

       for i in range(A  , total_number - level + 2       ):
              current_list.append(A       )
              create_all_state(i + 1  , A  , level - 1  , A  , A       )
              current_list.pop()

def _SCREAMING_SNAKE_CASE      (A       )       ->       None:






       """simple docstring"""







       for i in total_list:
              print(*A       )


if __name__ == "__main__":
 lowerCamelCase							:   Tuple  						=	4
 lowerCamelCase							:   Union[str, Any]  						=	2
 lowerCamelCase							:   Dict  						=	generate_all_combinations(n, k)
 print_all_state(total_list)




