
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						:    int			,    _snake_case						:    Optional[int]			,    _snake_case						:    Optional[int]=7			,    _snake_case						:    Dict=3			,    _snake_case						:    Any=18			,    _snake_case						:    int=30			,    _snake_case						:    Any=400			,    _snake_case						:    Tuple=True			,    _snake_case						:    Optional[int]=None			,    _snake_case						:    Optional[Any]=True			,    _snake_case						:    Optional[int]=None			,    _snake_case						:    List[Any]=True			,    _snake_case						:    List[str]=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]			,    _snake_case						:    int=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]			,    _snake_case						:    Optional[Any]=True			,    ):
          __lowercase						:     List[Any]		      =    size if size is not None else {'''shortest_edge''': 20}
          __lowercase						:     Any		      =    crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
          __lowercase						:     Optional[int]		      =    parent
          __lowercase						:     List[str]		      =    batch_size
          __lowercase						:     Optional[Any]		      =    num_channels
          __lowercase						:     List[str]		      =    image_size
          __lowercase						:     Tuple		      =    min_resolution
          __lowercase						:     Any		      =    max_resolution
          __lowercase						:     str		      =    do_resize
          __lowercase						:     List[Any]		      =    size
          __lowercase						:     Tuple		      =    do_center_crop
          __lowercase						:     Tuple		      =    crop_size
          __lowercase						:     Any		      =    do_normalize
          __lowercase						:     Dict		      =    image_mean
          __lowercase						:     str		      =    image_std
          __lowercase						:     str		      =    do_convert_rgb




      def 						snake_case_     ( self						:    Optional[Any]			):
          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						:    str			,    _snake_case						:    Optional[int]=False			,    _snake_case						:    Dict=False			,    _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:
              __lowercase						:     int		      =    []
              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:
              __lowercase						:     List[Any]		      =    []
              for i in range(self.batch_size			):
                  __lowercase      , __lowercase						:     Union[str, 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
              __lowercase						:     Optional[int]		      =    [Image.fromarray(np.moveaxis(_snake_case			,    0			,    -1			)			) for x in image_inputs]

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

          return image_inputs






@require_torch
@require_vision
class   __lowerCAmelCase		(		lowerCAmelCase_	,	unittest.TestCase ):



      """simple docstring"""







      A__		:     str       				=      CLIPImageProcessor if is_vision_available() else None




      def 						snake_case_     ( self						:    List[Any]			):
          __lowercase						:     List[Any]		      =    CLIPImageProcessingTester(self			)




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




      def 						snake_case_     ( self						:    str			):
          __lowercase						:     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]			):
          __lowercase						:     Dict		      =    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}			)

          __lowercase						:     Tuple		      =    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						:    List[str]			):
          pass




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



      """simple docstring"""







      A__		:     Union[str, Any]       				=      CLIPImageProcessor if is_vision_available() else None




      def 						snake_case_     ( self						:    int			):
          __lowercase						:     Optional[Any]		      =    CLIPImageProcessingTester(self			,    num_channels=4			)
          __lowercase						:     List[Any]		      =    3




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




      def 						snake_case_     ( self						:    List[Any]			):
          __lowercase						:     str		      =    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[int]			):
          pass




      def 						snake_case_     ( self						:    Optional[int]			):
          # Initialize image_processing
          __lowercase						:     List[str]		      =    self.image_processing_class(**self.image_processor_dict			)
          # create random PIL images
          __lowercase						:     str		      =    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
          __lowercase						:     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
          __lowercase						:     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'''],
              )			,    )




from __future__ import annotations

import math
from itertools import permutations


def       UpperCAmelCase_					(  __lowerCAmelCase		)	->  bool:

    if 1 < number < 4:
        # 2 and 3 are primes
        return True
    elif number < 2 or number % 2 == 0 or number % 3 == 0:
        # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
        return False

    # All primes number are in format of 6k +/- 1
    for i in range(5		,   int(math.sqrt(__lowerCAmelCase		) + 1		)		,   6		):
        if number % i == 0 or number % (i + 2) == 0:
            return False
    return True


def       UpperCAmelCase_					(  __lowerCAmelCase = 7		)	->  int:
    __lowercase						:     Union[str, Any]		      =    ''''''.join(str(__lowerCAmelCase		) for i in range(1		,   n + 1		)		)
    __lowercase						:     Dict		      =    [int(''''''.join(__lowerCAmelCase		)		) for i in permutations(__lowerCAmelCase		,   __lowerCAmelCase		)]
    __lowercase						:     int		      =    [num for num in perm_list if is_prime(__lowerCAmelCase		)]
    return max(__lowerCAmelCase		) if pandigitals else 0


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


