

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_					:       Optional[Any]       ,a_					:       str=1_0       ,a_					:       List[Any]=1_0       ,a_					:       Dict=False       ,a_					:       Tuple=False					)					->						Optional[Any]:




					'''simple docstring'''







					__magic_name__				=     []
					for i in range(image_processor_tester.num_frames					):
										video.append(np.random.randint(2_5_5       ,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__				=     [Image.fromarray(np.moveaxis(a_       ,0       ,-1					)					) for frame in video]

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

					return video




def        _lowercase  (					a_					:       Optional[int]       ,a_					:       Dict=False       ,a_					:       List[Any]=False       ,a_					:       Optional[Any]=False					)					->						List[Any]:




					'''simple docstring'''







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

					__magic_name__				=     []
					for i in range(image_processor_tester.batch_size					):
										if equal_resolution:
															__magic_name__				=     __magic_name__				=     image_processor_tester.max_resolution
										else:
															__magic_name__,						__magic_name__				=     np.random.choice(
															    np.arange(image_processor_tester.min_resolution       ,image_processor_tester.max_resolution					)       ,2					)
															__magic_name__				=     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      ):







	def __init__( self:			Optional[Any]	,			__UpperCamelCase:			List[str]	,			__UpperCamelCase:			int=7	,			__UpperCamelCase:			Optional[int]=3	,			__UpperCamelCase:			str=4	,			__UpperCamelCase:			str=18	,			__UpperCamelCase:			Tuple=30	,			__UpperCamelCase:			Any=4_00	,			__UpperCamelCase:			Dict=True	,			__UpperCamelCase:			Optional[Any]=None	,			__UpperCamelCase:			Dict=True	,			__UpperCamelCase:			Dict=[0.5, 0.5, 0.5]	,			__UpperCamelCase:			Optional[Any]=[0.5, 0.5, 0.5]	,			__UpperCamelCase:			Tuple=True	,			__UpperCamelCase:			List[str]=None	,			):

						'''simple docstring'''





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

						__magic_name__				=     parent
						__magic_name__				=     batch_size
						__magic_name__				=     num_channels
						__magic_name__				=     num_frames
						__magic_name__				=     image_size
						__magic_name__				=     min_resolution
						__magic_name__				=     max_resolution
						__magic_name__				=     do_resize
						__magic_name__				=     size
						__magic_name__				=     do_normalize
						__magic_name__				=     image_mean
						__magic_name__				=     image_std
						__magic_name__				=     do_center_crop
						__magic_name__				=     crop_size







	def 						_SCREAMING_SNAKE_CASE				( self:			Union[str, 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					(       SCREAMING_SNAKE_CASE	,    unittest.TestCase      ):
	_lowercase	: Union[str, Any]												=	TvltImageProcessor if is_vision_available() else None







	def 						_SCREAMING_SNAKE_CASE				( self:			Optional[Any]   ):

						'''simple docstring'''





						__magic_name__				=     TvltImageProcessorTester(self   )







	@property
	def 						_SCREAMING_SNAKE_CASE				( self:			Union[str, Any]   ):

						'''simple docstring'''





						return self.image_processor_tester.prepare_image_processor_dict()







	def 						_SCREAMING_SNAKE_CASE				( self:			List[str]   ):

						'''simple docstring'''





						__magic_name__				=     self.image_processing_class(**self.image_processor_dict   )
						self.assertTrue(hasattr(__UpperCamelCase	,			'image_mean'   )   )
						self.assertTrue(hasattr(__UpperCamelCase	,			'image_std'   )   )
						self.assertTrue(hasattr(__UpperCamelCase	,			'do_normalize'   )   )
						self.assertTrue(hasattr(__UpperCamelCase	,			'do_resize'   )   )
						self.assertTrue(hasattr(__UpperCamelCase	,			'do_center_crop'   )   )
						self.assertTrue(hasattr(__UpperCamelCase	,			'size'   )   )







	def 						_SCREAMING_SNAKE_CASE				( self:			str   ):

						'''simple docstring'''





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

						# Test not batched input
						__magic_name__				=     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__				=     image_processor(__UpperCamelCase	,			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 						_SCREAMING_SNAKE_CASE				( self:			Optional[Any]   ):

						'''simple docstring'''





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

						# Test not batched input
						__magic_name__				=     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__				=     image_processor(__UpperCamelCase	,			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 						_SCREAMING_SNAKE_CASE				( self:			Tuple   ):

						'''simple docstring'''





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

						# Test not batched input
						__magic_name__				=     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__				=     image_processor(__UpperCamelCase	,			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'],
						    )	,			)







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


A__							=				{"configuration_pegasus": ["PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP", "PegasusConfig"]}

try:
						if not is_sentencepiece_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A__							=				["PegasusTokenizer"]

try:
						if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A__							=				["PegasusTokenizerFast"]

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A__							=				[
						    "PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST",
						    "PegasusForCausalLM",
						    "PegasusForConditionalGeneration",
						    "PegasusModel",
						    "PegasusPreTrainedModel",
						]

try:
						if not is_tf_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A__							=				[
						    "TFPegasusForConditionalGeneration",
						    "TFPegasusModel",
						    "TFPegasusPreTrainedModel",
						]

try:
						if not is_flax_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A__							=				[
						    "FlaxPegasusForConditionalGeneration",
						    "FlaxPegasusModel",
						    "FlaxPegasusPreTrainedModel",
						]


if TYPE_CHECKING:
						from .configuration_pegasus import PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP, PegasusConfig

						try:
												if not is_sentencepiece_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_pegasus import PegasusTokenizer

						try:
												if not is_tokenizers_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_pegasus_fast import PegasusTokenizerFast

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_pegasus import (
												    PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST,
												    PegasusForCausalLM,
												    PegasusForConditionalGeneration,
												    PegasusModel,
												    PegasusPreTrainedModel,
												)

						try:
												if not is_tf_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_tf_pegasus import TFPegasusForConditionalGeneration, TFPegasusModel, TFPegasusPreTrainedModel

						try:
												if not is_flax_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_flax_pegasus import (
												    FlaxPegasusForConditionalGeneration,
												    FlaxPegasusModel,
												    FlaxPegasusPreTrainedModel,
												)

else:
						import sys

						A__							=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




