






'''simple docstring'''







import copy
import os
from typing import Union

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


UpperCamelCase     :   Tuple	      =		logging.get_logger(__name__)

UpperCamelCase     :   Any	      =		{
    'Salesforce/blip-vqa-base': 'https://huggingface.co/Salesforce/blip-vqa-base/resolve/main/config.json',
    'Salesforce/blip-vqa-capfit-large': (
        'https://huggingface.co/Salesforce/blip-vqa-base-capfit/resolve/main/config.json'
    ),
    'Salesforce/blip-image-captioning-base': (
        'https://huggingface.co/Salesforce/blip-image-captioning-base/resolve/main/config.json'
    ),
    'Salesforce/blip-image-captioning-large': (
        'https://huggingface.co/Salesforce/blip-image-captioning-large/resolve/main/config.json'
    ),
    'Salesforce/blip-itm-base-coco': 'https://huggingface.co/Salesforce/blip-itm-base-coco/resolve/main/config.json',
    'Salesforce/blip-itm-large-coco': 'https://huggingface.co/Salesforce/blip-itm-large-coco/resolve/main/config.json',
    'Salesforce/blip-itm-base-flikr': 'https://huggingface.co/Salesforce/blip-itm-base-flikr/resolve/main/config.json',
    'Salesforce/blip-itm-large-flikr': (
        'https://huggingface.co/Salesforce/blip-itm-large-flikr/resolve/main/config.json'
    ),
}




class 		UpperCamelCase__     (a      ):




		'''simple docstring'''





		_UpperCamelCase						=       'blip_text_model'






		def __init__(   self ,_lowerCAmelCase=3_05_24 ,_lowerCAmelCase=7_68 ,_lowerCAmelCase=7_68 ,_lowerCAmelCase=30_72 ,_lowerCAmelCase=7_68 ,_lowerCAmelCase=12 ,_lowerCAmelCase=8 ,_lowerCAmelCase=5_12 ,_lowerCAmelCase="gelu" ,_lowerCAmelCase=1E-12 ,_lowerCAmelCase=0.0 ,_lowerCAmelCase=0.0 ,_lowerCAmelCase=0.02 ,_lowerCAmelCase=3_05_22 ,_lowerCAmelCase=2 ,_lowerCAmelCase=0 ,_lowerCAmelCase=1_02 ,_lowerCAmelCase=True ,_lowerCAmelCase=True ,**_lowerCAmelCase ,):
								super().__init__(
								    pad_token_id=_lowerCAmelCase ,bos_token_id=_lowerCAmelCase ,eos_token_id=_lowerCAmelCase ,sep_token_id=_lowerCAmelCase ,**_lowerCAmelCase ,)

								lowerCamelCase__								=	vocab_size
								lowerCamelCase__								=	hidden_size
								lowerCamelCase__								=	encoder_hidden_size
								lowerCamelCase__								=	intermediate_size
								lowerCamelCase__								=	projection_dim
								lowerCamelCase__								=	hidden_dropout_prob
								lowerCamelCase__								=	num_hidden_layers
								lowerCamelCase__								=	num_attention_heads
								lowerCamelCase__								=	max_position_embeddings
								lowerCamelCase__								=	layer_norm_eps
								lowerCamelCase__								=	hidden_act
								lowerCamelCase__								=	initializer_range
								lowerCamelCase__								=	attention_probs_dropout_prob
								lowerCamelCase__								=	is_decoder
								lowerCamelCase__								=	use_cache






		@classmethod
		def       UpperCamelCase_       (   cls ,_lowerCAmelCase ,**_lowerCAmelCase							):
								cls._set_token_in_kwargs(_lowerCAmelCase							)

								lowerCamelCase__							,      lowerCamelCase__								=	cls.get_config_dict(_lowerCAmelCase ,**_lowerCAmelCase							)

								# get the text config dict if we are loading from BlipConfig
								if config_dict.get("""model_type"""							) == "blip":
														lowerCamelCase__								=	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(_lowerCAmelCase ,**_lowerCAmelCase							)




class 		UpperCamelCase__     (a      ):




		'''simple docstring'''





		_UpperCamelCase						=       'blip_vision_model'






		def __init__(   self ,_lowerCAmelCase=7_68 ,_lowerCAmelCase=30_72 ,_lowerCAmelCase=5_12 ,_lowerCAmelCase=12 ,_lowerCAmelCase=12 ,_lowerCAmelCase=3_84 ,_lowerCAmelCase=16 ,_lowerCAmelCase="gelu" ,_lowerCAmelCase=1E-5 ,_lowerCAmelCase=0.0 ,_lowerCAmelCase=1E-10 ,**_lowerCAmelCase ,):
								super().__init__(**_lowerCAmelCase							)

								lowerCamelCase__								=	hidden_size
								lowerCamelCase__								=	intermediate_size
								lowerCamelCase__								=	projection_dim
								lowerCamelCase__								=	num_hidden_layers
								lowerCamelCase__								=	num_attention_heads
								lowerCamelCase__								=	patch_size
								lowerCamelCase__								=	image_size
								lowerCamelCase__								=	initializer_range
								lowerCamelCase__								=	attention_dropout
								lowerCamelCase__								=	layer_norm_eps
								lowerCamelCase__								=	hidden_act






		@classmethod
		def       UpperCamelCase_       (   cls ,_lowerCAmelCase ,**_lowerCAmelCase							):
								cls._set_token_in_kwargs(_lowerCAmelCase							)

								lowerCamelCase__							,      lowerCamelCase__								=	cls.get_config_dict(_lowerCAmelCase ,**_lowerCAmelCase							)

								# get the vision config dict if we are loading from BlipConfig
								if config_dict.get("""model_type"""							) == "blip":
														lowerCamelCase__								=	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(_lowerCAmelCase ,**_lowerCAmelCase							)




