

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   __UpperCamelCase      (   unittest.TestCase  ):




	def __init__(						self		:  Dict						,		lowerCAmelCase		:  Any						,		lowerCAmelCase		:  List[Any]=7						,		lowerCAmelCase		:  Any=3						,		lowerCAmelCase		:  str=10						,		lowerCAmelCase		:  Any=18						,		lowerCAmelCase		:  Union[str, Any]=30						,		lowerCAmelCase		:  List[str]=400						,		lowerCAmelCase		:  List[str]=True						,		lowerCAmelCase		:  Union[str, Any]=None						,		lowerCAmelCase		:  List[str]=True						,		lowerCAmelCase		:  Union[str, Any]=[0.5, 0.5, 0.5]						,		lowerCAmelCase		:  Union[str, Any]=[0.5, 0.5, 0.5]						,		lowerCAmelCase		:  Optional[int]=None						,		):


		'''simple docstring'''







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

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




	def  __A   (						self		:  List[str]							):


		'''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   __UpperCamelCase      (   lowercase_       ,       unittest.TestCase  ):
	SCREAMING_SNAKE_CASE__      			=       VideoMAEImageProcessor if is_vision_available() else None




	def  __A   (						self		:  str							):


		'''simple docstring'''







		UpperCAmelCase_    			=     VideoMAEImageProcessingTester(self							)




	@property
	def  __A   (						self		:  Tuple							):


		'''simple docstring'''







		return self.image_processor_tester.prepare_image_processor_dict()




	def  __A   (						self		:  List[Any]							):


		'''simple docstring'''







		UpperCAmelCase_    			=     self.image_processing_class(**self.image_processor_dict							)
		self.assertTrue(hasattr(UpperCamelCase_						,		"image_mean"							)							)
		self.assertTrue(hasattr(UpperCamelCase_						,		"image_std"							)							)
		self.assertTrue(hasattr(UpperCamelCase_						,		"do_normalize"							)							)
		self.assertTrue(hasattr(UpperCamelCase_						,		"do_resize"							)							)
		self.assertTrue(hasattr(UpperCamelCase_						,		"do_center_crop"							)							)
		self.assertTrue(hasattr(UpperCamelCase_						,		"size"							)							)




	def  __A   (						self		:  int							):


		'''simple docstring'''







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

		UpperCAmelCase_    			=     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  __A   (						self		:  List[str]							):


		'''simple docstring'''







		pass




	def  __A   (						self		:  Any							):


		'''simple docstring'''







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

		# Test not batched input
		UpperCAmelCase_    			=     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
		UpperCAmelCase_    			=     image_processing(UpperCamelCase_						,		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  __A   (						self		:  Tuple							):


		'''simple docstring'''







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

		# Test not batched input
		UpperCAmelCase_    			=     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
		UpperCAmelCase_    			=     image_processing(UpperCamelCase_						,		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  __A   (						self		:  Optional[int]							):


		'''simple docstring'''







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

		# Test not batched input
		UpperCAmelCase_    			=     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
		UpperCAmelCase_    			=     image_processing(UpperCamelCase_						,		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 (  A      ):
	UpperCAmelCase_    			=     len(A      )

	# Set the gap value to be decreased by a factor of 1.3
	# after each iteration
	UpperCAmelCase_    			=     1.3

	# Continue sorting until the gap is 1
	while gap > 1:
		# Decrease the gap value
		UpperCAmelCase_    			=     int(gap / shrink      )

		# Sort the elements using insertion sort
		for i in range(A    ,       len(A      )      ):
			UpperCAmelCase_    			=     collection[i]
			UpperCAmelCase_    			=     i
			while j >= gap and collection[j - gap] > temp:
				UpperCAmelCase_    			=     collection[j - gap]
				j -= gap
			UpperCAmelCase_    			=     temp

	return collection


if __name__ == "__main__":
				import doctest

				doctest.testmod()