




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



  def __init__( self		,    __lowerCAmelCase		,    __lowerCAmelCase=7		,    __lowerCAmelCase=3		,    __lowerCAmelCase=18		,    __lowerCAmelCase=30		,    __lowerCAmelCase=400		,    __lowerCAmelCase=True		,    __lowerCAmelCase=None		,    __lowerCAmelCase=True		,    __lowerCAmelCase=None		,    __lowerCAmelCase=True		,    __lowerCAmelCase=[0.48145466, 0.4578275, 0.40821073]		,    __lowerCAmelCase=[0.26862954, 0.26130258, 0.27577711]		,    __lowerCAmelCase=True		,    ):







      '''simple docstring'''


      _a							:       List[Any]       					=			size if size is not None else {"""shortest_edge""": 20}
      _a							:       str       					=			crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
      _a							:       Tuple       					=			parent
      _a							:       Optional[Any]       					=			batch_size
      _a							:       Dict       					=			num_channels
      _a							:       Union[str, Any]       					=			image_size
      _a							:       List[str]       					=			min_resolution
      _a							:       int       					=			max_resolution
      _a							:       Tuple       					=			do_resize
      _a							:       List[str]       					=			size
      _a							:       List[str]       					=			do_center_crop
      _a							:       Any       					=			crop_size
      _a							:       Any       					=			do_normalize
      _a							:       Tuple       					=			image_mean
      _a							:       List[str]       					=			image_std
      _a							:       Union[str, Any]       					=			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,
      }



  def 						a_       ( self		,    __lowerCAmelCase=False		,    __lowerCAmelCase=False		,    __lowerCAmelCase=False   ):







      '''simple docstring'''


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

      if equal_resolution:
          _a							:       Optional[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:
          _a							:       List[Any]       					=			[]
          for i in range(self.batch_size   ):
              _a					,   _a							:       Optional[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
          _a							:       List[str]       					=			[Image.fromarray(np.moveaxis(_lowerCAmelCase		,    0		,    -1   )   ) for x in image_inputs]

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

      return image_inputs






@require_torch
@require_vision
class     UpperCamelCase					(  A__			,		unittest.TestCase					):
  a    :Any      					=				CLIPImageProcessor if is_vision_available() else None



  def 						a_       ( self   ):







      '''simple docstring'''


      _a							:       Optional[int]       					=			CLIPImageProcessingTester(self   )



  @property
  def 						a_       ( self   ):







      '''simple docstring'''


      return self.image_processor_tester.prepare_image_processor_dict()



  def 						a_       ( self   ):







      '''simple docstring'''


      _a							:       Any       					=			self.image_processing_class(**self.image_processor_dict   )
      self.assertTrue(hasattr(_lowerCAmelCase		,    """do_resize"""   )   )
      self.assertTrue(hasattr(_lowerCAmelCase		,    """size"""   )   )
      self.assertTrue(hasattr(_lowerCAmelCase		,    """do_center_crop"""   )   )
      self.assertTrue(hasattr(_lowerCAmelCase		,    """center_crop"""   )   )
      self.assertTrue(hasattr(_lowerCAmelCase		,    """do_normalize"""   )   )
      self.assertTrue(hasattr(_lowerCAmelCase		,    """image_mean"""   )   )
      self.assertTrue(hasattr(_lowerCAmelCase		,    """image_std"""   )   )
      self.assertTrue(hasattr(_lowerCAmelCase		,    """do_convert_rgb"""   )   )



  def 						a_       ( self   ):







      '''simple docstring'''


      _a							:       Optional[int]       					=			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}   )

      _a							:       Dict       					=			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   ):







      '''simple docstring'''


      pass



  def 						a_       ( self   ):







      '''simple docstring'''


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

      # Test not batched input
      _a							:       Union[str, Any]       					=			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
      _a							:       int       					=			image_processing(_lowerCAmelCase		,    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'''


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

      # Test not batched input
      _a							:       Optional[Any]       					=			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
      _a							:       Optional[int]       					=			image_processing(_lowerCAmelCase		,    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'''


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

      # Test not batched input
      _a							:       Optional[Any]       					=			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
      _a							:       Dict       					=			image_processing(_lowerCAmelCase		,    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     UpperCamelCase					(  A__			,		unittest.TestCase					):
  a    :Any      					=				CLIPImageProcessor if is_vision_available() else None



  def 						a_       ( self   ):







      '''simple docstring'''


      _a							:       str       					=			CLIPImageProcessingTester(self		,    num_channels=4   )
      _a							:       str       					=			3



  @property
  def 						a_       ( self   ):







      '''simple docstring'''


      return self.image_processor_tester.prepare_image_processor_dict()



  def 						a_       ( self   ):







      '''simple docstring'''


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



  def 						a_       ( self   ):







      '''simple docstring'''


      pass



  def 						a_       ( self   ):







      '''simple docstring'''


      _a							:       Tuple       					=			self.image_processing_class(**self.image_processor_dict   )
      # create random PIL images
      _a							:       int       					=			self.image_processor_tester.prepare_inputs(equal_resolution=_lowerCAmelCase   )
      for image in image_inputs:
          self.assertIsInstance(_lowerCAmelCase		,    Image.Image   )

      # Test not batched input
      _a							:       Optional[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
      _a							:       Optional[Any]       					=			image_processing(_lowerCAmelCase		,    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 math import exp





def UpperCAmelCase						(					UpperCAmelCase_	):
    return 8 * x - 2 * exp(-x	)





def UpperCAmelCase						(					UpperCAmelCase_      ,  UpperCAmelCase_      ,  UpperCAmelCase_	):
    _a							:       Optional[int]       					=			lower_bound
    _a							:       str       					=			upper_bound
    for _ in range(0      ,  UpperCAmelCase_	):
        _a					,   _a							:       List[str]       					=			xa, xa - (f(UpperCAmelCase_	) * (xa - xa)) / (f(UpperCAmelCase_	) - f(UpperCAmelCase_	))
    return xa


if __name__ == "__main__":
  print(F"""Example: {secant_method(1, 3, 2)}""")


