


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






      def __init__(					self     :Any	,		SCREAMING_SNAKE_CASE     :List[str]	,		SCREAMING_SNAKE_CASE     :Tuple=7	,		SCREAMING_SNAKE_CASE     :str=3	,		SCREAMING_SNAKE_CASE     :int=1_8	,		SCREAMING_SNAKE_CASE     :str=3_0	,		SCREAMING_SNAKE_CASE     :int=4_0_0	,		SCREAMING_SNAKE_CASE     :Tuple=True	,		SCREAMING_SNAKE_CASE     :Union[str, Any]=None	,		SCREAMING_SNAKE_CASE     :List[Any]=True	,		SCREAMING_SNAKE_CASE     :List[str]=None	,		SCREAMING_SNAKE_CASE     :Union[str, Any]=True	,		SCREAMING_SNAKE_CASE     :Optional[Any]=[0.48_145_466, 0.4_578_275, 0.40_821_073]	,		SCREAMING_SNAKE_CASE     :Union[str, Any]=[0.26_862_954, 0.26_130_258, 0.27_577_711]	,		SCREAMING_SNAKE_CASE     :str=True	,		)			->   Tuple:




             '''simple docstring'''
             _a       :					Optional[int]	   =size if size is not None else {"""height""": 2_2_4, """width""": 2_2_4}
             _a       :					Union[str, Any]	   =crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}
             _a       :					Dict	   =parent
             _a       :					Union[str, Any]	   =batch_size
             _a       :					Any	   =num_channels
             _a       :					Tuple	   =image_size
             _a       :					List[Any]	   =min_resolution
             _a       :					Any	   =max_resolution
             _a       :					List[Any]	   =do_resize
             _a       :					List[Any]	   =size
             _a       :					Dict	   =do_center_crop
             _a       :					List[str]	   =crop_size
             _a       :					int	   =do_normalize
             _a       :					List[str]	   =image_mean
             _a       :					str	   =image_std
             _a       :					Dict	   =do_convert_rgb






      def __UpperCAmelCase			(					self     :List[str]      )			->   List[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[Any]	,		SCREAMING_SNAKE_CASE     :Optional[int]=False	,		SCREAMING_SNAKE_CASE     :Tuple=False	,		SCREAMING_SNAKE_CASE     :str=False      )			->   List[str]:




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

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

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

             if torchify:
                    _a       :					Any	   =[torch.from_numpy(_SCREAMING_SNAKE_CASE      ) for x in image_inputs]

             return image_inputs