class 		UpperCamelCase__     (a      ):




		'''simple docstring'''





		_UpperCamelCase						=       'blip'
		_UpperCamelCase						=       True






		def __init__(   self ,_lowerCAmelCase=None ,_lowerCAmelCase=None ,_lowerCAmelCase=5_12 ,_lowerCAmelCase=2.6592 ,_lowerCAmelCase=2_56 ,**_lowerCAmelCase ,):
								super().__init__(**_lowerCAmelCase							)

								if text_config is None:
														lowerCamelCase__								=	{}
														logger.info("""`text_config` is `None`. Initializing the `BlipTextConfig` with default values."""							)

								if vision_config is None:
														lowerCamelCase__								=	{}
														logger.info("""`vision_config` is `None`. Initializing the `BlipVisionConfig` with default values."""							)

								lowerCamelCase__								=	BlipTextConfig(**_lowerCAmelCase							)
								lowerCamelCase__								=	BlipVisionConfig(**_lowerCAmelCase							)

								lowerCamelCase__								=	self.vision_config.hidden_size

								lowerCamelCase__								=	projection_dim
								lowerCamelCase__								=	logit_scale_init_value
								lowerCamelCase__								=	1.0
								lowerCamelCase__								=	0.02
								lowerCamelCase__								=	image_text_hidden_size






		@classmethod
		def       UpperCamelCase_       (   cls ,_lowerCAmelCase ,_lowerCAmelCase ,**_lowerCAmelCase							):
								return cls(text_config=text_config.to_dict() ,vision_config=vision_config.to_dict() ,**_lowerCAmelCase							)






		def       UpperCamelCase_       (   self							):
								lowerCamelCase__								=	copy.deepcopy(self.__dict__							)
								lowerCamelCase__								=	self.text_config.to_dict()
								lowerCamelCase__								=	self.vision_config.to_dict()
								lowerCamelCase__								=	self.__class__.model_type
								return output




from __future__ import annotations

# This is the precision for this function which can be altered.
# It is recommended for users to keep this number greater than or equal to 10.
__snake_case				:      Optional[Any]   		=			10


def 					_UpperCAmelCase				(						a__  ,	a__  ,	a__  ,	a__):

			'''simple docstring'''



			for i in range(a__  ,	a__):
						if array[i] == target:
									return i
			return -1


def 					_UpperCAmelCase				(						a__  ,	a__):

			'''simple docstring'''



			a_						:						Any 							= 0
			a_						:						List[str] 							= len(a__)
			while left <= right:
						if right - left < precision:
									return lin_search(a__  ,	a__  ,	a__  ,	a__)

						a_						:						Dict 							= (left + right) // 3 + 1
						a_						:						Optional[Any] 							= 2 * (left + right) // 3 + 1

						if array[one_third] == target:
									return one_third
						elif array[two_third] == target:
									return two_third

						elif target < array[one_third]:
									a_						:						int 							= one_third - 1
						elif array[two_third] < target:
									a_						:						Any 							= two_third + 1

						else:
									a_						:						Optional[int] 							= one_third + 1
									a_						:						int 							= two_third - 1
			else:
						return -1


def 					_UpperCAmelCase				(						a__  ,	a__  ,	a__  ,	a__):

			'''simple docstring'''



			if left < right:
						if right - left < precision:
									return lin_search(a__  ,	a__  ,	a__  ,	a__)
						a_						:						Optional[int] 							= (left + right) // 3 + 1
						a_						:						Union[str, Any] 							= 2 * (left + right) // 3 + 1

						if array[one_third] == target:
									return one_third
						elif array[two_third] == target:
									return two_third

						elif target < array[one_third]:
									return rec_ternary_search(a__  ,	one_third - 1  ,	a__  ,	a__)
						elif array[two_third] < target:
									return rec_ternary_search(two_third + 1  ,	a__  ,	a__  ,	a__)
						else:
									return rec_ternary_search(one_third + 1  ,	two_third - 1  ,	a__  ,	a__)
			else:
						return -1


if __name__ == "__main__":
	import doctest

	doctest.testmod()

	__snake_case				:      Optional[int]   		=			input("""Enter numbers separated by comma:\n""").strip()
	__snake_case				:      Optional[int]   		=			[int(item.strip()) for item in user_input.split(""",""")]
	assert collection == sorted(collection), F"List must be ordered.\n{collection}."
	__snake_case				:      int   		=			int(input("""Enter the number to be found in the list:\n""").strip())
	__snake_case				:      List[Any]   		=			ite_ternary_search(collection, target)
	__snake_case				:      Optional[int]   		=			rec_ternary_search(0, len(collection) - 1, collection, target)
	if resulta != -1:
		print(F"""Iterative search: {target} found at positions: {resulta}""")
		print(F"""Recursive search: {target} found at positions: {resulta}""")
	else:
		print("""Not found""")


