






"""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 						__UpperCAmelCase      (					a_							,					a_=10							,					a_=10							,					a_=False							,					a_=False):
							snake_case_           =							[]
							for i in range(image_processor_tester.num_frames):
														video.append(np.random.randint(2_55							,					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
														snake_case_           =							[Image.fromarray(np.moveaxis(a_							,					0							,					-1)) for frame in video]

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

							return video





def 						__UpperCAmelCase      (					a_							,					a_=False							,					a_=False							,					a_=False):
							assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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



	'''simple docstring'''




	def __init__(	self	,      a	,      a=7	,      a=3	,      a=4	,      a=18	,      a=30	,      a=4_00	,      a=True	,      a=None	,      a=True	,      a=[0.5, 0.5, 0.5]	,      a=[0.5, 0.5, 0.5]	,      a=True	,      a=None	,      )	->   List[Any]:
								snake_case_           =							size if size is not None else {'shortest_edge': 18}
								snake_case_           =							crop_size if crop_size is not None else {'height': 18, 'width': 18}

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






	def 							_UpperCamelCase      (	self )	->   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 			UpperCamelCase_				(      snake_case_	, unittest.TestCase    ):



	'''simple docstring'''




	lowerCAmelCase													=			TvltImageProcessor if is_vision_available() else None




	def 							_UpperCamelCase      (	self )	->   Tuple:
								snake_case_           =							TvltImageProcessorTester(self )




	@property
	def 							_UpperCamelCase      (	self )	->   Any:
								return self.image_processor_tester.prepare_image_processor_dict()




	def 							_UpperCamelCase      (	self )	->   Any:
								snake_case_           =							self.image_processing_class(**self.image_processor_dict )
								self.assertTrue(hasattr(a	,      'image_mean' ) )
								self.assertTrue(hasattr(a	,      'image_std' ) )
								self.assertTrue(hasattr(a	,      'do_normalize' ) )
								self.assertTrue(hasattr(a	,      'do_resize' ) )
								self.assertTrue(hasattr(a	,      'do_center_crop' ) )
								self.assertTrue(hasattr(a	,      'size' ) )




	def 							_UpperCamelCase      (	self )	->   Tuple:
								# Initialize image_processor
								snake_case_           =							self.image_processing_class(**self.image_processor_dict )
								# create random PIL videos
								snake_case_           =							prepare_video_inputs(self.image_processor_tester	,      equal_resolution=a )
								for video in video_inputs:
															self.assertIsInstance(a	,      a )
															self.assertIsInstance(video[0]	,      Image.Image )

								# Test not batched input
								snake_case_           =							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
								snake_case_           =							image_processor(a	,      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 							_UpperCamelCase      (	self )	->   Tuple:
								# Initialize image_processor
								snake_case_           =							self.image_processing_class(**self.image_processor_dict )
								# create random numpy tensors
								snake_case_           =							prepare_video_inputs(self.image_processor_tester	,      equal_resolution=a	,      numpify=a )
								for video in video_inputs:
															self.assertIsInstance(a	,      a )
															self.assertIsInstance(video[0]	,      np.ndarray )

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

								# Test not batched input
								snake_case_           =							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
								snake_case_           =							image_processor(a	,      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 						__UpperCAmelCase      (					a_):
							return 1 if input_a == 0 else 0





def 						__UpperCAmelCase      (					):
							assert not_gate(0) == 1
							assert not_gate(1) == 0


if __name__ == "__main__":
	print(not_gate(0))
	print(not_gate(1))