@require_torch
@require_vision
class A__			(		a_					,	unittest.TestCase ):
      __UpperCamelCase			:    Tuple      			=				ChineseCLIPImageProcessor if is_vision_available() else None






      def __UpperCAmelCase			(					self     :str      )			->   Tuple:




             '''simple docstring'''
             _a       :					Tuple	   =ChineseCLIPImageProcessingTester(self	,		do_center_crop=_SCREAMING_SNAKE_CASE      )






      @property
      def __UpperCAmelCase			(					self     :Optional[int]      )			->   List[str]:




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






      def __UpperCAmelCase			(					self     :str      )			->   int:




             '''simple docstring'''
             _a       :					Dict	   =self.image_processing_class(**self.image_processor_dict      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""do_resize"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""size"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""do_center_crop"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""center_crop"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""do_normalize"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""image_mean"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""image_std"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""do_convert_rgb"""      )      )






      def __UpperCAmelCase			(					self     :Tuple      )			->   List[Any]:




             '''simple docstring'''
             _a       :					List[str]	   =self.image_processing_class.from_dict(self.image_processor_dict      )
             self.assertEqual(image_processor.size	,		{"""height""": 2_2_4, """width""": 2_2_4}      )
             self.assertEqual(image_processor.crop_size	,		{"""height""": 1_8, """width""": 1_8}      )

             _a       :					List[Any]	   =self.image_processing_class.from_dict(self.image_processor_dict	,		size=4_2	,		crop_size=8_4      )
             self.assertEqual(image_processor.size	,		{"""shortest_edge""": 4_2}      )
             self.assertEqual(image_processor.crop_size	,		{"""height""": 8_4, """width""": 8_4}      )






      def __UpperCAmelCase			(					self     :Tuple      )			->   List[Any]:




             '''simple docstring'''
             pass






      def __UpperCAmelCase			(					self     :Tuple      )			->   int:




             '''simple docstring'''
             _a       :					int	   =self.image_processing_class(**self.image_processor_dict      )
             # create random PIL images
             _a       :					List[str]	   =self.image_processor_tester.prepare_inputs(equal_resolution=_SCREAMING_SNAKE_CASE      )
             for image in image_inputs:
                    self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		Image.Image      )

             # Test not batched input
             _a       :					int	   =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       :					List[str]	   =image_processing(_SCREAMING_SNAKE_CASE	,		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      )			->   Union[str, Any]:




             '''simple docstring'''
             _a       :					int	   =self.image_processing_class(**self.image_processor_dict      )
             # create random numpy tensors
             _a       :					Any	   =self.image_processor_tester.prepare_inputs(equal_resolution=_SCREAMING_SNAKE_CASE	,		numpify=_SCREAMING_SNAKE_CASE      )
             for image in image_inputs:
                    self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		np.ndarray      )

             # Test not batched input
             _a       :					Tuple	   =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       :					Union[str, Any]	   =image_processing(_SCREAMING_SNAKE_CASE	,		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     :Optional[int]      )			->   Any:




             '''simple docstring'''
             _a       :					str	   =self.image_processing_class(**self.image_processor_dict      )
             # create random PyTorch tensors
             _a       :					List[Any]	   =self.image_processor_tester.prepare_inputs(equal_resolution=_SCREAMING_SNAKE_CASE	,		torchify=_SCREAMING_SNAKE_CASE      )
             for image in image_inputs:
                    self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		torch.Tensor      )

             # Test not batched input
             _a       :					Optional[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
             _a       :					Optional[Any]	   =image_processing(_SCREAMING_SNAKE_CASE	,		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__			(		a_					,	unittest.TestCase ):
      __UpperCamelCase			:    int      			=				ChineseCLIPImageProcessor if is_vision_available() else None






      def __UpperCAmelCase			(					self     :Optional[int]      )			->   Union[str, Any]:




             '''simple docstring'''
             _a       :					Any	   =ChineseCLIPImageProcessingTester(self	,		num_channels=4	,		do_center_crop=_SCREAMING_SNAKE_CASE      )
             _a       :					List[Any]	   =3






      @property
      def __UpperCAmelCase			(					self     :Tuple      )			->   List[str]:




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






      def __UpperCAmelCase			(					self     :List[str]      )			->   Tuple:




             '''simple docstring'''
             _a       :					Any	   =self.image_processing_class(**self.image_processor_dict      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""do_resize"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""size"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""do_center_crop"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""center_crop"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""do_normalize"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""image_mean"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""image_std"""      )      )
             self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		"""do_convert_rgb"""      )      )






      def __UpperCAmelCase			(					self     :Tuple      )			->   List[Any]:




             '''simple docstring'''
             pass






      def __UpperCAmelCase			(					self     :Dict      )			->   str:




             '''simple docstring'''
             _a       :					Union[str, Any]	   =self.image_processing_class(**self.image_processor_dict      )
             # create random PIL images
             _a       :					Tuple	   =self.image_processor_tester.prepare_inputs(equal_resolution=_SCREAMING_SNAKE_CASE      )
             for image in image_inputs:
                    self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		Image.Image      )

             # Test not batched input
             _a       :					List[str]	   =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
             _a       :					int	   =image_processing(_SCREAMING_SNAKE_CASE	,		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   (	snake_case      : dict			) ->  set:


    """simple docstring"""


    lowerCAmelCase 						=							set()
    # edges = list of graph's edges
    lowerCAmelCase 						=							get_edges(snake_case			)

    # While there are still elements in edges list, take an arbitrary edge
    # (from_node, to_node) and add his extremity to chosen_vertices and then
    # remove all arcs adjacent to the from_node and to_node
    while edges:
        lowerCAmelCase						,   lowerCAmelCase 						=							edges.pop()
        chosen_vertices.add(snake_case			)
        chosen_vertices.add(snake_case			)
        for edge in edges.copy():
            if from_node in edge or to_node in edge:
                edges.discard(snake_case			)
    return chosen_vertices


def       snake_case   (	snake_case      : dict			) ->  set:


    """simple docstring"""


    lowerCAmelCase 						=							set()
    for from_node, to_nodes in graph.items():
        for to_node in to_nodes:
            edges.add((from_node, to_node)			)
    return edges


if __name__ == "__main__":
     import doctest

     doctest.testmod()

     # graph = {0: [1, 3], 1: [0, 3], 2: [0, 3, 4], 3: [0, 1, 2], 4: [2, 3]}
     # print(f"Matching vertex cover:\n{matching_min_vertex_cover(graph)}")





