





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





   def __init__( self					,			snake_case					,			snake_case=7					,			snake_case=3					,			snake_case=18					,			snake_case=30					,			snake_case=400					,			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					,			)				->  Any:
      """simple docstring"""





      a__	:						Dict      		=  size if size is not None else {"height": 224, "width": 224}
      a__	:						List[Any]      		=  crop_size if crop_size is not None else {"height": 18, "width": 18}
      a__	:						Optional[int]      		=  parent
      a__	:						Optional[Any]      		=  batch_size
      a__	:						List[str]      		=  num_channels
      a__	:						List[str]      		=  image_size
      a__	:						Dict      		=  min_resolution
      a__	:						List[str]      		=  max_resolution
      a__	:						str      		=  do_resize
      a__	:						Dict      		=  size
      a__	:						str      		=  do_center_crop
      a__	:						Optional[Any]      		=  crop_size
      a__	:						Union[str, Any]      		=  do_normalize
      a__	:						Optional[int]      		=  image_mean
      a__	:						Any      		=  image_std
      a__	:						Optional[Any]      		=  do_convert_rgb





   def 	_snake_case ( self      )				->  Optional[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 	_snake_case ( self					,			snake_case=False					,			snake_case=False					,			snake_case=False      )				->  Dict:
      """simple docstring"""





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

      if equal_resolution:
         a__	:						Dict      		=  []
         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:
         a__	:						List[Any]      		=  []
         for i in range(self.batch_size      ):
            a__	:						Tuple      		=  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
         a__	:						str      		=  [Image.fromarray(np.moveaxis(snake_case					,			0					,			-1      )      ) for x in image_inputs]

      if torchify:
         a__	:						Tuple      		=  [torch.from_numpy(snake_case      ) for x in image_inputs]

      return image_inputs







@require_torch
@require_vision
class   __lowerCAmelCase			(					_UpperCamelCase		,unittest.TestCase  ):
   _UpperCamelCase :						List[Any]     		=				ChineseCLIPImageProcessor if is_vision_available() else None





   def 	_snake_case ( self      )				->  Union[str, Any]:
      """simple docstring"""





      a__	:						List[Any]      		=  ChineseCLIPImageProcessingTester(self					,			do_center_crop=snake_case      )





   @property
   def 	_snake_case ( self      )				->  int:
      """simple docstring"""





      return self.image_processor_tester.prepare_image_processor_dict()





   def 	_snake_case ( self      )				->  Tuple:
      """simple docstring"""





      a__	:						Union[str, Any]      		=  self.image_processing_class(**self.image_processor_dict      )
      self.assertTrue(hasattr(snake_case					,			"do_resize"      )      )
      self.assertTrue(hasattr(snake_case					,			"size"      )      )
      self.assertTrue(hasattr(snake_case					,			"do_center_crop"      )      )
      self.assertTrue(hasattr(snake_case					,			"center_crop"      )      )
      self.assertTrue(hasattr(snake_case					,			"do_normalize"      )      )
      self.assertTrue(hasattr(snake_case					,			"image_mean"      )      )
      self.assertTrue(hasattr(snake_case					,			"image_std"      )      )
      self.assertTrue(hasattr(snake_case					,			"do_convert_rgb"      )      )





   def 	_snake_case ( self      )				->  Optional[Any]:
      """simple docstring"""





      a__	:						str      		=  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}      )

      a__	:						str      		=  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 	_snake_case ( self      )				->  Dict:
      """simple docstring"""





      pass





   def 	_snake_case ( self      )				->  Union[str, Any]:
      """simple docstring"""





      a__	:						Dict      		=  self.image_processing_class(**self.image_processor_dict      )
      # create random PIL images
      a__	:						Union[str, Any]      		=  self.image_processor_tester.prepare_inputs(equal_resolution=snake_case      )
      for image in image_inputs:
         self.assertIsInstance(snake_case					,			Image.Image      )

      # 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__	:						Tuple      		=  image_processing(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 	_snake_case ( self      )				->  List[Any]:
      """simple docstring"""





      a__	:						Dict      		=  self.image_processing_class(**self.image_processor_dict      )
      # create random numpy tensors
      a__	:						Optional[Any]      		=  self.image_processor_tester.prepare_inputs(equal_resolution=snake_case					,			numpify=snake_case      )
      for image in image_inputs:
         self.assertIsInstance(snake_case					,			np.ndarray      )

      # 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__	:						Dict      		=  image_processing(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 	_snake_case ( self      )				->  List[str]:
      """simple docstring"""





      a__	:						Optional[int]      		=  self.image_processing_class(**self.image_processor_dict      )
      # create random PyTorch tensors
      a__	:						Optional[Any]      		=  self.image_processor_tester.prepare_inputs(equal_resolution=snake_case					,			torchify=snake_case      )
      for image in image_inputs:
         self.assertIsInstance(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__	:						Dict      		=  image_processing(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   __lowerCAmelCase			(					_UpperCamelCase		,unittest.TestCase  ):
   _UpperCamelCase :						str     		=				ChineseCLIPImageProcessor if is_vision_available() else None





   def 	_snake_case ( self      )				->  List[Any]:
      """simple docstring"""





      a__	:						Any      		=  ChineseCLIPImageProcessingTester(self					,			num_channels=4					,			do_center_crop=snake_case      )
      a__	:						Any      		=  3





   @property
   def 	_snake_case ( self      )				->  List[str]:
      """simple docstring"""





      return self.image_processor_tester.prepare_image_processor_dict()





   def 	_snake_case ( self      )				->  Tuple:
      """simple docstring"""





      a__	:						Union[str, Any]      		=  self.image_processing_class(**self.image_processor_dict      )
      self.assertTrue(hasattr(snake_case					,			"do_resize"      )      )
      self.assertTrue(hasattr(snake_case					,			"size"      )      )
      self.assertTrue(hasattr(snake_case					,			"do_center_crop"      )      )
      self.assertTrue(hasattr(snake_case					,			"center_crop"      )      )
      self.assertTrue(hasattr(snake_case					,			"do_normalize"      )      )
      self.assertTrue(hasattr(snake_case					,			"image_mean"      )      )
      self.assertTrue(hasattr(snake_case					,			"image_std"      )      )
      self.assertTrue(hasattr(snake_case					,			"do_convert_rgb"      )      )





   def 	_snake_case ( self      )				->  List[str]:
      """simple docstring"""





      pass





   def 	_snake_case ( self      )				->  Any:
      """simple docstring"""





      a__	:						Union[str, Any]      		=  self.image_processing_class(**self.image_processor_dict      )
      # create random PIL images
      a__	:						Optional[Any]      		=  self.image_processor_tester.prepare_inputs(equal_resolution=snake_case      )
      for image in image_inputs:
         self.assertIsInstance(snake_case					,			Image.Image      )

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






SCREAMING_SNAKE_CASE__       :			Union[str, Any]			      =						9.80665






def       _A  (      lowerCamelCase							, lowerCamelCase							, lowerCamelCase = g   ):

   if fluid_density <= 0:
      raise ValueError("Impossible fluid density"   )
   if volume < 0:
      raise ValueError("Impossible Object volume"   )
   if gravity <= 0:
      raise ValueError("Impossible Gravity"   )

   return fluid_density * gravity * volume


if __name__ == "__main__":
  import doctest

  # run doctest
  doctest.testmod()

