


'''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, prepare_video_inputs


if is_torch_available():
       import torch

if is_vision_available():
       from PIL import Image

       from transformers import VivitImageProcessor
class 						UpperCamelCase__       (			unittest.TestCase						):



     """simple docstring"""






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

            '''simple docstring'''

            _lowerCAmelCase     :				List[Any]       =							size if size is not None else {'shortest_edge': 18}
            _lowerCAmelCase     :				str       =							crop_size if crop_size is not None else {'height': 18, 'width': 18}

            _lowerCAmelCase     :				str       =							parent
            _lowerCAmelCase     :				Any       =							batch_size
            _lowerCAmelCase     :				Union[str, Any]       =							num_channels
            _lowerCAmelCase     :				Union[str, Any]       =							num_frames
            _lowerCAmelCase     :				List[str]       =							image_size
            _lowerCAmelCase     :				Union[str, Any]       =							min_resolution
            _lowerCAmelCase     :				str       =							max_resolution
            _lowerCAmelCase     :				Union[str, Any]       =							do_resize
            _lowerCAmelCase     :				List[str]       =							size
            _lowerCAmelCase     :				Any       =							do_normalize
            _lowerCAmelCase     :				List[str]       =							image_mean
            _lowerCAmelCase     :				Optional[Any]       =							image_std
            _lowerCAmelCase     :				Dict       =							crop_size







     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_size": self.crop_size,
            }
@require_torch
@require_vision
class 						UpperCamelCase__       (			_UpperCAmelCase     ,       unittest.TestCase						):



     """simple docstring"""






     __magic_name__           =     VivitImageProcessor if is_vision_available() else None







     def a						(			self ):

            '''simple docstring'''

            _lowerCAmelCase     :				Tuple       =							VivitImageProcessingTester(self )







     @property
     def a						(			self ):

            '''simple docstring'''

            return self.image_processor_tester.prepare_image_processor_dict()







     def a						(			self ):

            '''simple docstring'''

            _lowerCAmelCase     :				Any       =							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 a						(			self ):

            '''simple docstring'''

            _lowerCAmelCase     :				Optional[int]       =							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} )

            _lowerCAmelCase     :				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 a						(			self ):

            '''simple docstring'''

            _lowerCAmelCase     :				str       =							self.image_processing_class(**self.image_processor_dict )
            # create random PIL videos
            _lowerCAmelCase     :				Any       =							prepare_video_inputs(self.image_processor_tester   ,						equal_resolution=__UpperCamelCase )
            for video in video_inputs:
                   self.assertIsInstance(__UpperCamelCase   ,						__UpperCamelCase )
                   self.assertIsInstance(video[0]   ,						Image.Image )

            # Test not batched input
            _lowerCAmelCase     :				Optional[int]       =							image_processing(video_inputs[0]   ,						return_tensors='pt' ).pixel_values
            self.assertEqual(
                encoded_videos.shape   ,						(
                    1,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )   ,						)

            # Test batched
            _lowerCAmelCase     :				Optional[int]       =							image_processing(__UpperCamelCase   ,						return_tensors='pt' ).pixel_values
            self.assertEqual(
                encoded_videos.shape   ,						(
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )   ,						)







     def a						(			self ):

            '''simple docstring'''

            _lowerCAmelCase     :				Optional[int]       =							self.image_processing_class(**self.image_processor_dict )
            # create random numpy tensors
            _lowerCAmelCase     :				Optional[Any]       =							prepare_video_inputs(self.image_processor_tester   ,						equal_resolution=__UpperCamelCase   ,						numpify=__UpperCamelCase )
            for video in video_inputs:
                   self.assertIsInstance(__UpperCamelCase   ,						__UpperCamelCase )
                   self.assertIsInstance(video[0]   ,						np.ndarray )

            # Test not batched input
            _lowerCAmelCase     :				Optional[Any]       =							image_processing(video_inputs[0]   ,						return_tensors='pt' ).pixel_values
            self.assertEqual(
                encoded_videos.shape   ,						(
                    1,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )   ,						)

            # Test batched
            _lowerCAmelCase     :				str       =							image_processing(__UpperCamelCase   ,						return_tensors='pt' ).pixel_values
            self.assertEqual(
                encoded_videos.shape   ,						(
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )   ,						)







     def a						(			self ):

            '''simple docstring'''

            _lowerCAmelCase     :				Tuple       =							self.image_processing_class(**self.image_processor_dict )
            # create random PyTorch tensors
            _lowerCAmelCase     :				Union[str, Any]       =							prepare_video_inputs(self.image_processor_tester   ,						equal_resolution=__UpperCamelCase   ,						torchify=__UpperCamelCase )
            for video in video_inputs:
                   self.assertIsInstance(__UpperCamelCase   ,						__UpperCamelCase )
                   self.assertIsInstance(video[0]   ,						torch.Tensor )

            # Test not batched input
            _lowerCAmelCase     :				Dict       =							image_processing(video_inputs[0]   ,						return_tensors='pt' ).pixel_values
            self.assertEqual(
                encoded_videos.shape   ,						(
                    1,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )   ,						)

            # Test batched
            _lowerCAmelCase     :				List[Any]       =							image_processing(__UpperCamelCase   ,						return_tensors='pt' ).pixel_values
            self.assertEqual(
                encoded_videos.shape   ,						(
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )   ,						)



"""simple docstring"""



import math
import unittest


def 			_UpperCamelCase						(    _A   )     ->	bool:





    """simple docstring"""

    assert isinstance(_A       ,   _A   ) and (
        number >= 0
    ), "'number' must been an int and positive"

    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(_A   ) + 1   )       ,   6   ):
        if number % i == 0 or number % (i + 2) == 0:
            return False
    return True




class 		a_    (			unittest.TestCase						):







    def   _snake_case       (      self      :							int  )		->Optional[int]:






        '''simple docstring'''






        self.assertTrue(is_prime(2  )  )
        self.assertTrue(is_prime(3  )  )
        self.assertTrue(is_prime(5  )  )
        self.assertTrue(is_prime(7  )  )
        self.assertTrue(is_prime(11  )  )
        self.assertTrue(is_prime(13  )  )
        self.assertTrue(is_prime(17  )  )
        self.assertTrue(is_prime(19  )  )
        self.assertTrue(is_prime(23  )  )
        self.assertTrue(is_prime(29  )  )







    def   _snake_case       (      self      :							Union[str, Any]  )		->Optional[Any]:






        '''simple docstring'''






        with self.assertRaises(__UpperCamelCase  ):
            is_prime(-19  )
        self.assertFalse(
            is_prime(0  )  ,       """Zero doesn't have any positive factors, primes must have exactly two."""  ,       )
        self.assertFalse(
            is_prime(1  )  ,       """One only has 1 positive factor, primes must have exactly two."""  ,       )
        self.assertFalse(is_prime(2 * 2  )  )
        self.assertFalse(is_prime(2 * 3  )  )
        self.assertFalse(is_prime(3 * 3  )  )
        self.assertFalse(is_prime(3 * 5  )  )
        self.assertFalse(is_prime(3 * 5 * 7  )  )


if __name__ == "__main__":
 unittest.main()