

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

  def __init__(				self      , _SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE=7      , _SCREAMING_SNAKE_CASE=3      , _SCREAMING_SNAKE_CASE=18      , _SCREAMING_SNAKE_CASE=30      , _SCREAMING_SNAKE_CASE=4_00      , _SCREAMING_SNAKE_CASE=True      , _SCREAMING_SNAKE_CASE=None      , _SCREAMING_SNAKE_CASE=True      , _SCREAMING_SNAKE_CASE=None      , _SCREAMING_SNAKE_CASE=True      , _SCREAMING_SNAKE_CASE=[0.48_145_466, 0.4_578_275, 0.40_821_073]      , _SCREAMING_SNAKE_CASE=[0.26_862_954, 0.26_130_258, 0.27_577_711]      , _SCREAMING_SNAKE_CASE=True      , ):





      '''simple docstring'''

      lowerCAmelCase 						=							size if size is not None else {'height': 2_24, 'width': 2_24}
      lowerCAmelCase 						=							crop_size if crop_size is not None else {'height': 18, 'width': 18}
      lowerCAmelCase 						=							parent
      lowerCAmelCase 						=							batch_size
      lowerCAmelCase 						=							num_channels
      lowerCAmelCase 						=							image_size
      lowerCAmelCase 						=							min_resolution
      lowerCAmelCase 						=							max_resolution
      lowerCAmelCase 						=							do_resize
      lowerCAmelCase 						=							size
      lowerCAmelCase 						=							do_center_crop
      lowerCAmelCase 						=							crop_size
      lowerCAmelCase 						=							do_normalize
      lowerCAmelCase 						=							image_mean
      lowerCAmelCase 						=							image_std
      lowerCAmelCase 						=							do_convert_rgb

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''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   _SCREAMING_SNAKE_CASE				(				self      , _SCREAMING_SNAKE_CASE=False      , _SCREAMING_SNAKE_CASE=False      , _SCREAMING_SNAKE_CASE=False	):





      '''simple docstring'''

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

      if equal_resolution:
          lowerCAmelCase 						=							[]
          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:
          lowerCAmelCase 						=							[]
          for i in range(self.batch_size	):
              lowerCAmelCase						,   lowerCAmelCase 						=							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
          lowerCAmelCase 						=							[Image.fromarray(np.moveaxis(_SCREAMING_SNAKE_CASE      , 0      , -1	)	) for x in image_inputs]

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

      return image_inputs



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

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							ChineseCLIPImageProcessingTester(self      , do_center_crop=_SCREAMING_SNAKE_CASE	)

  @property
  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      return self.image_processor_tester.prepare_image_processor_dict()

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							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   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							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}	)

      lowerCAmelCase 						=							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   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      pass

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.image_processing_class(**self.image_processor_dict	)
      # create random PIL images
      lowerCAmelCase 						=							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
      lowerCAmelCase 						=							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
      lowerCAmelCase 						=							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   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.image_processing_class(**self.image_processor_dict	)
      # create random numpy tensors
      lowerCAmelCase 						=							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
      lowerCAmelCase 						=							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
      lowerCAmelCase 						=							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   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.image_processing_class(**self.image_processor_dict	)
      # create random PyTorch tensors
      lowerCAmelCase 						=							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
      lowerCAmelCase 						=							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
      lowerCAmelCase 						=							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 				_snake_case					(   a_     , unittest.TestCase			):
  SCREAMING_SNAKE_CASE			:       int				=     ChineseCLIPImageProcessor if is_vision_available() else None

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							ChineseCLIPImageProcessingTester(self      , num_channels=4      , do_center_crop=_SCREAMING_SNAKE_CASE	)
      lowerCAmelCase 						=							3

  @property
  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      return self.image_processor_tester.prepare_image_processor_dict()

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							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   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      pass


  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.image_processing_class(**self.image_processor_dict	)
      # create random PIL images
      lowerCAmelCase 						=							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
      lowerCAmelCase 						=							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
      lowerCAmelCase 						=							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)}")





