





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, prepare_video_inputs


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import VivitImageProcessor







class   _UpperCamelCase  (       unittest.TestCase  ):







					'''simple docstring'''

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






						'''simple docstring'''







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

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





					def        SCREAMING_SNAKE_CASE							(						self    :  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,
						    "crop_size": self.crop_size,
						}







@require_torch
@require_vision
class   _UpperCamelCase  (       A_						,       unittest.TestCase  ):







					'''simple docstring'''

					lowerCamelCase     :     Optional[Any]			    =       VivitImageProcessor if is_vision_available() else None





					def        SCREAMING_SNAKE_CASE							(						self    :  Tuple		):






						'''simple docstring'''







						UpperCAmelCase_								=     VivitImageProcessingTester(self		)





					@property
					def        SCREAMING_SNAKE_CASE							(						self    :  List[str]		):






						'''simple docstring'''







						return self.image_processor_tester.prepare_image_processor_dict()





					def        SCREAMING_SNAKE_CASE							(						self    :  Union[str, Any]		):






						'''simple docstring'''







						UpperCAmelCase_								=     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        SCREAMING_SNAKE_CASE							(						self    :  Union[str, Any]		):






						'''simple docstring'''







						UpperCAmelCase_								=     self.image_processing_class.from_dict(self.image_processor_dict		)
						self.assertEqual(image_processor.size ,					{"""shortest_edge""": 18}		)
						self.assertEqual(image_processor.crop_size ,					{"""height""": 18, """width""": 18}		)

						UpperCAmelCase_								=     self.image_processing_class.from_dict(self.image_processor_dict ,					size=42 ,					crop_size=84		)
						self.assertEqual(image_processor.size ,					{"""shortest_edge""": 42}		)
						self.assertEqual(image_processor.crop_size ,					{"""height""": 84, """width""": 84}		)





					def        SCREAMING_SNAKE_CASE							(						self    :  Any		):






						'''simple docstring'''







						UpperCAmelCase_								=     self.image_processing_class(**self.image_processor_dict		)
						# create random PIL videos
						UpperCAmelCase_								=     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
						UpperCAmelCase_								=     image_processing(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_								=     image_processing(__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        SCREAMING_SNAKE_CASE							(						self    :  str		):






						'''simple docstring'''







						UpperCAmelCase_								=     self.image_processing_class(**self.image_processor_dict		)
						# create random numpy tensors
						UpperCAmelCase_								=     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
						UpperCAmelCase_								=     image_processing(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_								=     image_processing(__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        SCREAMING_SNAKE_CASE							(						self    :  int		):






						'''simple docstring'''







						UpperCAmelCase_								=     self.image_processing_class(**self.image_processor_dict		)
						# create random PyTorch tensors
						UpperCAmelCase_								=     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
						UpperCAmelCase_								=     image_processing(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_								=     image_processing(__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"""],
						    ) ,					)









from __future__ import annotations




def    A_(			A   ):
	if not nums:
		raise ValueError("""List is empty"""   )
	return sum(A   ) / len(A   )


if __name__ == "__main__":
				import doctest

				doctest.testmod()


