


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				(     UpperCAmelCase				,UpperCAmelCase=10				,UpperCAmelCase=10				,UpperCAmelCase=False				,UpperCAmelCase=False      )->		Any:







					'''simple docstring'''



					SCREAMING_SNAKE_CASE_	      =       []
					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
										SCREAMING_SNAKE_CASE_	      =       [Image.fromarray(np.moveaxis(UpperCAmelCase				,0				,-1      )      ) for frame in video]

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

					return video







def 							UpperCAmelCase				(     UpperCAmelCase				,UpperCAmelCase=False				,UpperCAmelCase=False				,UpperCAmelCase=False      )->		Dict:







					'''simple docstring'''



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

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

					return video_inputs

class 						snake_case			(       unittest.TestCase	):
			'''simple docstring'''

			def __init__(	self     :     str							,							lowerCAmelCase_     :     Optional[Any]							,							lowerCAmelCase_     :     Dict=7							,							lowerCAmelCase_     :     Tuple=3							,							lowerCAmelCase_     :     Optional[Any]=4							,							lowerCAmelCase_     :     Tuple=18							,							lowerCAmelCase_     :     List[Any]=30							,							lowerCAmelCase_     :     Union[str, Any]=400							,							lowerCAmelCase_     :     Tuple=True							,							lowerCAmelCase_     :     str=None							,							lowerCAmelCase_     :     Union[str, Any]=True							,							lowerCAmelCase_     :     int=[0.5, 0.5, 0.5]							,							lowerCAmelCase_     :     Dict=[0.5, 0.5, 0.5]							,							lowerCAmelCase_     :     List[Any]=True							,							lowerCAmelCase_     :     Any=None							,							)					->					Any:




								"""simple docstring"""






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

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




			def _lowercase (	self     :     Any					)					->					Tuple:




								"""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 						snake_case			(       lowerCAmelCase__	, unittest.TestCase	):
			'''simple docstring'''

			UpperCAmelCase       :       List[Any]       = TvltImageProcessor if is_vision_available() else None

			def _lowercase (	self     :     List[Any]					)					->					Any:




								"""simple docstring"""






								SCREAMING_SNAKE_CASE_	      =       TvltImageProcessorTester(self					)

			@property
			def _lowercase (	self     :     Tuple					)					->					Tuple:




								"""simple docstring"""






								return self.image_processor_tester.prepare_image_processor_dict()

			def _lowercase (	self     :     Optional[Any]					)					->					Any:




								"""simple docstring"""






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

			def _lowercase (	self     :     Dict					)					->					Optional[int]:




								"""simple docstring"""






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

								# Test not batched input
								SCREAMING_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
								SCREAMING_SNAKE_CASE_	      =       image_processor(lowerCAmelCase_							,							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 _lowercase (	self     :     Tuple					)					->					str:




								"""simple docstring"""






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

								# Test not batched input
								SCREAMING_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
								SCREAMING_SNAKE_CASE_	      =       image_processor(lowerCAmelCase_							,							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 _lowercase (	self     :     Dict					)					->					str:




								"""simple docstring"""






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

								# Test not batched input
								SCREAMING_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
								SCREAMING_SNAKE_CASE_	      =       image_processor(lowerCAmelCase_							,							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				(     UpperCAmelCase				,UpperCAmelCase      )->		int:







					'''simple docstring'''



					return (input_a, input_a).count(0      ) % 2







def 							UpperCAmelCase				(     )->		None:







					'''simple docstring'''



					assert xor_gate(0				,0      ) == 0
					assert xor_gate(0				,1      ) == 1
					assert xor_gate(1				,0      ) == 1
					assert xor_gate(1				,1      ) == 0


if __name__ == "__main__":
		print(xor_gate(0, 0))
		print(xor_gate(0, 1))


