





from math import exp


def        __SCREAMING_SNAKE_CASE	(				__lowercase:		float):



  '''simple docstring'''






  return 8 * x - 2 * exp(-x)


def        __SCREAMING_SNAKE_CASE	(				__lowercase:		float  ,				__lowercase:		float  ,				__lowercase:		int):



  '''simple docstring'''






  __lowerCAmelCase								=					lower_bound
  __lowerCAmelCase								=					upper_bound
  for _ in range(0  ,				__lowercase):
    __lowerCAmelCase						,    __lowerCAmelCase								=					xa, xa - (f(__lowercase) * (xa - xa)) / (f(__lowercase) - f(__lowercase))
  return xa


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







import os
import pathlib
import tempfile
import uuid

import numpy as np

from ..utils import is_soundfile_availble, is_torch_available, is_vision_available, logging


__lowercase				    =      logging.get_logger(__name__)

if is_vision_available():
      import PIL.Image
      from PIL import Image
      from PIL.Image import Image as ImageType
else:
      __lowercase				    =      object

if is_torch_available():
      import torch

if is_soundfile_availble():
      import soundfile as sf

class 	__snake_case					:






    '''simple docstring'''





    def __init__( self    :		Optional[int]      ,    snake_case    :		int				):

      """simple docstring"""





      __lowerCAmelCase								=					value





    def __str__( self    :		List[Any]				):

      """simple docstring"""





      return self.to_string()





    def 						A		( self    :		int				):

      """simple docstring"""





      logger.error(
          '''This is a raw AgentType of unknown type. Display in notebooks and string conversion will be unreliable'''				)
      return self._value





    def 						A		( self    :		Optional[int]				):

      """simple docstring"""





      logger.error(
          '''This is a raw AgentType of unknown type. Display in notebooks and string conversion will be unreliable'''				)
      return str(self._value				)


class 	__snake_case					(      _a							,					_a ):






    '''simple docstring'''





    def 						A		( self    :		int				):

      """simple docstring"""





      return self._value





    def 						A		( self    :		List[str]				):

      """simple docstring"""





      return self._value


class 	__snake_case					(      _a							,					_a ):






    '''simple docstring'''





    def __init__( self    :		int      ,    snake_case    :		Optional[int]				):

      """simple docstring"""





      super().__init__(snake_case				)

      if not is_vision_available():
        raise ImportError('''PIL must be installed in order to handle images.'''				)

      __lowerCAmelCase								=					None
      __lowerCAmelCase								=					None
      __lowerCAmelCase								=					None

      if isinstance(snake_case      ,    snake_case				):
        __lowerCAmelCase								=					value
      elif isinstance(snake_case      ,    (str, pathlib.Path)				):
        __lowerCAmelCase								=					value
      elif isinstance(snake_case      ,    torch.Tensor				):
        __lowerCAmelCase								=					value
      else:
        raise ValueError(f'''Unsupported type for {self.__class__.__name__}: {type(snake_case				)}'''				)





    def 						A		( self    :		Tuple      ,    snake_case    :		Union[str, Any]=None      ,    snake_case    :		int=None				):

      """simple docstring"""





      from IPython.display import Image, display

      display(Image(self.to_string()				)				)





    def 						A		( self    :		Optional[Any]				):

      """simple docstring"""





      if self._raw is not None:
        return self._raw

      if self._path is not None:
        __lowerCAmelCase								=					Image.open(self._path				)
        return self._raw





    def 						A		( self    :		List[Any]				):

      """simple docstring"""





      if self._path is not None:
        return self._path

      if self._raw is not None:
        __lowerCAmelCase								=					tempfile.mkdtemp()
        __lowerCAmelCase								=					os.path.join(snake_case      ,    str(uuid.uuida()				) + '''.png'''				)
        self._raw.save(self._path				)

        return self._path

      if self._tensor is not None:
        __lowerCAmelCase								=					self._tensor.cpu().detach().numpy()

        # There is likely simpler than load into image into save
        __lowerCAmelCase								=					Image.fromarray((array * 255).astype(np.uinta				)				)

        __lowerCAmelCase								=					tempfile.mkdtemp()
        __lowerCAmelCase								=					os.path.join(snake_case      ,    str(uuid.uuida()				) + '''.png'''				)

        img.save(self._path				)

        return self._path


