






"""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 						lowercase__(A					,		A=10					,		A=10					,		A=False					,		A=False						)				->Optional[int]:




						"""simple docstring"""



						lowercase__				:      Dict=       []
						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__				:      Dict=       [Image.fromarray(np.moveaxis(A					,		0					,		-1						)						) for frame in video]

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

						return video





def 						lowercase__(A					,		A=False					,		A=False					,		A=False						)				->Tuple:




						"""simple docstring"""



						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__				:      Any=       image_processor_tester.max_resolution
												else:
																		lowercase__,	lowercase__				:      Dict=       np.random.choice(
																		    np.arange(image_processor_tester.min_resolution					,		image_processor_tester.max_resolution						)					,		2						)
																		lowercase__				:      str=       prepare_video(
																		    image_processor_tester=A					,		width=A					,		height=A					,		numpify=A					,		torchify=A					,		)
												video_inputs.append(A						)

						return video_inputs


class     __UpperCAmelCase(   unittest.TestCase							):




						"""simple docstring"""




						def __init__(   self       ,  snake_case__       ,  snake_case__=7       ,  snake_case__=3       ,  snake_case__=4       ,  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__=True       ,  snake_case__=None       ,  ):
												'''simple docstring'''
												lowercase__				:      List[Any]=       size if size is not None else {"shortest_edge": 18}
												lowercase__				:      List[str]=       crop_size if crop_size is not None else {"height": 18, "width": 18}

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




						def 		UpperCAmelCase_       (   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     __UpperCAmelCase(   SCREAMING_SNAKE_CASE__  ,  unittest.TestCase							):




						"""simple docstring"""




						__lowerCamelCase				       =					TvltImageProcessor if is_vision_available() else None




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												lowercase__				:      Optional[int]=       TvltImageProcessorTester(self			)




						@property
						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												return self.image_processor_tester.prepare_image_processor_dict()




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												lowercase__				:      int=       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			):
												'''simple docstring'''
												# Initialize image_processor
												lowercase__				:      int=       self.image_processing_class(**self.image_processor_dict			)
												# create random PIL videos
												lowercase__				:      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
												lowercase__				:      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
												lowercase__				:      List[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			):
												'''simple docstring'''
												# Initialize image_processor
												lowercase__				:      Any=       self.image_processing_class(**self.image_processor_dict			)
												# create random numpy tensors
												lowercase__				:      Optional[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
												lowercase__				:      List[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__				:      Dict=       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			):
												'''simple docstring'''
												# Initialize image_processor
												lowercase__				:      Optional[Any]=       self.image_processing_class(**self.image_processor_dict			)
												# create random PyTorch tensors
												lowercase__				:      str=       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
												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__				:      List[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"],
												    )       ,  )














"""simple docstring"""







def 						lowercase__(A						)				->int:




						"""simple docstring"""



						lowercase__				:      str=       0
						for plain_chr in plain_text:
												lowercase__				:      List[str]=       (
												    ord(A						) + (hash_value << 6) + (hash_value << 16) - hash_value
												)
						return hash_value






