




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


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import VideoMAEImageProcessor

class  __lowercase    (     unittest.TestCase		):


				'''simple docstring'''


				def __init__(				self				:       List[Any] ,SCREAMING_SNAKE_CASE_				:       int ,SCREAMING_SNAKE_CASE_				:       Dict=7 ,SCREAMING_SNAKE_CASE_				:       Any=3 ,SCREAMING_SNAKE_CASE_				:       List[Any]=1_0 ,SCREAMING_SNAKE_CASE_				:       Any=1_8 ,SCREAMING_SNAKE_CASE_				:       Dict=3_0 ,SCREAMING_SNAKE_CASE_				:       List[str]=4_0_0 ,SCREAMING_SNAKE_CASE_				:       Optional[Any]=True ,SCREAMING_SNAKE_CASE_				:       Tuple=None ,SCREAMING_SNAKE_CASE_				:       Union[str, Any]=True ,SCREAMING_SNAKE_CASE_				:       Dict=[0.5, 0.5, 0.5] ,SCREAMING_SNAKE_CASE_				:       Optional[Any]=[0.5, 0.5, 0.5] ,SCREAMING_SNAKE_CASE_				:       Optional[int]=None ,):
										snake_case__    :   Any							     =   size if size is not None else {'''shortest_edge''': 1_8}
										snake_case__    :   List[Any]							     =   crop_size if crop_size is not None else {'''height''': 1_8, '''width''': 1_8}

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





				def  _lowerCamelCase   (				self				:       int ):
										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  __lowercase    (     snake_case_  ,				unittest.TestCase		):


				'''simple docstring'''


				_lowerCAmelCase		     =VideoMAEImageProcessor if is_vision_available() else None

				def  _lowerCamelCase   (				self				:       Optional[int] ):
										snake_case__    :   Union[str, Any]							     =   VideoMAEImageProcessingTester(self )

				@property
				def  _lowerCamelCase   (				self				:       List[str] ):
										return self.image_processor_tester.prepare_image_processor_dict()

				def  _lowerCamelCase   (				self				:       Optional[int] ):
										snake_case__    :   Union[str, Any]							     =   self.image_processing_class(**self.image_processor_dict )
										self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_ ,'''image_mean''' ) )
										self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_ ,'''image_std''' ) )
										self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_ ,'''do_normalize''' ) )
										self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_ ,'''do_resize''' ) )
										self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_ ,'''do_center_crop''' ) )
										self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_ ,'''size''' ) )

				def  _lowerCamelCase   (				self				:       List[str] ):
										snake_case__    :   Optional[Any]							     =   self.image_processing_class.from_dict(self.image_processor_dict )
										self.assertEqual(image_processor.size ,{'''shortest_edge''': 1_8} )
										self.assertEqual(image_processor.crop_size ,{'''height''': 1_8, '''width''': 1_8} )

										snake_case__    :   Union[str, Any]							     =   self.image_processing_class.from_dict(self.image_processor_dict ,size=4_2 ,crop_size=8_4 )
										self.assertEqual(image_processor.size ,{'''shortest_edge''': 4_2} )
										self.assertEqual(image_processor.crop_size ,{'''height''': 8_4, '''width''': 8_4} )

				def  _lowerCamelCase   (				self				:       str ):
										pass

				def  _lowerCamelCase   (				self				:       Optional[Any] ):
										# Initialize image_processing
										snake_case__    :   str							     =   self.image_processing_class(**self.image_processor_dict )
										# create random PIL videos
										snake_case__    :   List[Any]							     =   prepare_video_inputs(self.image_processor_tester ,equal_resolution=SCREAMING_SNAKE_CASE_ )
										for video in video_inputs:
																self.assertIsInstance(SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ )
																self.assertIsInstance(video[0] ,Image.Image )

										# Test not batched input
										snake_case__    :   List[str]							     =   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
										snake_case__    :   List[Any]							     =   image_processing(SCREAMING_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  _lowerCamelCase   (				self				:       Optional[Any] ):
										# Initialize image_processing
										snake_case__    :   Union[str, Any]							     =   self.image_processing_class(**self.image_processor_dict )
										# create random numpy tensors
										snake_case__    :   Union[str, Any]							     =   prepare_video_inputs(self.image_processor_tester ,equal_resolution=SCREAMING_SNAKE_CASE_ ,numpify=SCREAMING_SNAKE_CASE_ )
										for video in video_inputs:
																self.assertIsInstance(SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ )
																self.assertIsInstance(video[0] ,np.ndarray )

										# Test not batched input
										snake_case__    :   Optional[Any]							     =   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
										snake_case__    :   Any							     =   image_processing(SCREAMING_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  _lowerCamelCase   (				self				:       Dict ):
										# Initialize image_processing
										snake_case__    :   str							     =   self.image_processing_class(**self.image_processor_dict )
										# create random PyTorch tensors
										snake_case__    :   Optional[Any]							     =   prepare_video_inputs(self.image_processor_tester ,equal_resolution=SCREAMING_SNAKE_CASE_ ,torchify=SCREAMING_SNAKE_CASE_ )
										for video in video_inputs:
																self.assertIsInstance(SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ )
																self.assertIsInstance(video[0] ,torch.Tensor )

										# Test not batched input
										snake_case__    :   List[str]							     =   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
										snake_case__    :   List[Any]							     =   image_processing(SCREAMING_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"""





class  __lowercase    :


				'''simple docstring'''


				class  __lowercase    :


								'''simple docstring'''


								_lowerCAmelCase		     ="_prev", "_data", "_next"

								def __init__(				self				:       List[Any] ,SCREAMING_SNAKE_CASE_				:       int ,SCREAMING_SNAKE_CASE_				:       Union[str, Any] ,SCREAMING_SNAKE_CASE_				:       Any ):
														snake_case__    :   Any							     =   link_p
														snake_case__    :   List[str]							     =   element
														snake_case__    :   str							     =   link_n





								def  _lowerCamelCase   (				self				:       Optional[Any] ):
														return (
														    F''' Prev -> {self._prev is not None}, Next -> {self._next is not None}'''
														)







				def __init__(				self				:       Any ):
										snake_case__    :   int							     =   self._Node(SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ )
										snake_case__    :   Optional[int]							     =   self._Node(SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ )
										snake_case__    :   Union[str, Any]							     =   self._trailer
										snake_case__    :   Union[str, Any]							     =   self._header
										snake_case__    :   Any							     =   0

				def __len__(				self				:       str ):
										return self._size

				def  _lowerCamelCase   (				self				:       Union[str, Any] ):
										return self.__len__() == 0

				def  _lowerCamelCase   (				self				:       Any ,SCREAMING_SNAKE_CASE_				:       List[Any] ,SCREAMING_SNAKE_CASE_				:       List[str] ,SCREAMING_SNAKE_CASE_				:       Dict ):
										# Create new_node by setting it's prev.link -> header
										# setting it's next.link -> trailer
										snake_case__    :   Dict							     =   self._Node(SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ )
										snake_case__    :   Any							     =   new_node
										snake_case__    :   str							     =   new_node
										self._size += 1
										return self





				def  _lowerCamelCase   (				self				:       Union[str, Any] ,SCREAMING_SNAKE_CASE_				:       Dict ):
										snake_case__    :   Union[str, Any]							     =   node._prev
										snake_case__    :   Union[str, Any]							     =   node._next

										snake_case__    :   List[Any]							     =   successor
										snake_case__    :   Dict							     =   predecessor
										self._size -= 1
										snake_case__    :   Dict							     =   node._data
										snake_case__    :   List[str]							     =   None
										del node
										return temp







class  __lowercase    (     _DoublyLinkedBase		):


				'''simple docstring'''


				def  _lowerCamelCase   (				self				:       Optional[int] ):
										if self.is_empty():
																raise Exception('''List is empty''' )
										return self._header._next._data

				def  _lowerCamelCase   (				self				:       Union[str, Any] ):
										if self.is_empty():
																raise Exception('''List is empty''' )
										return self._trailer._prev._data

				def  _lowerCamelCase   (				self				:       Any ,SCREAMING_SNAKE_CASE_				:       Dict ):
										return self._insert(self._header ,SCREAMING_SNAKE_CASE_ ,self._header._next )

				def  _lowerCamelCase   (				self				:       Dict ,SCREAMING_SNAKE_CASE_				:       Union[str, Any] ):
										return self._insert(self._trailer._prev ,SCREAMING_SNAKE_CASE_ ,self._trailer )

				def  _lowerCamelCase   (				self				:       Optional[int] ):
										if self.is_empty():
																raise IndexError('''remove_first from empty list''' )
										return self._delete(self._header._next )





				def  _lowerCamelCase   (				self				:       Optional[Any] ):
										if self.is_empty():
																raise IndexError('''remove_first from empty list''' )
										return self._delete(self._trailer._prev )


