






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, prepare_image_inputs


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import ViltImageProcessor




class      __SCREAMING_SNAKE_CASE					(unittest.TestCase					):


  """simple docstring"""


  def __init__( self      ,  UpperCamelCase__      ,  UpperCamelCase__=7      ,  UpperCamelCase__=3      ,  UpperCamelCase__=18      ,  UpperCamelCase__=30      ,  UpperCamelCase__=400      ,  UpperCamelCase__=True      ,  UpperCamelCase__=None      ,  UpperCamelCase__=2      ,  UpperCamelCase__=True      ,  UpperCamelCase__=[0.5, 0.5, 0.5]      ,  UpperCamelCase__=[0.5, 0.5, 0.5]      ,  ):






         """simple docstring"""


         a_	    = size if size is not None else {'shortest_edge': 30}
         a_	    = parent
         a_	    = batch_size
         a_	    = num_channels
         a_	    = image_size
         a_	    = min_resolution
         a_	    = max_resolution
         a_	    = do_resize
         a_	    = size
         a_	    = size_divisor
         a_	    = do_normalize
         a_	    = image_mean
         a_	    = image_std







  def       _a					( self  ):






         """simple docstring"""


         return {
             "image_mean": self.image_mean,
             "image_std": self.image_std,
             "do_normalize": self.do_normalize,
             "do_resize": self.do_resize,
             "size": self.size,
             "size_divisor": self.size_divisor,
         }







  def       _a					( self      ,  UpperCamelCase__      ,  UpperCamelCase__=False  ):






         """simple docstring"""


         if not batched:
                a_	    = self.size['shortest_edge']
                a_	    = image_inputs[0]
                if isinstance(__SCREAMING_SNAKE_CASE      ,  Image.Image  ):
                       a_    ,  a_	    = image.size
                else:
                       a_    ,  a_	    = image.shape[1], image.shape[2]
                a_	    = size / min(__SCREAMING_SNAKE_CASE      ,  __SCREAMING_SNAKE_CASE  )
                if h < w:
                       a_    ,  a_	    = size, scale * w
                else:
                       a_    ,  a_	    = scale * h, size

                a_	    = int((1_333 / 800) * size  )
                if max(__SCREAMING_SNAKE_CASE      ,  __SCREAMING_SNAKE_CASE  ) > max_size:
                       a_	    = max_size / max(__SCREAMING_SNAKE_CASE      ,  __SCREAMING_SNAKE_CASE  )
                       a_	    = newh * scale
                       a_	    = neww * scale

                a_    ,  a_	    = int(newh + 0.5  ), int(neww + 0.5  )
                a_    ,  a_	    = (
                    newh // self.size_divisor * self.size_divisor,
                    neww // self.size_divisor * self.size_divisor,
                )

         else:
                a_	    = []
                for image in image_inputs:
                       a_    ,  a_	    = self.get_expected_values([image]  )
                       expected_values.append((expected_height, expected_width)  )
                a_	    = max(__SCREAMING_SNAKE_CASE      ,  key=lambda UpperCamelCase__  : item[0]  )[0]
                a_	    = max(__SCREAMING_SNAKE_CASE      ,  key=lambda UpperCamelCase__  : item[1]  )[1]

         return expected_height, expected_width





