
"""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, prepare_video_inputs


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import VideoMAEImageProcessor




class    __lowerCamelCase     (   unittest.TestCase ):




				def __init__(							self       ,	UpperCAmelCase       ,	UpperCAmelCase=7       ,	UpperCAmelCase=3       ,	UpperCAmelCase=10       ,	UpperCAmelCase=18       ,	UpperCAmelCase=30       ,	UpperCAmelCase=400       ,	UpperCAmelCase=True       ,	UpperCAmelCase=None       ,	UpperCAmelCase=True       ,	UpperCAmelCase=[0.5, 0.5, 0.5]       ,	UpperCAmelCase=[0.5, 0.5, 0.5]       ,	UpperCAmelCase=None       ,	):
							lowerCamelCase_ 		=     size if size is not None else {'''shortest_edge''': 18}
							lowerCamelCase_ 		=     crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

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





				def 					UpperCAmelCase__	(							self      ):
							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    __lowerCamelCase     (   lowerCAmelCase	,  unittest.TestCase ):
				a__:			Union[str, Any]									=						VideoMAEImageProcessor if is_vision_available() else None




				def 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     VideoMAEImageProcessingTester(self      )




				@property
				def 					UpperCAmelCase__	(							self      ):
							return self.image_processor_tester.prepare_image_processor_dict()




				def 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     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 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     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}      )

							lowerCamelCase_ 		=     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      ):
							pass




				def 					UpperCAmelCase__	(							self      ):
							# Initialize image_processing
							lowerCamelCase_ 		=     self.image_processing_class(**self.image_processor_dict      )
							# create random PIL videos
							lowerCamelCase_ 		=     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
							lowerCamelCase_ 		=     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
							lowerCamelCase_ 		=     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 					UpperCAmelCase__	(							self      ):
							# Initialize image_processing
							lowerCamelCase_ 		=     self.image_processing_class(**self.image_processor_dict      )
							# create random numpy tensors
							lowerCamelCase_ 		=     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
							lowerCamelCase_ 		=     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
							lowerCamelCase_ 		=     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 					UpperCAmelCase__	(							self      ):
							# Initialize image_processing
							lowerCamelCase_ 		=     self.image_processing_class(**self.image_processor_dict      )
							# create random PyTorch tensors
							lowerCamelCase_ 		=     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
							lowerCamelCase_ 		=     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
							lowerCamelCase_ 		=     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'''],
							    )       ,	)





"""simple docstring"""


import warnings
from collections.abc import Callable
from typing import Any

import numpy
from matplotlib import pyplot

A_						       =				0.25 + 0.0J
A_						       =				-0.4 + 0.6J
A_						       =				-0.1 + 0.651J
A_						       =				-2.0
A_						       =				56
A_						       =				2.0
A_						       =				666






def    lowercase	(  lowerCAmelCase__  ,lowerCAmelCase__	):
			return numpy.exp(lowerCAmelCase__	) + c_parameter






def    lowercase	(  lowerCAmelCase__  ,lowerCAmelCase__	):
			return z_values * z_values + c_parameter






def    lowercase	(  lowerCAmelCase__  ,lowerCAmelCase__	):
			lowerCamelCase_ 		=     numpy.linspace(-window_size  ,lowerCAmelCase__  ,lowerCAmelCase__	)
			lowerCamelCase_ 		=     x.reshape((nb_pixels, 1)	)
			lowerCamelCase_ 		=     numpy.linspace(-window_size  ,lowerCAmelCase__  ,lowerCAmelCase__	)
			lowerCamelCase_ 		=     y.reshape((1, nb_pixels)	)
			return x + 1.0J * y






def    lowercase	(  lowerCAmelCase__  ,lowerCAmelCase__  ,lowerCAmelCase__  ,lowerCAmelCase__  ,lowerCAmelCase__ = None  ,):
			lowerCamelCase_ 		=     z_a.astype('''complex64'''	)
			for _ in range(lowerCAmelCase__	):
						lowerCamelCase_ 		=     eval_function(lowerCAmelCase__  ,lowerCAmelCase__	)
						if infinity is not None:
									numpy.nan_to_num(lowerCAmelCase__  ,copy=lowerCAmelCase__  ,nan=lowerCAmelCase__	)
									lowerCamelCase_ 		=     infinity
			return z_n






def    lowercase	(  lowerCAmelCase__  ,lowerCAmelCase__  ,lowerCAmelCase__  ,lowerCAmelCase__  ,):
			lowerCamelCase_ 		=     (abs(lowerCAmelCase__	)).transpose()
			lowerCamelCase_ 		=     abs_z_final[::-1, :]
			pyplot.matshow(abs_z_final < escape_radius	)
			pyplot.title(f"Julia set of ${function_label}$, $c={function_params}$"	)
			pyplot.show()






def    lowercase	(  ):
			warnings.filterwarnings(
			    '''ignore'''  ,category=lowerCAmelCase__  ,message='''overflow encountered in multiply'''	)
			warnings.filterwarnings(
			    '''ignore'''  ,category=lowerCAmelCase__  ,message='''invalid value encountered in multiply'''  ,)
			warnings.filterwarnings(
			    '''ignore'''  ,category=lowerCAmelCase__  ,message='''overflow encountered in absolute'''	)
			warnings.filterwarnings(
			    '''ignore'''  ,category=lowerCAmelCase__  ,message='''overflow encountered in exp'''	)


if __name__ == "__main__":
						A_						       =				prepare_grid(window_size, nb_pixels)

						ignore_overflow_warnings()  # See file header for explanations

						A_						       =				24
						A_						       =				2 * abs(c_cauliflower) + 1
						A_						       =				iterate_function(
						    eval_quadratic_polynomial,
						    c_cauliflower,
						    nb_iterations,
						    z_a,
						    infinity=1.1 * escape_radius,
						)
						show_results("""z^2+c""", c_cauliflower, escape_radius, z_final)

						A_						       =				64
						A_						       =				2 * abs(c_polynomial_a) + 1
						A_						       =				iterate_function(
						    eval_quadratic_polynomial,
						    c_polynomial_a,
						    nb_iterations,
						    z_a,
						    infinity=1.1 * escape_radius,
						)
						show_results("""z^2+c""", c_polynomial_a, escape_radius, z_final)

						A_						       =				161
						A_						       =				2 * abs(c_polynomial_a) + 1
						A_						       =				iterate_function(
						    eval_quadratic_polynomial,
						    c_polynomial_a,
						    nb_iterations,
						    z_a,
						    infinity=1.1 * escape_radius,
						)
						show_results("""z^2+c""", c_polynomial_a, escape_radius, z_final)

						A_						       =				12
						A_						       =				10000.0
						A_						       =				iterate_function(
						    eval_exponential,
						    c_exponential,
						    nb_iterations,
						    z_a + 2,
						    infinity=1.0e10,
						)
						show_results("""e^z+c""", c_exponential, escape_radius, z_final)



