






import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


snake_case__      :	str       	=      logging.get_logger(__name__)

snake_case__      :	List[str]       	=      {
    """BridgeTower/bridgetower-base""": """https://huggingface.co/BridgeTower/bridgetower-base/blob/main/config.json""",
    """BridgeTower/bridgetower-base-itm-mlm""": (
        """https://huggingface.co/BridgeTower/bridgetower-base-itm-mlm/blob/main/config.json"""
    ),
}


class 						_a       (  UpperCAmelCase__    ):






  """simple docstring"""





  A_						=   """bridgetower_vision_model"""




  def __init__(     self		,		_UpperCAmelCase=768		,		_UpperCAmelCase=12		,		_UpperCAmelCase=3		,		_UpperCAmelCase=16		,		_UpperCAmelCase=288		,		_UpperCAmelCase=1		,		_UpperCAmelCase=1e-05		,		_UpperCAmelCase=False		,		_UpperCAmelCase=True		,		_UpperCAmelCase=False		,		**_UpperCAmelCase		,		)			-> Tuple:
     super().__init__(**_UpperCAmelCase )
     UpperCamelCase_									=     hidden_size
     UpperCamelCase_									=     num_hidden_layers
     UpperCamelCase_									=     num_channels
     UpperCamelCase_									=     patch_size
     UpperCamelCase_									=     image_size
     UpperCamelCase_									=     initializer_factor
     UpperCamelCase_									=     layer_norm_eps
     UpperCamelCase_									=     stop_gradient
     UpperCamelCase_									=     share_layernorm
     UpperCamelCase_									=     remove_last_layer




  @classmethod
  def    _UpperCAmelCase     (     cls		,		_UpperCAmelCase		,		**_UpperCAmelCase )			-> "PretrainedConfig":
     UpperCamelCase_		,      UpperCamelCase_									=     cls.get_config_dict(_UpperCAmelCase		,		**_UpperCAmelCase )

     if config_dict.get('model_type' ) == "bridgetower":
        UpperCamelCase_									=     config_dict['text_config']

     if "model_type" in config_dict and hasattr(cls		,		'model_type' ) and config_dict["model_type"] != cls.model_type:
        logger.warning(
            f"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
            f"""{cls.model_type}. This is not supported for all configurations of models and can yield errors.""" )

     return cls.from_dict(_UpperCAmelCase		,		**_UpperCAmelCase )




class 						_a       (  UpperCAmelCase__    ):






  """simple docstring"""





  A_						=   """bridgetower_text_model"""




  def __init__(     self		,		_UpperCAmelCase=50265		,		_UpperCAmelCase=768		,		_UpperCAmelCase=12		,		_UpperCAmelCase=12		,		_UpperCAmelCase=1		,		_UpperCAmelCase=3072		,		_UpperCAmelCase="gelu"		,		_UpperCAmelCase=0.1		,		_UpperCAmelCase=0.1		,		_UpperCAmelCase=514		,		_UpperCAmelCase=1		,		_UpperCAmelCase=1e-05		,		_UpperCAmelCase=1		,		_UpperCAmelCase=0		,		_UpperCAmelCase=2		,		_UpperCAmelCase="absolute"		,		_UpperCAmelCase=True		,		**_UpperCAmelCase		,		)			-> str:
     super().__init__(**_UpperCAmelCase )

     UpperCamelCase_									=     vocab_size
     UpperCamelCase_									=     hidden_size
     UpperCamelCase_									=     num_hidden_layers
     UpperCamelCase_									=     num_attention_heads
     UpperCamelCase_									=     hidden_act
     UpperCamelCase_									=     initializer_factor
     UpperCamelCase_									=     intermediate_size
     UpperCamelCase_									=     hidden_dropout_prob
     UpperCamelCase_									=     attention_probs_dropout_prob
     UpperCamelCase_									=     max_position_embeddings
     UpperCamelCase_									=     type_vocab_size
     UpperCamelCase_									=     layer_norm_eps
     UpperCamelCase_									=     position_embedding_type
     UpperCamelCase_									=     use_cache
     UpperCamelCase_									=     pad_token_id
     UpperCamelCase_									=     bos_token_id
     UpperCamelCase_									=     eos_token_id




  @classmethod
  def    _UpperCAmelCase     (     cls		,		_UpperCAmelCase		,		**_UpperCAmelCase )			-> "PretrainedConfig":
     UpperCamelCase_		,      UpperCamelCase_									=     cls.get_config_dict(_UpperCAmelCase		,		**_UpperCAmelCase )

     if config_dict.get('model_type' ) == "bridgetower":
        UpperCamelCase_									=     config_dict['text_config']

     if "model_type" in config_dict and hasattr(cls		,		'model_type' ) and config_dict["model_type"] != cls.model_type:
        logger.warning(
            f"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
            f"""{cls.model_type}. This is not supported for all configurations of models and can yield errors.""" )

     return cls.from_dict(_UpperCAmelCase		,		**_UpperCAmelCase )




