




'''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 			snake_case_					( _lowerCAmelCase  :						Tuple       ,				_lowerCAmelCase  :						Tuple=10       ,				_lowerCAmelCase  :						Optional[int]=10       ,				_lowerCAmelCase  :						Any=False       ,				_lowerCAmelCase  :						str=False  )				->       int:
							UpperCAmelCase			:	int										=		[]
							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
														UpperCAmelCase			:	Dict										=		[Image.fromarray(np.moveaxis(_lowerCamelCase       ,				0       ,				-1  )  ) for frame in video]

							if torchify:
														UpperCAmelCase			:	List[str]										=		[torch.from_numpy(_lowerCamelCase  ) for frame in video]

							return video


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

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

							return video_inputs

class     SCREAMING_SNAKE_CASE(							unittest.TestCase      ):







	"""simple docstring"""






	def __init__(						self      :					int		,      __snake_case      :					Union[str, Any]		,      __snake_case      :					Tuple=7		,      __snake_case      :					Tuple=3		,      __snake_case      :					List[Any]=4		,      __snake_case      :					Union[str, Any]=18		,      __snake_case      :					List[Any]=30		,      __snake_case      :					Union[str, Any]=400		,      __snake_case      :					List[Any]=True		,      __snake_case      :					str=None		,      __snake_case      :					List[str]=True		,      __snake_case      :					List[str]=[0.5, 0.5, 0.5]		,      __snake_case      :					str=[0.5, 0.5, 0.5]		,      __snake_case      :					Optional[int]=True		,      __snake_case      :					Any=None		,      )      ->		int:
								UpperCAmelCase			:	int										=		size if size is not None else {"""shortest_edge""": 18}
								UpperCAmelCase			:	Union[str, Any]										=		crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

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







	def 					A     (						self      :					Any		)      ->		Optional[Any]:
								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     SCREAMING_SNAKE_CASE(							_a							,		unittest.TestCase      ):







	"""simple docstring"""






	lowerCamelCase__      			=	TvltImageProcessor if is_vision_available() else None







	def 					A     (						self      :					List[Any]		)      ->		List[Any]:
								UpperCAmelCase			:	Optional[Any]										=		TvltImageProcessorTester(self		)







	@property
	def 					A     (						self      :					Dict		)      ->		Tuple:
								return self.image_processor_tester.prepare_image_processor_dict()







	def 					A     (						self      :					List[Any]		)      ->		Tuple:
								UpperCAmelCase			:	str										=		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 					A     (						self      :					str		)      ->		Tuple:
								# Initialize image_processor
								UpperCAmelCase			:	Any										=		self.image_processing_class(**self.image_processor_dict		)
								# create random PIL videos
								UpperCAmelCase			:	Dict										=		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
								UpperCAmelCase			:	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
								UpperCAmelCase			:	Tuple										=		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 					A     (						self      :					str		)      ->		List[Any]:
								# Initialize image_processor
								UpperCAmelCase			:	List[str]										=		self.image_processing_class(**self.image_processor_dict		)
								# create random numpy tensors
								UpperCAmelCase			:	Any										=		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
								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			:	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 					A     (						self      :					Tuple		)      ->		str:
								# Initialize image_processor
								UpperCAmelCase			:	int										=		self.image_processing_class(**self.image_processor_dict		)
								# create random PyTorch tensors
								UpperCAmelCase			:	Optional[int]										=		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
								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			:	Tuple										=		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 re


def 			snake_case_					( _lowerCAmelCase  :						List[str]  )				->       Dict:
							def docstring_decorator(_lowerCAmelCase  :						List[str]  ):
														UpperCAmelCase			:	str										=		fn.__doc__
														UpperCAmelCase			:	List[str]										=		func_doc.split('''\n'''  )
														UpperCAmelCase			:	Optional[Any]										=		0
														while i < len(_lowerCAmelCase  ) and re.search(R'''^\s*Examples?:\s*$'''       ,				lines[i]  ) is None:
																					i += 1
														if i < len(_lowerCAmelCase  ):
																					UpperCAmelCase			:	Union[str, Any]										=		example_docstring
																					UpperCAmelCase			:	Tuple										=		'''\n'''.join(_lowerCAmelCase  )
														else:
																					raise ValueError(
																					    f"""The function {fn} should have an empty 'Examples:' in its docstring as placeholder, """
																					    f"""current docstring is:\n{func_doc}"""  )
														UpperCAmelCase			:	Any										=		func_doc
														return fn

							return docstring_decorator





