






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



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



         """simple docstring"""





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



  def 		UpperCamelCase_				(      self				)			->			int:



         """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 ,		snake_case__=False ,		snake_case__=False ,		snake_case__=False				)			->			Any:



         """simple docstring"""





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

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

         if torchify:
                UpperCAmelCase	    =			[torch.from_numpy(__UpperCamelCase				) for x in image_inputs]

         return image_inputs





@require_torch
@require_vision
class   UpperCamelCase_ (       a_   ,					unittest.TestCase  ):
  _A       :					str				=	ChineseCLIPImageProcessor if is_vision_available() else None



  def 		UpperCamelCase_				(      self				)			->			Optional[int]:



         """simple docstring"""





         UpperCAmelCase	    =			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				)			->			Optional[Any]:



         """simple docstring"""





         UpperCAmelCase	    =			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				)			->			Any:



         """simple docstring"""





         UpperCAmelCase	    =			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	    =			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				)			->			List[str]:



         """simple docstring"""





         UpperCAmelCase	    =			self.image_processing_class(**self.image_processor_dict				)
         # create random PIL images
         UpperCAmelCase	    =			self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase				)
         for image in image_inputs:
                self.assertIsInstance(__UpperCamelCase ,		Image.Image				)

         # Test not batched input
         UpperCAmelCase	    =			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	    =			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"""





         UpperCAmelCase	    =			self.image_processing_class(**self.image_processor_dict				)
         # create random numpy tensors
         UpperCAmelCase	    =			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
         UpperCAmelCase	    =			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	    =			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				)			->			Optional[int]:



         """simple docstring"""





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



  def 		UpperCamelCase_				(      self				)			->			Optional[int]:



         """simple docstring"""





         UpperCAmelCase	    =			ChineseCLIPImageProcessingTester(self ,		num_channels=4 ,		do_center_crop=__UpperCamelCase				)
         UpperCAmelCase	    =			3



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



         """simple docstring"""





         return self.image_processor_tester.prepare_image_processor_dict()



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



         """simple docstring"""





         UpperCAmelCase	    =			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				)			->			Union[str, Any]:



         """simple docstring"""





         pass



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



         """simple docstring"""





         UpperCAmelCase	    =			self.image_processing_class(**self.image_processor_dict				)
         # create random PIL images
         UpperCAmelCase	    =			self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase				)
         for image in image_inputs:
                self.assertIsInstance(__UpperCamelCase ,		Image.Image				)

         # Test not batched input
         UpperCAmelCase	    =			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	    =			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 typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


lowerCAmelCase_	:    Optional[int]            =      {
    '''configuration_graphormer''': ['''GRAPHORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''GraphormerConfig'''],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCAmelCase_	:    str            =      [
     '''GRAPHORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''GraphormerForGraphClassification''',
     '''GraphormerModel''',
     '''GraphormerPreTrainedModel''',
 ]


if TYPE_CHECKING:
 from .configuration_graphormer import GRAPHORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, GraphormerConfig

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_graphormer import (
      GRAPHORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
      GraphormerForGraphClassification,
      GraphormerModel,
      GraphormerPreTrainedModel,
  )


else:
 import sys

 lowerCAmelCase_	:    Optional[Any]            =      _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
