


'''simple docstring'''







from collections import namedtuple

A      :     Any										= namedtuple('''from_to''', '''from_ to''')

A      :     Dict										= {
    '''atm''': from_to(1, 1),
    '''pascal''': from_to(0.0_00_00_98, 101325),
    '''bar''': from_to(0.98_69_23, 1.0_13_25),
    '''kilopascal''': from_to(0.00_98_69_23, 1_01.3_25),
    '''megapascal''': from_to(9.8_69_23, 0.10_13_25),
    '''psi''': from_to(0.06_80_46, 14.69_59),
    '''inHg''': from_to(0.0_33_42_11, 29.92_13),
    '''torr''': from_to(0.00_13_15_79, 760),
}






def       lowerCAmelCase__       (				lowerCamelCase     :			float  ,lowerCamelCase     :			str  ,lowerCamelCase     :			str   ):
       if from_type not in PRESSURE_CONVERSION:
              raise ValueError(
                  F'Invalid \'from_type\' value: {from_type!r}  Supported values are:\n'
                  + ', '.join(lowerCamelCase   )   )
       if to_type not in PRESSURE_CONVERSION:
              raise ValueError(
                  F'Invalid \'to_type\' value: {to_type!r}.  Supported values are:\n'
                  + ', '.join(lowerCamelCase   )   )
       return (
           value * PRESSURE_CONVERSION[from_type].from_ * PRESSURE_CONVERSION[to_type].to
       )


if __name__ == "__main__":
   import doctest

   doctest.testmod()










'''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 CLIPImageProcessor


class  __lowerCamelCase (       unittest.TestCase       ):
    """simple docstring"""


    def __init__(  self			:							Union[str, Any]      ,							SCREAMING_SNAKE_CASE			:							Any      ,							SCREAMING_SNAKE_CASE			:							List[str]=7      ,							SCREAMING_SNAKE_CASE			:							List[Any]=3      ,							SCREAMING_SNAKE_CASE			:							Dict=18      ,							SCREAMING_SNAKE_CASE			:							List[str]=30      ,							SCREAMING_SNAKE_CASE			:							List[Any]=400      ,							SCREAMING_SNAKE_CASE			:							int=True      ,							SCREAMING_SNAKE_CASE			:							Any=None      ,							SCREAMING_SNAKE_CASE			:							str=True      ,							SCREAMING_SNAKE_CASE			:							List[Any]=None      ,							SCREAMING_SNAKE_CASE			:							List[str]=True      ,							SCREAMING_SNAKE_CASE			:							Optional[int]=[0.4814_5466, 0.457_8275, 0.4082_1073]      ,							SCREAMING_SNAKE_CASE			:							Optional[Any]=[0.2686_2954, 0.2613_0258, 0.2757_7711]      ,							SCREAMING_SNAKE_CASE			:							Union[str, Any]=True      ,							):
           _A     :	List[Any]      =					size if size is not None else {'shortest_edge': 20}
           _A     :	List[Any]      =					crop_size if crop_size is not None else {'height': 18, 'width': 18}
           _A     :	Union[str, Any]      =					parent
           _A     :	Dict      =					batch_size
           _A     :	str      =					num_channels
           _A     :	int      =					image_size
           _A     :	Dict      =					min_resolution
           _A     :	Optional[Any]      =					max_resolution
           _A     :	int      =					do_resize
           _A     :	List[Any]      =					size
           _A     :	Any      =					do_center_crop
           _A     :	List[str]      =					crop_size
           _A     :	List[str]      =					do_normalize
           _A     :	Optional[int]      =					image_mean
           _A     :	Dict      =					image_std
           _A     :	Any      =					do_convert_rgb


    def    A    (  self			:							Tuple):
           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    A    (  self			:							Any      ,							SCREAMING_SNAKE_CASE			:							str=False      ,							SCREAMING_SNAKE_CASE			:							str=False      ,							SCREAMING_SNAKE_CASE			:							List[Any]=False):
           assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

           if torchify:
                  _A     :	Optional[Any]      =					[torch.from_numpy(SCREAMING_SNAKE_CASE) for x in image_inputs]

           return image_inputs




@require_torch
@require_vision
class  __lowerCamelCase (       a_				,					unittest.TestCase       ):
    """simple docstring"""
    a													=    CLIPImageProcessor if is_vision_available() else None


    def    A    (  self			:							Dict):
           _A     :	Tuple      =					CLIPImageProcessingTester(self)


    @property
    def    A    (  self			:							Any):
           return self.image_processor_tester.prepare_image_processor_dict()


    def    A    (  self			:							List[str]):
           _A     :	Optional[int]      =					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    A    (  self			:							Optional[int]):
           _A     :	Optional[Any]      =					self.image_processing_class.from_dict(self.image_processor_dict)
           self.assertEqual(image_processor.size      ,							{'shortest_edge': 20})
           self.assertEqual(image_processor.crop_size      ,							{'height': 18, 'width': 18})

           _A     :	Optional[int]      =					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    A    (  self			:							List[str]):
           pass


    def    A    (  self			:							Optional[int]):
           # Initialize image_processing
           _A     :	Any      =					self.image_processing_class(**self.image_processor_dict)
           # create random PIL images
           _A     :	List[Any]      =					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.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    A    (  self			:							Dict):
           # Initialize image_processing
           _A     :	Optional[int]      =					self.image_processing_class(**self.image_processor_dict)
           # create random numpy tensors
           _A     :	Tuple      =					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     :	Dict      =					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(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    A    (  self			:							str):
           # Initialize image_processing
           _A     :	Optional[Any]      =					self.image_processing_class(**self.image_processor_dict)
           # create random PyTorch tensors
           _A     :	Tuple      =					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     :	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     :	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'],
               )      ,							)




@require_torch
@require_vision
class  __lowerCamelCase (       a_				,					unittest.TestCase       ):
    """simple docstring"""
    a													=    CLIPImageProcessor if is_vision_available() else None


    def    A    (  self			:							int):
           _A     :	Union[str, Any]      =					CLIPImageProcessingTester(self      ,							num_channels=4)
           _A     :	Dict      =					3


    @property
    def    A    (  self			:							Any):
           return self.image_processor_tester.prepare_image_processor_dict()


    def    A    (  self			:							str):
           _A     :	str      =					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    A    (  self			:							str):
           pass


    def    A    (  self			:							int):
           # Initialize image_processing
           _A     :	List[Any]      =					self.image_processing_class(**self.image_processor_dict)
           # create random PIL images
           _A     :	Union[str, Any]      =					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.expected_encoded_image_num_channels,
                   self.image_processor_tester.crop_size['height'],
                   self.image_processor_tester.crop_size['width'],
               )      ,							)

           # Test batched
           _A     :	str      =					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'],
               )      ,							)






