



"""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_image_inputs


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import OwlViTImageProcessor




class    __snake_case(					unittest.TestCase       ):




    def __init__(   self    ,							A_    ,							A_=7    ,							A_=3    ,							A_=18    ,							A_=30    ,							A_=400    ,							A_=True    ,							A_=None    ,							A_=True    ,							A_=None    ,							A_=True    ,							A_=[0.48_145_466, 0.4_578_275, 0.40_821_073]    ,							A_=[0.26_862_954, 0.26_130_258, 0.27_577_711]    ,							A_=True    ,							):





      '''simple docstring'''



      _SCREAMING_SNAKE_CASE        =			parent
      _SCREAMING_SNAKE_CASE        =			batch_size
      _SCREAMING_SNAKE_CASE        =			num_channels
      _SCREAMING_SNAKE_CASE        =			image_size
      _SCREAMING_SNAKE_CASE        =			min_resolution
      _SCREAMING_SNAKE_CASE        =			max_resolution
      _SCREAMING_SNAKE_CASE        =			do_resize
      _SCREAMING_SNAKE_CASE        =			size if size is not None else {'height': 18, 'width': 18}
      _SCREAMING_SNAKE_CASE        =			do_center_crop
      _SCREAMING_SNAKE_CASE        =			crop_size if crop_size is not None else {'height': 18, 'width': 18}
      _SCREAMING_SNAKE_CASE        =			do_normalize
      _SCREAMING_SNAKE_CASE        =			image_mean
      _SCREAMING_SNAKE_CASE        =			image_std
      _SCREAMING_SNAKE_CASE        =			do_convert_rgb




    def   A   (   self			):





      '''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,
      }




@require_torch
@require_vision
class    __snake_case(					_A			,			unittest.TestCase       ):
    _A       = OwlViTImageProcessor if is_vision_available() else None




    def   A   (   self			):





      '''simple docstring'''



      _SCREAMING_SNAKE_CASE        =			OwlViTImageProcessingTester(self			)




    @property
    def   A   (   self			):





      '''simple docstring'''



      return self.image_processor_tester.prepare_image_processor_dict()




    def   A   (   self			):





      '''simple docstring'''



      _SCREAMING_SNAKE_CASE        =			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   A   (   self			):





      '''simple docstring'''



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

      _SCREAMING_SNAKE_CASE        =			self.image_processing_class.from_dict(self.image_processor_dict    ,							size=42    ,							crop_size=84			)
      self.assertEqual(image_processor.size    ,							{'''height''': 42, '''width''': 42}			)
      self.assertEqual(image_processor.crop_size    ,							{'''height''': 84, '''width''': 84}			)




    def   A   (   self			):





      '''simple docstring'''



      _SCREAMING_SNAKE_CASE        =			self.image_processing_class(**self.image_processor_dict			)
      # create random PIL images
      _SCREAMING_SNAKE_CASE        =			prepare_image_inputs(self.image_processor_tester    ,							equal_resolution=_UpperCAmelCase			)

      for image in image_inputs:
        self.assertIsInstance(_UpperCAmelCase    ,							Image.Image			)

      # Test not batched input
      _SCREAMING_SNAKE_CASE        =			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
      _SCREAMING_SNAKE_CASE        =			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   A   (   self			):





      '''simple docstring'''



      _SCREAMING_SNAKE_CASE        =			self.image_processing_class(**self.image_processor_dict			)
      # create random numpy tensors
      _SCREAMING_SNAKE_CASE        =			prepare_image_inputs(self.image_processor_tester    ,							equal_resolution=_UpperCAmelCase    ,							numpify=_UpperCAmelCase			)
      for image in image_inputs:
        self.assertIsInstance(_UpperCAmelCase    ,							np.ndarray			)

      # Test not batched input
      _SCREAMING_SNAKE_CASE        =			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
      _SCREAMING_SNAKE_CASE        =			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   A   (   self			):





      '''simple docstring'''



      _SCREAMING_SNAKE_CASE        =			self.image_processing_class(**self.image_processor_dict			)
      # create random PyTorch tensors
      _SCREAMING_SNAKE_CASE        =			prepare_image_inputs(self.image_processor_tester    ,							equal_resolution=_UpperCAmelCase    ,							torchify=_UpperCAmelCase			)
      for image in image_inputs:
        self.assertIsInstance(_UpperCAmelCase    ,							torch.Tensor			)

      # Test not batched input
      _SCREAMING_SNAKE_CASE        =			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
      _SCREAMING_SNAKE_CASE        =			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'''],
          )    ,							)




from __future__ import annotations

from collections.abc import Callable
def 			__SCREAMING_SNAKE_CASE							(					lowercase__	:Callable[[int | float], int | float]   ,    lowercase__	:int | float   ,    lowercase__	:int | float   ,    lowercase__	:int = 1_0_0   ,    )							->	float:
						__magic_name__					:				str				=   x_start
						__magic_name__					:				str				=   fnc(lowercase__					)
						__magic_name__					:				Union[str, Any]				=   0.0

						for _ in range(lowercase__					):
												# Approximates small segments of curve as linear and solve
												# for trapezoidal area
												__magic_name__					:				Optional[int]				=   (x_end - x_start) / steps + xa
												__magic_name__					:				List[Any]				=   fnc(lowercase__					)
												area += abs(fxa + fxa					) * (xa - xa) / 2

												# Increment step
												__magic_name__					:				Optional[Any]				=   xa
												__magic_name__					:				Union[str, Any]				=   fxa
						return area


if __name__ == "__main__":
			def 			__SCREAMING_SNAKE_CASE							(					lowercase__	:Dict					)							->	Optional[int]:
									return x**3

			print('f(x) = x^3')
			print('The area between the curve, x = -10, x = 10 and the x axis is:')
			snake_case__  				=			10
			while i <= 10_0000:
						snake_case__  				=			trapezoidal_area(f, -5, 5, i)
						print(F"""with {i} steps: {area}""")
						i *= 10