@require_torch
@require_vision
class      __SCREAMING_SNAKE_CASE					(UpperCamelCase_       ,					unittest.TestCase					):


  """simple docstring"""


  _a     :   Tuple			 =    ViltImageProcessor if is_vision_available() else None







  def       _a					( self  ):






         """simple docstring"""


         a_	    = ViltImageProcessingTester(self  )







  @property
  def       _a					( self  ):






         """simple docstring"""


         return self.image_processor_tester.prepare_image_processor_dict()







  def       _a					( self  ):






         """simple docstring"""


         a_	    = self.image_processing_class(**self.image_processor_dict  )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,  'image_mean'  )  )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,  'image_std'  )  )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,  'do_normalize'  )  )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,  'do_resize'  )  )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,  'size'  )  )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,  'size_divisor'  )  )







  def       _a					( self  ):






         """simple docstring"""


         a_	    = self.image_processing_class.from_dict(self.image_processor_dict  )
         self.assertEqual(image_processor.size      ,  {'shortest_edge': 30}  )

         a_	    = self.image_processing_class.from_dict(self.image_processor_dict      ,  size=42  )
         self.assertEqual(image_processor.size      ,  {'shortest_edge': 42}  )







  def       _a					( self  ):






         """simple docstring"""


         pass







  def       _a					( self  ):






         """simple docstring"""


         a_	    = self.image_processing_class(**self.image_processor_dict  )
         # create random PIL images
         a_	    = prepare_image_inputs(self.image_processor_tester      ,  equal_resolution=__SCREAMING_SNAKE_CASE  )
         for image in image_inputs:
                self.assertIsInstance(__SCREAMING_SNAKE_CASE      ,  Image.Image  )

         # Test not batched input
         a_	    = image_processing(image_inputs[0]      ,  return_tensors='pt'  ).pixel_values

         a_    ,  a_	    = self.image_processor_tester.get_expected_values(__SCREAMING_SNAKE_CASE  )
         self.assertEqual(
             encoded_images.shape      ,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)      ,  )

         # Test batched
         a_	    = image_processing(__SCREAMING_SNAKE_CASE      ,  return_tensors='pt'  ).pixel_values

         a_    ,  a_	    = self.image_processor_tester.get_expected_values(__SCREAMING_SNAKE_CASE      ,  batched=__SCREAMING_SNAKE_CASE  )
         self.assertEqual(
             encoded_images.shape      ,  (
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 expected_height,
                 expected_width,
             )      ,  )







  def       _a					( self  ):






         """simple docstring"""


         a_	    = self.image_processing_class(**self.image_processor_dict  )
         # create random numpy tensors
         a_	    = prepare_image_inputs(self.image_processor_tester      ,  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_	    = image_processing(image_inputs[0]      ,  return_tensors='pt'  ).pixel_values

         a_    ,  a_	    = self.image_processor_tester.get_expected_values(__SCREAMING_SNAKE_CASE  )
         self.assertEqual(
             encoded_images.shape      ,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)      ,  )

         # Test batched
         a_	    = image_processing(__SCREAMING_SNAKE_CASE      ,  return_tensors='pt'  ).pixel_values

         a_    ,  a_	    = self.image_processor_tester.get_expected_values(__SCREAMING_SNAKE_CASE      ,  batched=__SCREAMING_SNAKE_CASE  )
         self.assertEqual(
             encoded_images.shape      ,  (
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 expected_height,
                 expected_width,
             )      ,  )







  def       _a					( self  ):






         """simple docstring"""


         a_	    = self.image_processing_class(**self.image_processor_dict  )
         # create random PyTorch tensors
         a_	    = prepare_image_inputs(self.image_processor_tester      ,  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_	    = image_processing(image_inputs[0]      ,  return_tensors='pt'  ).pixel_values

         a_    ,  a_	    = self.image_processor_tester.get_expected_values(__SCREAMING_SNAKE_CASE  )
         self.assertEqual(
             encoded_images.shape      ,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)      ,  )

         # Test batched
         a_	    = image_processing(__SCREAMING_SNAKE_CASE      ,  return_tensors='pt'  ).pixel_values

         a_    ,  a_	    = self.image_processor_tester.get_expected_values(__SCREAMING_SNAKE_CASE      ,  batched=__SCREAMING_SNAKE_CASE  )
         self.assertEqual(
             encoded_images.shape      ,  (
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 expected_height,
                 expected_width,
             )      ,  )












'''simple docstring'''







def 			__UpperCamelCase				(			lowercase_					:     int      ):
       """simple docstring"""




       if not isinstance(lowercase_      ,					lowercase_      ):
              raise ValueError('double_factorial() only accepts integral values'      )
       if num < 0:
              raise ValueError('double_factorial() not defined for negative values'      )
       a_	    = 1
       for i in range(lowercase_      ,					0      ,					-2      ):
              value *= i
       return value


if __name__ == "__main__":
  import doctest

  doctest.testmod()




