





"""simple docstring"""




import copy

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


UpperCamelCase_	 =logging.get_logger(__name__)




class 					_a		( _lowerCAmelCase							):
				UpperCamelCase								=       '''hybrid-clip'''
				UpperCamelCase								=       True






				def __init__(					self						:       List[str],					lowerCAmelCase__						:       Optional[int]=5_1_2,					**lowerCAmelCase__						:       Union[str, Any]				)      -> Optional[int]:




										'''simple docstring'''



										super().__init__(**lowerCAmelCase__				)

										if "text_config" not in kwargs:
																raise ValueError('''`text_config` can not be `None`.'''				)

										if "vision_config" not in kwargs:
																raise ValueError('''`vision_config` can not be `None`.'''				)

										_UpperCamelCase     :   Tuple      =       kwargs.pop('''text_config'''				)
										_UpperCamelCase     :   List[str]      =       kwargs.pop('''vision_config'''				)

										_UpperCamelCase     :   Tuple      =       text_config.pop('''model_type'''				)
										_UpperCamelCase     :   Tuple      =       vision_config.pop('''model_type'''				)

										from transformers import AutoConfig

										_UpperCamelCase     :   Any      =       AutoConfig.for_model(lowerCAmelCase__,					**lowerCAmelCase__				)

										if vision_model_type == "clip":
																_UpperCamelCase     :   Union[str, Any]      =       AutoConfig.for_model(lowerCAmelCase__,					**lowerCAmelCase__				).vision_config
										elif vision_model_type == "clip_vision_model":
																from transformers import CLIPVisionConfig

																_UpperCamelCase     :   List[Any]      =       CLIPVisionConfig(**lowerCAmelCase__				)
										else:
																_UpperCamelCase     :   Optional[Any]      =       AutoConfig.for_model(lowerCAmelCase__,					**lowerCAmelCase__				)

										_UpperCamelCase     :   Optional[Any]      =       projection_dim
										_UpperCamelCase     :   str      =       1.0






				@classmethod
				def 							snake_case      (					cls						:       int,					lowerCAmelCase__						:       PretrainedConfig,					lowerCAmelCase__						:       PretrainedConfig,					**lowerCAmelCase__						:       Optional[int]				)      -> Union[str, Any]:




										'''simple docstring'''



										return cls(text_config=text_config.to_dict(),					vision_config=vision_config.to_dict(),					**lowerCAmelCase__				)






				def 							snake_case      (					self						:       Tuple				)      -> List[Any]:




										'''simple docstring'''



										_UpperCamelCase     :   Optional[int]      =       copy.deepcopy(self.__dict__				)
										_UpperCamelCase     :   Union[str, Any]      =       self.text_config.to_dict()
										_UpperCamelCase     :   str      =       self.vision_config.to_dict()
										_UpperCamelCase     :   List[Any]      =       self.__class__.model_type
										return output










"""simple docstring"""




from .hash_table import HashTable
from .number_theory.prime_numbers import is_prime, next_prime




class 					_a		( _lowerCAmelCase							):






				def __init__(					self						:       Tuple,					*lowerCAmelCase__						:       Tuple,					**lowerCAmelCase__						:       Optional[int]				)      -> Union[str, Any]:




										'''simple docstring'''



										super().__init__(*lowerCAmelCase__,					**lowerCAmelCase__				)






				def 							snake_case      (					self						:       Any,					lowerCAmelCase__						:       Dict,					lowerCAmelCase__						:       Tuple				)      -> Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase     :   Tuple      =       (
										    next_prime(value % self.size_table				)
										    if not is_prime(value % self.size_table				)
										    else value % self.size_table
										)  # gt = bigger than
										return next_prime_gt - (data % next_prime_gt)






				def 							snake_case      (					self						:       int,					lowerCAmelCase__						:       Any,					lowerCAmelCase__						:       List[Any],					lowerCAmelCase__						:       Tuple				)      -> Any:




										'''simple docstring'''



										return (increment * self.__hash_function_a(lowerCAmelCase__,					lowerCAmelCase__				)) % self.size_table






				def 							snake_case      (					self						:       Dict,					lowerCAmelCase__						:       str,					lowerCAmelCase__						:       Optional[Any]=None				)      -> Union[str, Any]:




										'''simple docstring'''



										_UpperCamelCase     :   Tuple      =       1
										_UpperCamelCase     :   Dict      =       self.hash_function(lowerCAmelCase__				)

										while self.values[new_key] is not None and self.values[new_key] != key:
																_UpperCamelCase     :   Optional[int]      =       (
																    self.__hash_double_function(lowerCAmelCase__,					lowerCAmelCase__,					lowerCAmelCase__				)
																    if self.balanced_factor() >= self.lim_charge
																    else None
																)
																if new_key is None:
																						break
																else:
																						i += 1

										return new_key



