
"""simple docstring"""







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


_SCREAMING_SNAKE_CASE	       =      logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE	       =      {
    """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 							__magic_name__     (		lowercase__   ):
					_SCREAMING_SNAKE_CASE       :					List[str]     							=   'owlvit_text_model'





					def __init__(				self   :							int							,						snake_case_   :							str=49408							,						snake_case_   :							Optional[Any]=512							,						snake_case_   :							Dict=2048							,						snake_case_   :							str=12							,						snake_case_   :							Any=8							,						snake_case_   :							Union[str, Any]=16							,						snake_case_   :							Optional[Any]="quick_gelu"							,						snake_case_   :							Any=1e-5							,						snake_case_   :							Any=0.0							,						snake_case_   :							Union[str, Any]=0.02							,						snake_case_   :							Union[str, Any]=1.0							,						snake_case_   :							Union[str, Any]=0							,						snake_case_   :							Dict=49406							,						snake_case_   :							Optional[Any]=49407							,						**snake_case_   :							int							,						):
												super().__init__(pad_token_id=snake_case_							,						bos_token_id=snake_case_							,						eos_token_id=snake_case_							,						**snake_case_    )

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





					@classmethod
					def 							lowerCAmelCase      (				cls   :							Optional[Any]							,						snake_case_   :							Union[str, os.PathLike]							,						**snake_case_   :							Tuple    ):
												cls._set_token_in_kwargs(snake_case_    )

												__snake_case			,   __snake_case     			=       cls.get_config_dict(snake_case_							,						**snake_case_    )

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







class 							__magic_name__     (		lowercase__   ):
					_SCREAMING_SNAKE_CASE       :					Any     							=   'owlvit_vision_model'





					def __init__(				self   :							Any							,						snake_case_   :							Optional[int]=768							,						snake_case_   :							Optional[Any]=3072							,						snake_case_   :							Union[str, Any]=12							,						snake_case_   :							Optional[Any]=12							,						snake_case_   :							Any=3							,						snake_case_   :							Union[str, Any]=768							,						snake_case_   :							Tuple=32							,						snake_case_   :							Tuple="quick_gelu"							,						snake_case_   :							List[Any]=1e-5							,						snake_case_   :							Dict=0.0							,						snake_case_   :							List[str]=0.02							,						snake_case_   :							List[str]=1.0							,						**snake_case_   :							str							,						):
												super().__init__(**snake_case_    )

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





					@classmethod
					def 							lowerCAmelCase      (				cls   :							Dict							,						snake_case_   :							Union[str, os.PathLike]							,						**snake_case_   :							Dict    ):
												cls._set_token_in_kwargs(snake_case_    )

												__snake_case			,   __snake_case     			=       cls.get_config_dict(snake_case_							,						**snake_case_    )

												# get the vision config dict if we are loading from OwlViTConfig
												if config_dict.get("model_type"    ) == "owlvit":
																			__snake_case     			=       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(snake_case_							,						**snake_case_    )







class 							__magic_name__     (		lowercase__   ):
					_SCREAMING_SNAKE_CASE       :					Dict     							=   'owlvit'
					_SCREAMING_SNAKE_CASE       :					Optional[Any]     							=   True





					def __init__(				self   :							Any							,						snake_case_   :							Dict=None							,						snake_case_   :							Union[str, Any]=None							,						snake_case_   :							str=512							,						snake_case_   :							List[str]=2.6592							,						snake_case_   :							List[str]=True							,						**snake_case_   :							Any							,						):
												super().__init__(**snake_case_    )

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

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

												__snake_case     			=       OwlViTTextConfig(**snake_case_    )
												__snake_case     			=       OwlViTVisionConfig(**snake_case_    )

												__snake_case     			=       projection_dim
												__snake_case     			=       logit_scale_init_value
												__snake_case     			=       return_dict
												__snake_case     			=       1.0





					@classmethod
					def 							lowerCAmelCase      (				cls   :							Tuple							,						snake_case_   :							Union[str, os.PathLike]							,						**snake_case_   :							str    ):
												cls._set_token_in_kwargs(snake_case_    )

												__snake_case			,   __snake_case     			=       cls.get_config_dict(snake_case_							,						**snake_case_    )

												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(snake_case_							,						**snake_case_    )





					@classmethod
					def 							lowerCAmelCase      (				cls   :							Optional[Any]							,						snake_case_   :							Dict							,						snake_case_   :							Dict							,						**snake_case_   :							int    ):
												__snake_case     			=       {}
												__snake_case     			=       text_config
												__snake_case     			=       vision_config

												return cls.from_dict(snake_case_							,						**snake_case_    )





					def 							lowerCAmelCase      (				self   :							Union[str, Any]    ):
												__snake_case     			=       copy.deepcopy(self.__dict__    )
												__snake_case     			=       self.text_config.to_dict()
												__snake_case     			=       self.vision_config.to_dict()
												__snake_case     			=       self.__class__.model_type
												return output







class 							__magic_name__     (		lowercase__   ):





					@property
					def 							lowerCAmelCase      (				self   :							str    ):
												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 							lowerCAmelCase      (				self   :							List[str]    ):
												return OrderedDict(
												    [
												        ("logits_per_image", {0: "batch"}),
												        ("logits_per_text", {0: "batch"}),
												        ("text_embeds", {0: "batch"}),
												        ("image_embeds", {0: "batch"}),
												    ]    )





					@property
					def 							lowerCAmelCase      (				self   :							Tuple    ):
												return 1e-4





					def 							lowerCAmelCase      (				self   :							Any							,						snake_case_   :							"ProcessorMixin"							,						snake_case_   :							int = -1							,						snake_case_   :							int = -1							,						snake_case_   :							Optional["TensorType"] = None							,						):
												__snake_case     			=       super().generate_dummy_inputs(
												    processor.tokenizer							,						batch_size=snake_case_							,						seq_length=snake_case_							,						framework=snake_case_    )
												__snake_case     			=       super().generate_dummy_inputs(
												    processor.image_processor							,						batch_size=snake_case_							,						framework=snake_case_    )
												return {**text_input_dict, **image_input_dict}





					@property
					def 							lowerCAmelCase      (				self   :							Tuple    ):
												return 14


"""simple docstring"""







from __future__ import annotations

from collections.abc import Callable
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE = 1_00							,    )  ->     float:







							"""simple docstring"""


							__snake_case     			=       x_start
							__snake_case     			=       fnc(SCREAMING_SNAKE_CASE )
							__snake_case     			=       0.0
							for _ in range(SCREAMING_SNAKE_CASE ):
														# Approximates small segments of curve as linear and solve
														# for trapezoidal area
														__snake_case     			=       (x_end - x_start) / steps + xa
														__snake_case     			=       fnc(SCREAMING_SNAKE_CASE )
														area += abs(fxa + fxa ) * (xa - xa) / 2
														# Increment step
														__snake_case     			=       xa
														__snake_case     			=       fxa
							return area


if __name__ == "__main__":
		def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE )  ->     List[Any]:







									"""simple docstring"""


									return x**3 + x**2

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