






import copy
import os
from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, Union


if TYPE_CHECKING:
	from ...processing_utils import ProcessorMixin
	from ...utils import TensorType

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


snake_case__      :	int       	=      logging.get_logger(__name__)

snake_case__      :	List[Any]       	=      {
    """google/owlvit-base-patch32""": """https://huggingface.co/google/owlvit-base-patch32/resolve/main/config.json""",
    """google/owlvit-base-patch16""": """https://huggingface.co/google/owlvit-base-patch16/resolve/main/config.json""",
    """google/owlvit-large-patch14""": """https://huggingface.co/google/owlvit-large-patch14/resolve/main/config.json""",
}


class 						_a       (  _snake_case    ):






		"""simple docstring"""





		A_						=   'owlvit_text_model'




		def __init__(     self		,		_UpperCAmelCase=49408		,		_UpperCAmelCase=512		,		_UpperCAmelCase=2048		,		_UpperCAmelCase=12		,		_UpperCAmelCase=8		,		_UpperCAmelCase=16		,		_UpperCAmelCase="quick_gelu"		,		_UpperCAmelCase=1e-5		,		_UpperCAmelCase=0.0		,		_UpperCAmelCase=0.0_2		,		_UpperCAmelCase=1.0		,		_UpperCAmelCase=0		,		_UpperCAmelCase=49406		,		_UpperCAmelCase=49407		,		**_UpperCAmelCase		,		)			-> Tuple:
					super().__init__(pad_token_id=_UpperCAmelCase		,		bos_token_id=_UpperCAmelCase		,		eos_token_id=_UpperCAmelCase		,		**_UpperCAmelCase )

					UpperCamelCase_									=     vocab_size
					UpperCamelCase_									=     hidden_size
					UpperCamelCase_									=     intermediate_size
					UpperCamelCase_									=     num_hidden_layers
					UpperCamelCase_									=     num_attention_heads
					UpperCamelCase_									=     max_position_embeddings
					UpperCamelCase_									=     hidden_act
					UpperCamelCase_									=     layer_norm_eps
					UpperCamelCase_									=     attention_dropout
					UpperCamelCase_									=     initializer_range
					UpperCamelCase_									=     initializer_factor




		@classmethod
		def    _UpperCAmelCase     (     cls		,		_UpperCAmelCase		,		**_UpperCAmelCase )			-> List[Any]:
					cls._set_token_in_kwargs(_UpperCAmelCase )

					UpperCamelCase_		,      UpperCamelCase_									=     cls.get_config_dict(_UpperCAmelCase		,		**_UpperCAmelCase )

					# get the text config dict if we are loading from OwlViTConfig
					if config_dict.get('model_type' ) == "owlvit":
								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       (  _snake_case    ):






		"""simple docstring"""





		A_						=   'owlvit_vision_model'




		def __init__(     self		,		_UpperCAmelCase=768		,		_UpperCAmelCase=3072		,		_UpperCAmelCase=12		,		_UpperCAmelCase=12		,		_UpperCAmelCase=3		,		_UpperCAmelCase=768		,		_UpperCAmelCase=32		,		_UpperCAmelCase="quick_gelu"		,		_UpperCAmelCase=1e-5		,		_UpperCAmelCase=0.0		,		_UpperCAmelCase=0.0_2		,		_UpperCAmelCase=1.0		,		**_UpperCAmelCase		,		)			-> int:
					super().__init__(**_UpperCAmelCase )

					UpperCamelCase_									=     hidden_size
					UpperCamelCase_									=     intermediate_size
					UpperCamelCase_									=     num_hidden_layers
					UpperCamelCase_									=     num_attention_heads
					UpperCamelCase_									=     num_channels
					UpperCamelCase_									=     image_size
					UpperCamelCase_									=     patch_size
					UpperCamelCase_									=     hidden_act
					UpperCamelCase_									=     layer_norm_eps
					UpperCamelCase_									=     attention_dropout
					UpperCamelCase_									=     initializer_range
					UpperCamelCase_									=     initializer_factor




		@classmethod
		def    _UpperCAmelCase     (     cls		,		_UpperCAmelCase		,		**_UpperCAmelCase )			-> Dict:
					cls._set_token_in_kwargs(_UpperCAmelCase )

					UpperCamelCase_		,      UpperCamelCase_									=     cls.get_config_dict(_UpperCAmelCase		,		**_UpperCAmelCase )

					# get the vision config dict if we are loading from OwlViTConfig
					if config_dict.get('model_type' ) == "owlvit":
								UpperCamelCase_									=     config_dict['vision_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       (  _snake_case    ):






		"""simple docstring"""





		A_						=   'owlvit'
		A_						=   True




		def __init__(     self		,		_UpperCAmelCase=None		,		_UpperCAmelCase=None		,		_UpperCAmelCase=512		,		_UpperCAmelCase=2.6_5_9_2		,		_UpperCAmelCase=True		,		**_UpperCAmelCase		,		)			-> str:
					super().__init__(**_UpperCAmelCase )

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

					if vision_config is None:
								UpperCamelCase_									=     {}
								logger.info('vision_config is None. initializing the OwlViTVisionConfig with default values.' )

					UpperCamelCase_									=     OwlViTTextConfig(**_UpperCAmelCase )
					UpperCamelCase_									=     OwlViTVisionConfig(**_UpperCAmelCase )

					UpperCamelCase_									=     projection_dim
					UpperCamelCase_									=     logit_scale_init_value
					UpperCamelCase_									=     return_dict
					UpperCamelCase_									=     1.0




		@classmethod
		def    _UpperCAmelCase     (     cls		,		_UpperCAmelCase		,		**_UpperCAmelCase )			-> Optional[Any]:
					cls._set_token_in_kwargs(_UpperCAmelCase )

					UpperCamelCase_		,      UpperCamelCase_									=     cls.get_config_dict(_UpperCAmelCase		,		**_UpperCAmelCase )

					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 )




		@classmethod
		def    _UpperCAmelCase     (     cls		,		_UpperCAmelCase		,		_UpperCAmelCase		,		**_UpperCAmelCase )			-> List[str]:
					UpperCamelCase_									=     {}
					UpperCamelCase_									=     text_config
					UpperCamelCase_									=     vision_config

					return cls.from_dict(_UpperCAmelCase		,		**_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




class 						_a       (  _snake_case    ):






		"""simple docstring"""





		@property
		def    _UpperCAmelCase     (     self )			-> Dict:
					return OrderedDict(
					    [
					        ('input_ids', {0: 'batch', 1: 'sequence'}),
					        ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
					        ('attention_mask', {0: 'batch', 1: 'sequence'}),
					    ] )




		@property
		def    _UpperCAmelCase     (     self )			-> Optional[int]:
					return OrderedDict(
					    [
					        ('logits_per_image', {0: 'batch'}),
					        ('logits_per_text', {0: 'batch'}),
					        ('text_embeds', {0: 'batch'}),
					        ('image_embeds', {0: 'batch'}),
					    ] )




		@property
		def    _UpperCAmelCase     (     self )			-> int:
					return 1e-4




		def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		_UpperCAmelCase = -1		,		_UpperCAmelCase = -1		,		_UpperCAmelCase = None		,		)			-> Tuple:
					UpperCamelCase_									=     super().generate_dummy_inputs(
					    processor.tokenizer		,		batch_size=_UpperCAmelCase		,		seq_length=_UpperCAmelCase		,		framework=_UpperCAmelCase )
					UpperCamelCase_									=     super().generate_dummy_inputs(
					    processor.image_processor		,		batch_size=_UpperCAmelCase		,		framework=_UpperCAmelCase )
					return {**text_input_dict, **image_input_dict}




		@property
		def    _UpperCAmelCase     (     self )			-> str:
					return 14













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





