

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 				a__	(	lowerCAmelCase ,  lowerCAmelCase=10 ,  lowerCAmelCase=10 ,  lowerCAmelCase=False ,  lowerCAmelCase=False						)  ->   Optional[int]:
      UpperCAmelCase__ :       int						=						[]
      for i in range(image_processor_tester.num_frames						):
            video.append(np.random.randint(2_55 ,  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
            UpperCAmelCase__ :       Optional[int]						=						[Image.fromarray(np.moveaxis(lowerCAmelCase ,  0 ,  -1						)						) for frame in video]

      if torchify:
            UpperCAmelCase__ :       Any						=						[torch.from_numpy(lowerCAmelCase						) for frame in video]

      return video




def 				a__	(	lowerCAmelCase ,  lowerCAmelCase=False ,  lowerCAmelCase=False ,  lowerCAmelCase=False						)  ->   Dict:
      assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

      return video_inputs

class 			lowerCamelCase  (					unittest.TestCase      ):


  '''simple docstring'''







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


        """simple docstring"""

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

        UpperCAmelCase__ :       Optional[int]						=						parent
        UpperCAmelCase__ :       List[str]						=						batch_size
        UpperCAmelCase__ :       List[str]						=						num_channels
        UpperCAmelCase__ :       Optional[int]						=						num_frames
        UpperCAmelCase__ :       Union[str, Any]						=						image_size
        UpperCAmelCase__ :       int						=						min_resolution
        UpperCAmelCase__ :       Dict						=						max_resolution
        UpperCAmelCase__ :       Any						=						do_resize
        UpperCAmelCase__ :       List[Any]						=						size
        UpperCAmelCase__ :       List[Any]						=						do_normalize
        UpperCAmelCase__ :       List[str]						=						image_mean
        UpperCAmelCase__ :       Any						=						image_std
        UpperCAmelCase__ :       Union[str, Any]						=						do_center_crop
        UpperCAmelCase__ :       str						=						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,
            "do_center_crop": self.do_center_crop,
            "crop_size": self.crop_size,
        }




@require_torch
@require_vision
class 			lowerCamelCase  (					lowerCAmelCase__				,				unittest.TestCase      ):


  '''simple docstring'''







  SCREAMING_SNAKE_CASE							=     TvltImageProcessor if is_vision_available() else None



  def    _a			(self  ):


        """simple docstring"""

        UpperCAmelCase__ :       Dict						=						TvltImageProcessorTester(self  )



  @property
  def    _a			(self  ):


        """simple docstring"""

        return self.image_processor_tester.prepare_image_processor_dict()



  def    _a			(self  ):


        """simple docstring"""

        UpperCAmelCase__ :       List[Any]						=						self.image_processing_class(**self.image_processor_dict  )
        self.assertTrue(hasattr(_lowerCamelCase       ,					"""image_mean"""  )  )
        self.assertTrue(hasattr(_lowerCamelCase       ,					"""image_std"""  )  )
        self.assertTrue(hasattr(_lowerCamelCase       ,					"""do_normalize"""  )  )
        self.assertTrue(hasattr(_lowerCamelCase       ,					"""do_resize"""  )  )
        self.assertTrue(hasattr(_lowerCamelCase       ,					"""do_center_crop"""  )  )
        self.assertTrue(hasattr(_lowerCamelCase       ,					"""size"""  )  )



  def    _a			(self  ):


        """simple docstring"""

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

        # Test not batched input
        UpperCAmelCase__ :       str						=						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
        UpperCAmelCase__ :       Any						=						image_processor(_lowerCamelCase       ,					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"""

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

        # Test not batched input
        UpperCAmelCase__ :       Union[str, 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
        UpperCAmelCase__ :       Optional[Any]						=						image_processor(_lowerCamelCase       ,					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"""

        UpperCAmelCase__ :       str						=						self.image_processing_class(**self.image_processor_dict  )
        # create random PyTorch tensors
        UpperCAmelCase__ :       Optional[int]						=						prepare_video_inputs(self.image_processor_tester       ,					equal_resolution=_lowerCamelCase       ,					torchify=_lowerCamelCase  )
        for video in video_inputs:
              self.assertIsInstance(_lowerCamelCase       ,					_lowerCamelCase  )
              self.assertIsInstance(video[0]       ,					torch.Tensor  )

        # Test not batched input
        UpperCAmelCase__ :       str						=						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
        UpperCAmelCase__ :       str						=						image_processor(_lowerCamelCase       ,					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"""
from __future__ import annotations




def 				a__	(	lowerCAmelCase						)  ->   set[int]:
      UpperCAmelCase__ :       List[Any]						=						{1}
      UpperCAmelCase__ :       Optional[int]						=						[1]
      for _ in range(2 ,  depth + 1						):
            UpperCAmelCase__ :       Tuple						=						[*previous_coefficients, 0]
            UpperCAmelCase__ :       List[str]						=						[0, *previous_coefficients]
            UpperCAmelCase__ :       Dict						=						[]
            for x, y in zip(lowerCAmelCase ,  lowerCAmelCase						):
                  coefficients.add(x + y						)
                  previous_coefficients.append(x + y						)
      return coefficients




def 				a__	(	lowerCAmelCase						)  ->   set[int]:
      UpperCAmelCase__ :       List[str]						=						set()
      for number in unique_coefficients:
            UpperCAmelCase__ :       int						=						2
            UpperCAmelCase__ :       List[Any]						=						number
            while divisor**2 <= copy_number:
                  UpperCAmelCase__ :       Tuple						=						0
                  while copy_number % divisor == 0:
                        copy_number //= divisor
                        multiplicity += 1
                  if multiplicity >= 2:
                        non_squarefrees.add(lowerCAmelCase						)
                        break
                  divisor += 1

      return unique_coefficients.difference(lowerCAmelCase						)




def 				a__	(	lowerCAmelCase = 51						)  ->   int:
      UpperCAmelCase__ :       Any						=						get_pascal_triangle_unique_coefficients(lowerCAmelCase						)
      UpperCAmelCase__ :       Dict						=						get_squarefrees(lowerCAmelCase						)
      return sum(lowerCAmelCase						)


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