class 						_a       (  UpperCAmelCase__    ):






  """simple docstring"""





  A_						=   """bridgetower"""




  def __init__(     self		,		_UpperCAmelCase=True		,		_UpperCAmelCase="gelu"		,		_UpperCAmelCase=768		,		_UpperCAmelCase=1		,		_UpperCAmelCase=1e-05		,		_UpperCAmelCase=False		,		_UpperCAmelCase="add"		,		_UpperCAmelCase=12		,		_UpperCAmelCase=6		,		_UpperCAmelCase=False		,		_UpperCAmelCase=False		,		_UpperCAmelCase=None		,		_UpperCAmelCase=None		,		**_UpperCAmelCase		,		)			-> str:
     # TODO: remove this once the Hub files are updated.
     UpperCamelCase_									=     kwargs.pop('text_config_dict'		,		_UpperCAmelCase )
     UpperCamelCase_									=     kwargs.pop('vision_config_dict'		,		_UpperCAmelCase )

     super().__init__(**_UpperCAmelCase )
     UpperCamelCase_									=     share_cross_modal_transformer_layers
     UpperCamelCase_									=     hidden_act
     UpperCamelCase_									=     hidden_size
     UpperCamelCase_									=     initializer_factor
     UpperCamelCase_									=     layer_norm_eps
     UpperCamelCase_									=     share_link_tower_layers
     UpperCamelCase_									=     link_tower_type
     UpperCamelCase_									=     num_attention_heads
     UpperCamelCase_									=     num_hidden_layers
     UpperCamelCase_									=     tie_word_embeddings
     UpperCamelCase_									=     init_layernorm_from_vision_encoder

     if text_config is None:
        UpperCamelCase_									=     {}
        logger.info('`text_config` is `None`. Initializing the `BridgeTowerTextConfig` with default values.' )

     if vision_config is None:
        UpperCamelCase_									=     {}
        logger.info('`vision_config` is `None`. Initializing the `BridgeTowerVisionConfig` with default values.' )

     UpperCamelCase_									=     BridgeTowerTextConfig(**_UpperCAmelCase )
     UpperCamelCase_									=     BridgeTowerVisionConfig(**_UpperCAmelCase )




  @classmethod
  def    _UpperCAmelCase     (     cls		,		_UpperCAmelCase		,		_UpperCAmelCase		,		**_UpperCAmelCase )			-> Union[str, Any]:
     return cls(text_config=text_config.to_dict()		,		vision_config=vision_config.to_dict()		,		**_UpperCAmelCase )




  def    _UpperCAmelCase     (     self )			-> Optional[int]:
     UpperCamelCase_									=     copy.deepcopy(self.__dict__ )
     UpperCamelCase_									=     self.text_config.to_dict()
     UpperCamelCase_									=     self.vision_config.to_dict()
     UpperCamelCase_									=     self.__class__.model_type
     return output













from sympy import diff, lambdify, symbols
from sympy.functions import *  # noqa: F403






def     _snake_case    (__lowercase    ,      __lowercase    ,      __lowercase = "x"    ,      __lowercase = 10**-10    ,      __lowercase = 1    ,      ):
   UpperCamelCase_									=     symbols(__lowercase)
   UpperCamelCase_									=     lambdify(__lowercase    ,      __lowercase)
   UpperCamelCase_									=     lambdify(__lowercase    ,      diff(__lowercase    ,      __lowercase))

   UpperCamelCase_									=     starting_point

   while True:
      if diff_function(__lowercase) != 0:
         UpperCamelCase_									=     prev_guess - multiplicity * func(__lowercase) / diff_function(
             __lowercase)
      else:
         raise ZeroDivisionError('Could not find root') from None

      # Precision is checked by comparing the difference of consecutive guesses
      if abs(next_guess - prev_guess) < precision:
         return next_guess

      UpperCamelCase_									=     next_guess


# Let's Execute
if __name__ == "__main__":
 # Find root of trigonometric function
 # Find value of pi
 print(f'The root of sin(x) = 0 is {newton_raphson("sin(x)", 2)}')

 # Find root of polynomial
 # Find fourth Root of 5
 print(f'The root of x**4 - 5 = 0 is {newton_raphson("x**4 -5", 0.4 +5J)}')

 # Find value of e
 print(
     """The root of log(y) - 1 = 0 is """,
     f'{newton_raphson("log(y) - 1", 2, variable="y")}',
 )

 # Exponential Roots
 print(
     """The root of exp(x) - 1 = 0 is""",
     f'{newton_raphson("exp(x) - 1", 1_0, precision=0.005)}',
 )

 # Find root of cos(x)
 print(f'The root of cos(x) = 0 is {newton_raphson("cos(x)", 0)}')





