

"""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        _lowerCAmelCase      (						UpperCAmelCase     :							List[str]      ,							UpperCAmelCase     :							int=10      ,							UpperCAmelCase     :							Any=10      ,							UpperCAmelCase     :							List[Any]=False      ,							UpperCAmelCase     :							Tuple=False				):


					'''simple docstring'''






					UpperCamelCase__		:    List[str]         =[]
					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__		:    Optional[Any]         =[Image.fromarray(np.moveaxis(UpperCAmelCase      ,							0      ,							-1				)				) for frame in video]

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

					return video



def        _lowerCAmelCase      (						UpperCAmelCase     :							Any      ,							UpperCAmelCase     :							Optional[Any]=False      ,							UpperCAmelCase     :							List[Any]=False      ,							UpperCAmelCase     :							Optional[int]=False				):


					'''simple docstring'''






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

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

					return video_inputs

class     __a   (      unittest.TestCase    ):

			"""simple docstring"""

			def __init__(							self     :					List[Any]						,  lowercase_     :					Optional[int]						,  lowercase_     :					Union[str, Any]=7						,  lowercase_     :					str=3						,  lowercase_     :					Union[str, Any]=4						,  lowercase_     :					str=18						,  lowercase_     :					Dict=30						,  lowercase_     :					Optional[Any]=400						,  lowercase_     :					List[Any]=True						,  lowercase_     :					List[Any]=None						,  lowercase_     :					str=True						,  lowercase_     :					Union[str, Any]=[0.5, 0.5, 0.5]						,  lowercase_     :					Optional[Any]=[0.5, 0.5, 0.5]						,  lowercase_     :					int=True						,  lowercase_     :					Union[str, Any]=None						,  ):
								UpperCamelCase__		:    Union[str, Any]         =size if size is not None else {'''shortest_edge''': 18}
								UpperCamelCase__		:    Optional[Any]         =crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

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






			def    _lowerCAmelCase			(							self     :					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     __a   (      snake_case__,    unittest.TestCase    ):

			"""simple docstring"""

			SCREAMING_SNAKE_CASE_						     =						TvltImageProcessor if is_vision_available() else None






			def    _lowerCAmelCase			(							self     :					str						):
								UpperCamelCase__		:    Dict         =TvltImageProcessorTester(self						)






			@property
			def    _lowerCAmelCase			(							self     :					Union[str, Any]						):
								return self.image_processor_tester.prepare_image_processor_dict()






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





"""simple docstring"""





from __future__ import annotations

from collections.abc import Iterable
from dataclasses import dataclass
from typing import Any

class     __a   :

			"""simple docstring"""

			SCREAMING_SNAKE_CASE_						     =						('_front', '_back', '_len')

			@dataclass
			class     __a   :

						"""simple docstring"""

						SCREAMING_SNAKE_CASE_						     =						None
						SCREAMING_SNAKE_CASE_						     =						None
						SCREAMING_SNAKE_CASE_						     =						None



			class     __a   :

						"""simple docstring"""

						SCREAMING_SNAKE_CASE_						     =						('_cur',)






						def __init__(							self     :					Optional[int]						,  lowercase_     :					Deque._Node | None						):
											UpperCamelCase__		:    List[str]         =cur






						def __iter__(							self     :					List[str]						):
											return self






						def    _lowerCAmelCase			(							self     :					List[Any]						):
											if self._cur is None:
																# finished iterating
																raise StopIteration
											UpperCamelCase__		:    str         =self._cur.val
											UpperCamelCase__		:    Any         =self._cur.next_node

											return val






			def __init__(							self     :					str						,  lowercase_     :					Iterable[Any] | None = None						):
								UpperCamelCase__		:    Any         =None
								UpperCamelCase__		:    Any         =None
								UpperCamelCase__		:    int         =0

								if iterable is not None:
													# append every value to the deque
													for val in iterable:
																		self.append(lowercase_						)






			def    _lowerCAmelCase			(							self     :					str						,  lowercase_     :					Any						):
								UpperCamelCase__		:    Union[str, Any]         =self._Node(lowercase_						,  lowercase_						,  lowercase_						)
								if self.is_empty():
													# front = back
													UpperCamelCase__		:    Any         =node
													UpperCamelCase__		:    List[Any]         =1
								else:
													# connect nodes
													UpperCamelCase__		:    Any         =node
													UpperCamelCase__		:    Optional[Any]         =self._back
													UpperCamelCase__		:    str         =node  # assign new back to the new node

													self._len += 1

													# make sure there were no errors
													assert not self.is_empty(), "Error on appending value."






			def    _lowerCAmelCase			(							self     :					Optional[Any]						,  lowercase_     :					Any						):
								UpperCamelCase__		:    str         =self._Node(lowercase_						,  lowercase_						,  lowercase_						)
								if self.is_empty():
													# front = back
													UpperCamelCase__		:    str         =node
													UpperCamelCase__		:    Any         =1
								else:
													# connect nodes
													UpperCamelCase__		:    int         =self._front
													UpperCamelCase__		:    int         =node
													UpperCamelCase__		:    Any         =node  # assign new front to the new node

													self._len += 1

													# make sure there were no errors
													assert not self.is_empty(), "Error on appending value."






			def    _lowerCAmelCase			(							self     :					List[Any]						,  lowercase_     :					Iterable[Any]						):
								for val in iterable:
													self.append(lowercase_						)






			def    _lowerCAmelCase			(							self     :					Dict						,  lowercase_     :					Iterable[Any]						):
								for val in iterable:
													self.appendleft(lowercase_						)






			def    _lowerCAmelCase			(							self     :					Optional[int]						):
								assert not self.is_empty(), "Deque is empty."

								UpperCamelCase__		:    List[Any]         =self._back
								UpperCamelCase__		:    Any         =self._back.prev_node  # set new back
								# drop the last node - python will deallocate memory automatically
								UpperCamelCase__		:    List[str]         =None

								self._len -= 1

								return topop.val






			def    _lowerCAmelCase			(							self     :					str						):
								assert not self.is_empty(), "Deque is empty."

								UpperCamelCase__		:    List[str]         =self._front
								UpperCamelCase__		:    List[Any]         =self._front.next_node  # set new front and drop the first node
								UpperCamelCase__		:    Dict         =None

								self._len -= 1

								return topop.val






			def    _lowerCAmelCase			(							self     :					Dict						):
								return self._front is None






			def __len__(							self     :					Any						):
								return self._len






			def __eq__(							self     :					Dict						,  lowercase_     :					object						):

								if not isinstance(lowercase_						,  lowercase_						):
													return NotImplemented

								UpperCamelCase__		:    Union[str, Any]         =self._front
								UpperCamelCase__		:    Union[str, Any]         =other._front

								# if the length of the dequeues are not the same, they are not equal
								if len(self						) != len(lowercase_						):
													return False

								while me is not None and oth is not None:
													# compare every value
													if me.val != oth.val:
																		return False
													UpperCamelCase__		:    Union[str, Any]         =me.next_node
													UpperCamelCase__		:    Union[str, Any]         =oth.next_node

								return True






			def __iter__(							self     :					Optional[int]						):
								return Deque._Iterator(self._front						)






			def __repr__(							self     :					Tuple						):
								UpperCamelCase__		:    List[Any]         =[]
								UpperCamelCase__		:    Optional[int]         =self._front
								while aux is not None:
													# append the values in a list to display
													values_list.append(aux.val						)
													UpperCamelCase__		:    Optional[Any]         =aux.next_node

								return f'''[{', '.join(repr(lowercase_						) for val in values_list						)}]'''


if __name__ == "__main__":
				import doctest

				doctest.testmod()


