





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 LevitImageProcessor




class 			__UpperCamelCase    (							unittest.TestCase    ):





     def __init__(     self				,							_UpperCamelCase				,							_UpperCamelCase=7				,							_UpperCamelCase=3				,							_UpperCamelCase=18				,							_UpperCamelCase=30				,							_UpperCamelCase=400				,							_UpperCamelCase=True				,							_UpperCamelCase=None				,							_UpperCamelCase=True				,							_UpperCamelCase=None				,							_UpperCamelCase=True				,							_UpperCamelCase=[0.5, 0.5, 0.5]				,							_UpperCamelCase=[0.5, 0.5, 0.5]				,							):
        _UpperCAmelCase           =   size if size is not None else {'''shortest_edge''': 18}
        _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





     def 		UpperCamelCase(     self					):
        return {
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_normalize": self.do_normalize,
            "do_resize": self.do_resize,
            "do_center_crop": self.do_center_crop,
            "size": self.size,
            "crop_size": self.crop_size,
        }




@require_torch
@require_vision
class 			__UpperCamelCase    (							A__	, unittest.TestCase    ):
     __A	:  int							  =   LevitImageProcessor if is_vision_available() else None





     def 		UpperCamelCase(     self					):
        _UpperCAmelCase           =   LevitImageProcessingTester(self					)





     @property
     def 		UpperCamelCase(     self					):
        return self.image_processor_tester.prepare_image_processor_dict()





     def 		UpperCamelCase(     self					):
        _UpperCAmelCase           =   self.image_processing_class(**self.image_processor_dict					)
        self.assertTrue(hasattr(_UpperCamelCase				,							'''image_mean'''					)					)
        self.assertTrue(hasattr(_UpperCamelCase				,							'''image_std'''					)					)
        self.assertTrue(hasattr(_UpperCamelCase				,							'''do_normalize'''					)					)
        self.assertTrue(hasattr(_UpperCamelCase				,							'''do_resize'''					)					)
        self.assertTrue(hasattr(_UpperCamelCase				,							'''do_center_crop'''					)					)
        self.assertTrue(hasattr(_UpperCamelCase				,							'''size'''					)					)





     def 		UpperCamelCase(     self					):
        _UpperCAmelCase           =   self.image_processing_class.from_dict(self.image_processor_dict					)
        self.assertEqual(image_processor.size				,							{'''shortest_edge''': 18}					)
        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					):
        pass





     def 		UpperCamelCase(     self					):
        # Initialize image_processing
        _UpperCAmelCase           =   self.image_processing_class(**self.image_processor_dict					)
        # create random PIL images
        _UpperCAmelCase           =   prepare_image_inputs(self.image_processor_tester				,							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					):
        # Initialize image_processing
        _UpperCAmelCase           =   self.image_processing_class(**self.image_processor_dict					)
        # create random numpy tensors
        _UpperCAmelCase           =   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
        _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					):
        # Initialize image_processing
        _UpperCAmelCase           =   self.image_processing_class(**self.image_processor_dict					)
        # create random PyTorch tensors
        _UpperCAmelCase           =   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
        _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'''],
            )				,							)






from __future__ import annotations
def      A__       (    SCREAMING_SNAKE_CASE_   :      int						)  ->  bool:






   """simple docstring"""







   _UpperCAmelCase           =   str(SCREAMING_SNAKE_CASE_						)
   return len(SCREAMING_SNAKE_CASE_						) == 9 and set(SCREAMING_SNAKE_CASE_						) == set('''123456789'''						)
def      A__       (    )  ->  int | None:






   """simple docstring"""







   for base_num in range(99_99				,	49_99				,	-1						):
      _UpperCAmelCase           =   10_00_02 * base_num
      if is_9_pandigital(SCREAMING_SNAKE_CASE_						):
         return candidate

   for base_num in range(3_33				,	99				,	-1						):
      _UpperCAmelCase           =   1_00_20_03 * base_num
      if is_9_pandigital(SCREAMING_SNAKE_CASE_						):
         return candidate

   return None


if __name__ == "__main__":
   print(f'''{solution() = }''')