

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    a__  (   unittest.TestCase     ):
			"""simple docstring"""







			def __init__(      self , lowercase , lowercase=7 , lowercase=3 , lowercase=10 , lowercase=18 , lowercase=30 , lowercase=400 , lowercase=True , lowercase=None , lowercase=True , lowercase=[0.5, 0.5, 0.5] , lowercase=[0.5, 0.5, 0.5] , lowercase=None , )					->  Tuple:
							'''simple docstring'''






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

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


			def        UpperCamelCase						(      self    )					->  Union[str, 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    a__  (   snake_case							,		unittest.TestCase     ):
			"""simple docstring"""







			__lowerCamelCase	    =    VideoMAEImageProcessor if is_vision_available() else None


			def        UpperCamelCase						(      self    )					->  Union[str, Any]:
							'''simple docstring'''






							A__            =     VideoMAEImageProcessingTester(self    )


			@property
			def        UpperCamelCase						(      self    )					->  int:
							'''simple docstring'''






							return self.image_processor_tester.prepare_image_processor_dict()


			def        UpperCamelCase						(      self    )					->  Optional[Any]:
							'''simple docstring'''






							A__            =     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        UpperCamelCase						(      self    )					->  List[str]:
							'''simple docstring'''






							A__            =     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}    )

							A__            =     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        UpperCamelCase						(      self    )					->  int:
							'''simple docstring'''






							pass


			def        UpperCamelCase						(      self    )					->  List[str]:
							'''simple docstring'''






							A__            =     self.image_processing_class(**self.image_processor_dict    )
							# create random PIL videos
							A__            =     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
							A__            =     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
							A__            =     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        UpperCamelCase						(      self    )					->  Dict:
							'''simple docstring'''






							A__            =     self.image_processing_class(**self.image_processor_dict    )
							# create random numpy tensors
							A__            =     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
							A__            =     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
							A__            =     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        UpperCamelCase						(      self    )					->  List[str]:
							'''simple docstring'''






							A__            =     self.image_processing_class(**self.image_processor_dict    )
							# create random PyTorch tensors
							A__            =     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
							A__            =     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
							A__            =     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    lowerCAmelCase__							(		SCREAMING_SNAKE_CASE_:							list		,    SCREAMING_SNAKE_CASE_:							int		,    SCREAMING_SNAKE_CASE_:							int		,    SCREAMING_SNAKE_CASE_:							int )     -> int:




				'''simple docstring'''





				A__            =     int((lower_bound + upper_bound) // 2 )
				if array[r] == value:
								return r
				if lower_bound >= upper_bound:
								return -1
				if array[r] < value:
								return binary_search(SCREAMING_SNAKE_CASE_		,    r + 1		,    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_ )
				else:
								return binary_search(SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_		,    r - 1		,    SCREAMING_SNAKE_CASE_ )



def    lowerCAmelCase__							(		SCREAMING_SNAKE_CASE_:							int		,    SCREAMING_SNAKE_CASE_:							list )     -> list:




				'''simple docstring'''





				A__            =     0
				if matrix[index][0] == value:
								return [index, 0]
				while index < len(SCREAMING_SNAKE_CASE_ ) and matrix[index][0] < value:
								A__            =     binary_search(matrix[index]		,    0		,    len(matrix[index] ) - 1		,    SCREAMING_SNAKE_CASE_ )
								if r != -1:
												return [index, r]
								index += 1
				return [-1, -1]


if __name__ == "__main__":
	import doctest

	doctest.testmod()

