






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 ConvNextImageProcessor




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__=0.875      ,  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': 20}
         a_	    = parent
         a_	    = batch_size
         a_	    = num_channels
         a_	    = image_size
         a_	    = min_resolution
         a_	    = max_resolution
         a_	    = do_resize
         a_	    = size
         a_	    = crop_pct
         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,
             "crop_pct": self.crop_pct,
         }





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


  """simple docstring"""


  _a     :   int			 =    ConvNextImageProcessor if is_vision_available() else None







  def       _a					( self  ):






         """simple docstring"""


         a_	    = ConvNextImageProcessingTester(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(UpperCamelCase__      ,  'do_resize'  )  )
         self.assertTrue(hasattr(UpperCamelCase__      ,  'size'  )  )
         self.assertTrue(hasattr(UpperCamelCase__      ,  'crop_pct'  )  )
         self.assertTrue(hasattr(UpperCamelCase__      ,  'do_normalize'  )  )
         self.assertTrue(hasattr(UpperCamelCase__      ,  'image_mean'  )  )
         self.assertTrue(hasattr(UpperCamelCase__      ,  'image_std'  )  )







  def       _a					( self  ):






         """simple docstring"""


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

         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=UpperCamelCase__  )
         for image in image_inputs:
                self.assertIsInstance(UpperCamelCase__      ,  Image.Image  )

         # Test not batched input
         a_	    = 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.size['shortest_edge'],
                 self.image_processor_tester.size['shortest_edge'],
             )      ,  )

         # Test batched
         a_	    = 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.size['shortest_edge'],
                 self.image_processor_tester.size['shortest_edge'],
             )      ,  )







  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=UpperCamelCase__      ,  numpify=UpperCamelCase__  )
         for image in image_inputs:
                self.assertIsInstance(UpperCamelCase__      ,  np.ndarray  )

         # Test not batched input
         a_	    = 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.size['shortest_edge'],
                 self.image_processor_tester.size['shortest_edge'],
             )      ,  )

         # Test batched
         a_	    = 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.size['shortest_edge'],
                 self.image_processor_tester.size['shortest_edge'],
             )      ,  )







  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=UpperCamelCase__      ,  torchify=UpperCamelCase__  )
         for image in image_inputs:
                self.assertIsInstance(UpperCamelCase__      ,  torch.Tensor  )

         # Test not batched input
         a_	    = 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.size['shortest_edge'],
                 self.image_processor_tester.size['shortest_edge'],
             )      ,  )

         # Test batched
         a_	    = 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.size['shortest_edge'],
                 self.image_processor_tester.size['shortest_edge'],
             )      ,  )












'''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()




