

"""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


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import TvltImageProcessor







def       UpperCamelCase_					(     lowerCamelCase							:					Optional[Any]     , lowerCamelCase							:					str=10     , lowerCamelCase							:					Any=10     , lowerCamelCase							:					List[Any]=False     , lowerCamelCase							:					Optional[int]=False   )						->     int:



       """simple docstring"""







       __magic_name__			:		str        =     []
       for i in range(image_processor_tester.num_frames   ):
              video.append(np.random.randint(255     , size=(image_processor_tester.num_channels, width, height)     , dtype=np.uinta   )   )

       if not numpify and not torchify:
              # PIL expects the channel dimension as last dimension
              __magic_name__			:		Optional[int]        =     [Image.fromarray(np.moveaxis(lowerCamelCase     , 0     , -1   )   ) for frame in video]

       if torchify:
              __magic_name__			:		Optional[int]        =     [torch.from_numpy(lowerCamelCase   ) for frame in video]

       return video







def       UpperCamelCase_					(     lowerCamelCase							:					Any     , lowerCamelCase							:					Dict=False     , lowerCamelCase							:					Dict=False     , lowerCamelCase							:					Union[str, Any]=False   )						->     Dict:



       """simple docstring"""







       assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

       __magic_name__			:		str        =     []
       for i in range(image_processor_tester.batch_size   ):
              if equal_resolution:
                     __magic_name__			:		Optional[int]        =     image_processor_tester.max_resolution
              else:
                     __magic_name__       ,							__magic_name__			:		Optional[Any]        =     np.random.choice(
                         np.arange(image_processor_tester.min_resolution     , image_processor_tester.max_resolution   )     , 2   )
                     __magic_name__			:		Tuple        =     prepare_video(
                         image_processor_tester=lowerCamelCase     , width=lowerCamelCase     , height=lowerCamelCase     , numpify=lowerCamelCase     , torchify=lowerCamelCase     , )
              video_inputs.append(lowerCamelCase   )

       return video_inputs

class        _UpperCamelCase	(						unittest.TestCase	):


  """simple docstring"""





  def __init__( self					: Any       ,       snake_case					: Optional[int]       ,       snake_case					: str=7       ,       snake_case					: Optional[Any]=3       ,       snake_case					: Tuple=4       ,       snake_case					: Union[str, Any]=18       ,       snake_case					: str=30       ,       snake_case					: int=400       ,       snake_case					: Union[str, Any]=True       ,       snake_case					: Tuple=None       ,       snake_case					: Any=True       ,       snake_case					: Dict=[0.5, 0.5, 0.5]       ,       snake_case					: Dict=[0.5, 0.5, 0.5]       ,       snake_case					: int=True       ,       snake_case					: Any=None       ,       )	->			Union[str, Any]:


         '''simple docstring'''





         __magic_name__			:		str        =     size if size is not None else {'''shortest_edge''': 18}
         __magic_name__			:		Any        =     crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

         __magic_name__			:		Union[str, Any]        =     parent
         __magic_name__			:		int        =     batch_size
         __magic_name__			:		Tuple        =     num_channels
         __magic_name__			:		Tuple        =     num_frames
         __magic_name__			:		Union[str, Any]        =     image_size
         __magic_name__			:		int        =     min_resolution
         __magic_name__			:		Union[str, Any]        =     max_resolution
         __magic_name__			:		Dict        =     do_resize
         __magic_name__			:		Any        =     size
         __magic_name__			:		Dict        =     do_normalize
         __magic_name__			:		List[Any]        =     image_mean
         __magic_name__			:		Dict        =     image_std
         __magic_name__			:		List[str]        =     do_center_crop
         __magic_name__			:		List[str]        =     crop_size




  def 							_UpperCAmelCase      ( self					: Dict      )	->			List[Any]:


         '''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,
             "do_center_crop": self.do_center_crop,
             "crop_size": self.crop_size,
         }

@require_torch
@require_vision
class        _UpperCamelCase	(						lowerCamelCase__   ,				unittest.TestCase	):


  """simple docstring"""





  snake_case_        =    TvltImageProcessor if is_vision_available() else None



  def 							_UpperCAmelCase      ( self					: Optional[Any]      )	->			List[Any]:


         '''simple docstring'''





         __magic_name__			:		Any        =     TvltImageProcessorTester(self      )



  @property
  def 							_UpperCAmelCase      ( self					: Optional[int]      )	->			Optional[int]:


         '''simple docstring'''





         return self.image_processor_tester.prepare_image_processor_dict()



  def 							_UpperCAmelCase      ( self					: List[Any]      )	->			Any:


         '''simple docstring'''





         __magic_name__			:		Union[str, Any]        =     self.image_processing_class(**self.image_processor_dict      )
         self.assertTrue(hasattr(snake_case       ,       '''image_mean'''      )      )
         self.assertTrue(hasattr(snake_case       ,       '''image_std'''      )      )
         self.assertTrue(hasattr(snake_case       ,       '''do_normalize'''      )      )
         self.assertTrue(hasattr(snake_case       ,       '''do_resize'''      )      )
         self.assertTrue(hasattr(snake_case       ,       '''do_center_crop'''      )      )
         self.assertTrue(hasattr(snake_case       ,       '''size'''      )      )



  def 							_UpperCAmelCase      ( self					: Union[str, Any]      )	->			int:


         '''simple docstring'''





         __magic_name__			:		List[Any]        =     self.image_processing_class(**self.image_processor_dict      )
         # create random PIL videos
         __magic_name__			:		Optional[int]        =     prepare_video_inputs(self.image_processor_tester       ,       equal_resolution=snake_case      )
         for video in video_inputs:
                self.assertIsInstance(snake_case       ,       snake_case      )
                self.assertIsInstance(video[0]       ,       Image.Image      )

         # Test not batched input
         __magic_name__			:		List[Any]        =     image_processor(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
         __magic_name__			:		str        =     image_processor(snake_case       ,       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 							_UpperCAmelCase      ( self					: int      )	->			Dict:


         '''simple docstring'''





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

         # Test not batched input
         __magic_name__			:		Dict        =     image_processor(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
         __magic_name__			:		Optional[int]        =     image_processor(snake_case       ,       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 							_UpperCAmelCase      ( self					: Tuple      )	->			Optional[int]:


         '''simple docstring'''





         __magic_name__			:		Any        =     self.image_processing_class(**self.image_processor_dict      )
         # create random PyTorch tensors
         __magic_name__			:		Dict        =     prepare_video_inputs(self.image_processor_tester       ,       equal_resolution=snake_case       ,       torchify=snake_case      )
         for video in video_inputs:
                self.assertIsInstance(snake_case       ,       snake_case      )
                self.assertIsInstance(video[0]       ,       torch.Tensor      )

         # Test not batched input
         __magic_name__			:		Dict        =     image_processor(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
         __magic_name__			:		Union[str, Any]        =     image_processor(snake_case       ,       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







def       UpperCamelCase_					(     lowerCamelCase							:					int   )						->     list:



       """simple docstring"""







       if n <= 0:
              raise ValueError('''Only positive integers have prime factors'''   )
       __magic_name__			:		Union[str, Any]        =     []
       while n % 2 == 0:
              pf.append(2   )
              __magic_name__			:		Union[str, Any]        =     int(n / 2   )
       for i in range(3     , int(math.sqrt(lowerCamelCase   )   ) + 1     , 2   ):
              while n % i == 0:
                     pf.append(lowerCamelCase   )
                     __magic_name__			:		Any        =     int(n / i   )
       if n > 2:
              pf.append(lowerCamelCase   )
       return pf







def       UpperCamelCase_					(     lowerCamelCase							:					int   )						->     int:



       """simple docstring"""







       if n <= 0:
              raise ValueError('''Only positive numbers are accepted'''   )
       __magic_name__			:		List[Any]        =     1
       __magic_name__			:		Dict        =     1
       while n % 2 == 0:
              temp += 1
              __magic_name__			:		Dict        =     int(n / 2   )
       div *= temp
       for i in range(3     , int(math.sqrt(lowerCamelCase   )   ) + 1     , 2   ):
              __magic_name__			:		Dict        =     1
              while n % i == 0:
                     temp += 1
                     __magic_name__			:		Union[str, Any]        =     int(n / i   )
              div *= temp
       if n > 1:
              div *= 2
       return div







def       UpperCamelCase_					(     lowerCamelCase							:					int   )						->     int:



       """simple docstring"""







       if n <= 0:
              raise ValueError('''Only positive numbers are accepted'''   )
       __magic_name__			:		int        =     1
       __magic_name__			:		Dict        =     1
       while n % 2 == 0:
              temp += 1
              __magic_name__			:		List[Any]        =     int(n / 2   )
       if temp > 1:
              s *= (2**temp - 1) / (2 - 1)
       for i in range(3     , int(math.sqrt(lowerCamelCase   )   ) + 1     , 2   ):
              __magic_name__			:		Any        =     1
              while n % i == 0:
                     temp += 1
                     __magic_name__			:		Any        =     int(n / i   )
              if temp > 1:
                     s *= (i**temp - 1) / (i - 1)
       return int(lowerCamelCase   )







def       UpperCamelCase_					(     lowerCamelCase							:					int   )						->     int:



       """simple docstring"""







       __magic_name__			:		str        =     n
       for x in set(prime_factors(lowerCamelCase   )   ):
              s *= (x - 1) / x
       return int(lowerCamelCase   )


if __name__ == "__main__":
 import doctest

 doctest.testmod()
