
'''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 CLIPImageProcessor






class      snake_case__    (	unittest.TestCase ):







		"""simple docstring"""

		def __init__(	self							:       Optional[int]   ,     UpperCamelCase__							:       Tuple   ,     UpperCamelCase__							:       List[Any]=7   ,     UpperCamelCase__							:       List[Any]=3   ,     UpperCamelCase__							:       Optional[Any]=18   ,     UpperCamelCase__							:       Optional[Any]=30   ,     UpperCamelCase__							:       Optional[Any]=400   ,     UpperCamelCase__							:       int=True   ,     UpperCamelCase__							:       List[str]=None   ,     UpperCamelCase__							:       Any=True   ,     UpperCamelCase__							:       Union[str, Any]=None   ,     UpperCamelCase__							:       List[str]=True   ,     UpperCamelCase__							:       int=[0.48_145_466, 0.4_578_275, 0.40_821_073]   ,     UpperCamelCase__							:       Optional[Any]=[0.26_862_954, 0.26_130_258, 0.27_577_711]   ,     UpperCamelCase__							:       Optional[Any]=True   ,     )		->       Tuple:






				"""simple docstring"""







				snake_case   :    List[str]			       =		size if size is not None else {'''shortest_edge''': 20}
				snake_case   :    int			       =		crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
				snake_case   :    Optional[int]			       =		parent
				snake_case   :    Optional[Any]			       =		batch_size
				snake_case   :    str			       =		num_channels
				snake_case   :    Tuple			       =		image_size
				snake_case   :    Optional[int]			       =		min_resolution
				snake_case   :    List[str]			       =		max_resolution
				snake_case   :    Optional[Any]			       =		do_resize
				snake_case   :    List[Any]			       =		size
				snake_case   :    int			       =		do_center_crop
				snake_case   :    str			       =		crop_size
				snake_case   :    Optional[int]			       =		do_normalize
				snake_case   :    Union[str, Any]			       =		image_mean
				snake_case   :    Tuple			       =		image_std
				snake_case   :    Any			       =		do_convert_rgb



		def 	lowerCAmelCase							(	self							:       List[str]	)		->       Dict:






				"""simple docstring"""







				return {
				    "do_resize": self.do_resize,
				    "size": self.size,
				    "do_center_crop": self.do_center_crop,
				    "crop_size": self.crop_size,
				    "do_normalize": self.do_normalize,
				    "image_mean": self.image_mean,
				    "image_std": self.image_std,
				    "do_convert_rgb": self.do_convert_rgb,
				}



		def 	lowerCAmelCase							(	self							:       Dict   ,     UpperCamelCase__							:       str=False   ,     UpperCamelCase__							:       Optional[int]=False   ,     UpperCamelCase__							:       Tuple=False	)		->       List[Any]:






				"""simple docstring"""







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

				if equal_resolution:
						snake_case   :    Any			       =		[]
						for i in range(self.batch_size	):
								image_inputs.append(
								    np.random.randint(
								        255   ,     size=(self.num_channels, self.max_resolution, self.max_resolution)   ,     dtype=np.uinta	)	)
				else:
						snake_case   :    Optional[Any]			       =		[]
						for i in range(self.batch_size	):
								snake_case       ,snake_case   :    Any			       =		np.random.choice(np.arange(self.min_resolution   ,     self.max_resolution	)   ,     2	)
								image_inputs.append(np.random.randint(255   ,     size=(self.num_channels, width, height)   ,     dtype=np.uinta	)	)

				if not numpify and not torchify:
						# PIL expects the channel dimension as last dimension
						snake_case   :    str			       =		[Image.fromarray(np.moveaxis(UpperCamelCase__   ,     0   ,     -1	)	) for x in image_inputs]

				if torchify:
						snake_case   :    str			       =		[torch.from_numpy(UpperCamelCase__	) for x in image_inputs]

				return image_inputs







@require_torch
@require_vision
class      snake_case__    (	__SCREAMING_SNAKE_CASE  , unittest.TestCase ):







		"""simple docstring"""

		lowerCamelCase							=		CLIPImageProcessor if is_vision_available() else None



		def 	lowerCAmelCase							(	self							:       List[str]	)		->       Dict:






				"""simple docstring"""







				snake_case   :    Any			       =		CLIPImageProcessingTester(self	)



		@property
		def 	lowerCAmelCase							(	self							:       str	)		->       Any:






				"""simple docstring"""







				return self.image_processor_tester.prepare_image_processor_dict()



		def 	lowerCAmelCase							(	self							:       int	)		->       Optional[int]:






				"""simple docstring"""







				snake_case   :    str			       =		self.image_processing_class(**self.image_processor_dict	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''do_resize'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''size'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''do_center_crop'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''center_crop'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''do_normalize'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''image_mean'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''image_std'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''do_convert_rgb'''	)	)



		def 	lowerCAmelCase							(	self							:       List[str]	)		->       Optional[int]:






				"""simple docstring"""







				snake_case   :    Dict			       =		self.image_processing_class.from_dict(self.image_processor_dict	)
				self.assertEqual(image_processor.size   ,     {'''shortest_edge''': 20}	)
				self.assertEqual(image_processor.crop_size   ,     {'''height''': 18, '''width''': 18}	)

				snake_case   :    Any			       =		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 	lowerCAmelCase							(	self							:       Optional[Any]	)		->       List[Any]:






				"""simple docstring"""







				pass



		def 	lowerCAmelCase							(	self							:       List[Any]	)		->       Dict:






				"""simple docstring"""







				snake_case   :    int			       =		self.image_processing_class(**self.image_processor_dict	)
				# create random PIL images
				snake_case   :    List[str]			       =		self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase__	)
				for image in image_inputs:
						self.assertIsInstance(UpperCamelCase__   ,     Image.Image	)

				# Test not batched input
				snake_case   :    Dict			       =		image_processing(image_inputs[0]   ,     return_tensors='''pt'''	).pixel_values
				self.assertEqual(
				    encoded_images.shape   ,     (
				        1,
				        self.image_processor_tester.num_channels,
				        self.image_processor_tester.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )

				# Test batched
				snake_case   :    Optional[Any]			       =		image_processing(UpperCamelCase__   ,     return_tensors='''pt'''	).pixel_values
				self.assertEqual(
				    encoded_images.shape   ,     (
				        self.image_processor_tester.batch_size,
				        self.image_processor_tester.num_channels,
				        self.image_processor_tester.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )



		def 	lowerCAmelCase							(	self							:       str	)		->       Dict:






				"""simple docstring"""







				snake_case   :    str			       =		self.image_processing_class(**self.image_processor_dict	)
				# create random numpy tensors
				snake_case   :    Any			       =		self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase__   ,     numpify=UpperCamelCase__	)
				for image in image_inputs:
						self.assertIsInstance(UpperCamelCase__   ,     np.ndarray	)

				# Test not batched input
				snake_case   :    List[str]			       =		image_processing(image_inputs[0]   ,     return_tensors='''pt'''	).pixel_values
				self.assertEqual(
				    encoded_images.shape   ,     (
				        1,
				        self.image_processor_tester.num_channels,
				        self.image_processor_tester.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )

				# Test batched
				snake_case   :    List[str]			       =		image_processing(UpperCamelCase__   ,     return_tensors='''pt'''	).pixel_values
				self.assertEqual(
				    encoded_images.shape   ,     (
				        self.image_processor_tester.batch_size,
				        self.image_processor_tester.num_channels,
				        self.image_processor_tester.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )



		def 	lowerCAmelCase							(	self							:       Optional[int]	)		->       Union[str, Any]:






				"""simple docstring"""







				snake_case   :    List[Any]			       =		self.image_processing_class(**self.image_processor_dict	)
				# create random PyTorch tensors
				snake_case   :    int			       =		self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase__   ,     torchify=UpperCamelCase__	)
				for image in image_inputs:
						self.assertIsInstance(UpperCamelCase__   ,     torch.Tensor	)

				# Test not batched input
				snake_case   :    str			       =		image_processing(image_inputs[0]   ,     return_tensors='''pt'''	).pixel_values
				self.assertEqual(
				    encoded_images.shape   ,     (
				        1,
				        self.image_processor_tester.num_channels,
				        self.image_processor_tester.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )

				# Test batched
				snake_case   :    Dict			       =		image_processing(UpperCamelCase__   ,     return_tensors='''pt'''	).pixel_values
				self.assertEqual(
				    encoded_images.shape   ,     (
				        self.image_processor_tester.batch_size,
				        self.image_processor_tester.num_channels,
				        self.image_processor_tester.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )







@require_torch
@require_vision
class      snake_case__    (	__SCREAMING_SNAKE_CASE  , unittest.TestCase ):







		"""simple docstring"""

		lowerCamelCase							=		CLIPImageProcessor if is_vision_available() else None



		def 	lowerCAmelCase							(	self							:       Tuple	)		->       Any:






				"""simple docstring"""







				snake_case   :    Optional[Any]			       =		CLIPImageProcessingTester(self   ,     num_channels=4	)
				snake_case   :    Optional[Any]			       =		3



		@property
		def 	lowerCAmelCase							(	self							:       Optional[int]	)		->       List[str]:






				"""simple docstring"""







				return self.image_processor_tester.prepare_image_processor_dict()



		def 	lowerCAmelCase							(	self							:       Optional[int]	)		->       Optional[int]:






				"""simple docstring"""







				snake_case   :    List[str]			       =		self.image_processing_class(**self.image_processor_dict	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''do_resize'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''size'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''do_center_crop'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''center_crop'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''do_normalize'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''image_mean'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''image_std'''	)	)
				self.assertTrue(hasattr(UpperCamelCase__   ,     '''do_convert_rgb'''	)	)



		def 	lowerCAmelCase							(	self							:       List[Any]	)		->       int:






				"""simple docstring"""







				pass



		def 	lowerCAmelCase							(	self							:       Any	)		->       Dict:






				"""simple docstring"""







				snake_case   :    Optional[Any]			       =		self.image_processing_class(**self.image_processor_dict	)
				# create random PIL images
				snake_case   :    Any			       =		self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase__	)
				for image in image_inputs:
						self.assertIsInstance(UpperCamelCase__   ,     Image.Image	)

				# Test not batched input
				snake_case   :    List[Any]			       =		image_processing(image_inputs[0]   ,     return_tensors='''pt'''	).pixel_values
				self.assertEqual(
				    encoded_images.shape   ,     (
				        1,
				        self.expected_encoded_image_num_channels,
				        self.image_processor_tester.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )

				# Test batched
				snake_case   :    Dict			       =		image_processing(UpperCamelCase__   ,     return_tensors='''pt'''	).pixel_values
				self.assertEqual(
				    encoded_images.shape   ,     (
				        self.image_processor_tester.batch_size,
				        self.expected_encoded_image_num_channels,
				        self.image_processor_tester.crop_size['''height'''],
				        self.image_processor_tester.crop_size['''width'''],
				    )   ,     )




'''simple docstring'''
from __future__ import annotations

from collections.abc import Callable




def 					_UpperCamelCase		(    SCREAMING_SNAKE_CASE__      ,    SCREAMING_SNAKE_CASE__      ,    SCREAMING_SNAKE_CASE__      ,    SCREAMING_SNAKE_CASE__ = 100      ,    )   ->				float:


		'''simple docstring'''


		snake_case   :    int			       =		x_start
		snake_case   :    Tuple			       =		fnc(SCREAMING_SNAKE_CASE__       )
		snake_case   :    Dict			       =		0.0

		for _ in range(SCREAMING_SNAKE_CASE__       ):
				# Approximates small segments of curve as linear and solve
				# for trapezoidal area
				snake_case   :    str			       =		(x_end - x_start) / steps + xa
				snake_case   :    str			       =		fnc(SCREAMING_SNAKE_CASE__       )
				area += abs(fxa + fxa       ) * (xa - xa) / 2

				# Increment step
				snake_case   :    Any			       =		xa
				snake_case   :    List[str]			       =		fxa
		return area


if __name__ == "__main__":




						def 					_UpperCamelCase		(    SCREAMING_SNAKE_CASE__       )   ->				str:


								'''simple docstring'''


								return x**3

						print("f(x) = x^3")
						print("The area between the curve, x = -10, x = 10 and the x axis is:")
						lowercase__		    =	1_0
						while i <= 1_0_0_0_0_0:
												lowercase__		    =	trapezoidal_area(f, -5, 5, i)
												print(f"with {i} steps: {area}")
												i *= 1_0