class 	__snake_case					(      _a ):






    '''simple docstring'''





    def __init__( self    :		List[Any]      ,    snake_case    :		int      ,    snake_case    :		Any=16_000				):

      """simple docstring"""





      super().__init__(snake_case				)

      if not is_soundfile_availble():
        raise ImportError('''soundfile must be installed in order to handle audio.'''				)

      __lowerCAmelCase								=					None
      __lowerCAmelCase								=					None

      __lowerCAmelCase								=					samplerate

      if isinstance(snake_case      ,    (str, pathlib.Path)				):
        __lowerCAmelCase								=					value
      elif isinstance(snake_case      ,    torch.Tensor				):
        __lowerCAmelCase								=					value
      else:
        raise ValueError(f'''Unsupported audio type: {type(snake_case				)}'''				)





    def 						A		( self    :		Optional[int]      ,    snake_case    :		Tuple=None      ,    snake_case    :		Tuple=None				):

      """simple docstring"""





      from IPython.display import Audio, display

      display(Audio(self.to_string()      ,    rate=self.samplerate				)				)





    def 						A		( self    :		Optional[int]				):

      """simple docstring"""





      if self._tensor is not None:
        return self._tensor

      if self._path is not None:
        __lowerCAmelCase						,    __lowerCAmelCase								=					sf.read(self._path				)
        __lowerCAmelCase								=					torch.tensor(snake_case				)
        return self._tensor





    def 						A		( self    :		Optional[Any]				):

      """simple docstring"""





      if self._path is not None:
        return self._path

      if self._tensor is not None:
        __lowerCAmelCase								=					tempfile.mkdtemp()
        __lowerCAmelCase								=					os.path.join(snake_case      ,    str(uuid.uuida()				) + '''.wav'''				)
        sf.write(self._path      ,    self._tensor      ,    samplerate=self.samplerate				)
        return self._path


__lowercase				    =      {"""text""": AgentText, """image""": AgentImage, """audio""": AgentAudio}
__lowercase				    =      {str: AgentText}

if is_vision_available():
      __lowercase				    =      AgentImage


def        __SCREAMING_SNAKE_CASE	(				*__lowercase:		List[Any]  ,				**__lowercase:		Tuple):



  '''simple docstring'''






  __lowerCAmelCase								=					[(arg.to_raw() if isinstance(__lowercase  ,				__lowercase) else arg) for arg in args]
  __lowerCAmelCase								=					{k: (v.to_raw() if isinstance(__lowercase  ,				__lowercase) else v) for k, v in kwargs.items()}
  return args, kwargs




def        __SCREAMING_SNAKE_CASE	(				__lowercase:		List[Any]  ,				__lowercase:		List[Any]=None):



  '''simple docstring'''






  if isinstance(__lowercase  ,				__lowercase):
    __lowerCAmelCase								=					{}
    for i, (k, v) in enumerate(outputs.items()):
      if output_types is not None:
        # If the class has defined outputs, we can map directly according to the class definition
        if output_types[i] in AGENT_TYPE_MAPPING:
          __lowerCAmelCase								=					AGENT_TYPE_MAPPING[output_types[i]](__lowercase)
        else:
          __lowerCAmelCase								=					AgentType(__lowercase)

      else:
        # If the class does not have defined output, then we map according to the type
        for _k, _v in INSTANCE_TYPE_MAPPING.items():
          if isinstance(__lowercase  ,				_k):
            __lowerCAmelCase								=					_v(__lowercase)
        if k not in decoded_outputs:
          __lowerCAmelCase								=					AgentType[v]

  elif isinstance(__lowercase  ,				(list, tuple)):
    __lowerCAmelCase								=					type(__lowercase)()
    for i, v in enumerate(__lowercase):
      if output_types is not None:
        # If the class has defined outputs, we can map directly according to the class definition
        if output_types[i] in AGENT_TYPE_MAPPING:
          decoded_outputs.append(AGENT_TYPE_MAPPING[output_types[i]](__lowercase))
        else:
          decoded_outputs.append(AgentType(__lowercase))
      else:
        # If the class does not have defined output, then we map according to the type
        __lowerCAmelCase								=					False
        for _k, _v in INSTANCE_TYPE_MAPPING.items():
          if isinstance(__lowercase  ,				_k):
            decoded_outputs.append(_v(__lowercase))
            __lowerCAmelCase								=					True

        if not found:
          decoded_outputs.append(AgentType(__lowercase))

  else:
    if output_types[0] in AGENT_TYPE_MAPPING:
      # If the class has defined outputs, we can map directly according to the class definition
      __lowerCAmelCase								=					AGENT_TYPE_MAPPING[output_types[0]](__lowercase)

    else:
      # If the class does not have defined output, then we map according to the type
      for _k, _v in INSTANCE_TYPE_MAPPING.items():
        if isinstance(__lowercase  ,				_k):
          return _v(__lowercase)
      return AgentType(__lowercase)

  return decoded_outputs
