'''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 (					__UpperCAmelCase  :					List[Any] ,   __UpperCAmelCase  :					int=10 ,   __UpperCAmelCase  :					List[Any]=10 ,   __UpperCAmelCase  :					Union[str, Any]=False ,   __UpperCAmelCase  :					Tuple=False			)							->	Optional[int]:
  lowercase				:							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
    lowercase				:							List[str]									=   [Image.fromarray(np.moveaxis(__UpperCAmelCase ,   0 ,   -1			)			) for frame in video]

  if torchify:
    lowercase				:							Tuple									=   [torch.from_numpy(__UpperCAmelCase			) for frame in video]

  return video







def 				__UpperCamelCase (					__UpperCAmelCase  :					Union[str, Any] ,   __UpperCAmelCase  :					Optional[int]=False ,   __UpperCAmelCase  :					List[Any]=False ,   __UpperCAmelCase  :					List[Any]=False			)							->	str:
  assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

  return video_inputs




class _lowerCAmelCase			(	unittest.TestCase					):







      def __init__(  self  ,    lowercase  ,    lowercase=7  ,    lowercase=3  ,    lowercase=4  ,    lowercase=18  ,    lowercase=30  ,    lowercase=400  ,    lowercase=True  ,    lowercase=None  ,    lowercase=True  ,    lowercase=[0.5, 0.5, 0.5]  ,    lowercase=[0.5, 0.5, 0.5]  ,    lowercase=True  ,    lowercase=None  ,    ):
        lowercase				:							List[Any]									=   size if size is not None else {'''shortest_edge''': 18}
        lowercase				:							Optional[int]									=   crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

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







      def      lowerCamelCase__      (  self     ):
        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			(	snake_case							,   unittest.TestCase					):
      UpperCAmelCase_	:						Optional[int]	 =       TvltImageProcessor if is_vision_available() else None







      def      lowerCamelCase__      (  self     ):
        lowercase				:							Union[str, Any]									=   TvltImageProcessorTester(self     )







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







      def      lowerCamelCase__      (  self     ):
        lowercase				:							Tuple									=   self.image_processing_class(**self.image_processor_dict     )
        self.assertTrue(hasattr(lowercase  ,    '''image_mean'''     )     )
        self.assertTrue(hasattr(lowercase  ,    '''image_std'''     )     )
        self.assertTrue(hasattr(lowercase  ,    '''do_normalize'''     )     )
        self.assertTrue(hasattr(lowercase  ,    '''do_resize'''     )     )
        self.assertTrue(hasattr(lowercase  ,    '''do_center_crop'''     )     )
        self.assertTrue(hasattr(lowercase  ,    '''size'''     )     )







      def      lowerCamelCase__      (  self     ):
        # Initialize image_processor
        lowercase				:							Tuple									=   self.image_processing_class(**self.image_processor_dict     )
        # create random PIL videos
        lowercase				:							List[str]									=   prepare_video_inputs(self.image_processor_tester  ,    equal_resolution=lowercase     )
        for video in video_inputs:
          self.assertIsInstance(lowercase  ,    lowercase     )
          self.assertIsInstance(video[0]  ,    Image.Image     )

        # Test not batched input
        lowercase				:							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
        lowercase				:							Any									=   image_processor(lowercase  ,    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      lowerCamelCase__      (  self     ):
        # Initialize image_processor
        lowercase				:							Optional[int]									=   self.image_processing_class(**self.image_processor_dict     )
        # create random numpy tensors
        lowercase				:							Tuple									=   prepare_video_inputs(self.image_processor_tester  ,    equal_resolution=lowercase  ,    numpify=lowercase     )
        for video in video_inputs:
          self.assertIsInstance(lowercase  ,    lowercase     )
          self.assertIsInstance(video[0]  ,    np.ndarray     )

        # Test not batched input
        lowercase				:							Optional[int]									=   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
        lowercase				:							Optional[Any]									=   image_processor(lowercase  ,    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      lowerCamelCase__      (  self     ):
        # Initialize image_processor
        lowercase				:							int									=   self.image_processing_class(**self.image_processor_dict     )
        # create random PyTorch tensors
        lowercase				:							Tuple									=   prepare_video_inputs(self.image_processor_tester  ,    equal_resolution=lowercase  ,    torchify=lowercase     )
        for video in video_inputs:
          self.assertIsInstance(lowercase  ,    lowercase     )
          self.assertIsInstance(video[0]  ,    torch.Tensor     )

        # Test not batched input
        lowercase				:							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
        lowercase				:							Any									=   image_processor(lowercase  ,    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

import math
import random







def 				__UpperCamelCase (					__UpperCAmelCase  :					int ,   __UpperCAmelCase  :					int ,   __UpperCAmelCase  :					int			)							->	list[int]:
  lowercase				:							Union[str, Any]									=   d * e - 1
  lowercase				:							List[str]									=   0
  lowercase				:							Tuple									=   0
  while p == 0:
    lowercase				:							Optional[Any]									=   random.randint(2 ,   n - 1			)
    lowercase				:							Dict									=   k
    while True:
      if t % 2 == 0:
        lowercase				:							List[Any]									=   t // 2
        lowercase				:							Union[str, Any]									=   (g**t) % n
        lowercase				:							Optional[Any]									=   math.gcd(x - 1 ,   __UpperCAmelCase			)
        if x > 1 and y > 1:
          lowercase				:							Dict									=   y
          lowercase				:							Any									=   n // y
          break  # find the correct factors
      else:
        break  # t is not divisible by 2, break and choose another g
  return sorted([p, q]			)


if __name__ == "__main__":
 import doctest

 doctest.testmod()