
"""simple docstring"""


import copy
import os
from typing import Union

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


_lowercase							   =				logging.get_logger(__name__)

_lowercase							   =				{
    '''BAAI/AltCLIP''': '''https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json''',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}







class 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


						_lowerCamelCase:    Dict      =    '''altclip_text_model'''


						def __init__( self     :      Tuple  ,A_     :      Optional[Any]=25_0002  ,A_     :      str=1024  ,A_     :      int=24  ,A_     :      str=16  ,A_     :      Dict=4096  ,A_     :      Optional[Any]="gelu"  ,A_     :      Optional[Any]=0.1  ,A_     :      Any=0.1  ,A_     :      Any=514  ,A_     :      str=1  ,A_     :      Union[str, Any]=0.02  ,A_     :      Tuple=0.02  ,A_     :      Optional[int]=1e-05  ,A_     :      Optional[Any]=1  ,A_     :      Tuple=0  ,A_     :      List[str]=2  ,A_     :      str="absolute"  ,A_     :      Optional[int]=True  ,A_     :      Union[str, Any]=768  ,**A_     :      Optional[Any]  ,)     ->   Dict:
							super().__init__(pad_token_id=A_  ,bos_token_id=A_  ,eos_token_id=A_  ,**A_      )

							A						   =   vocab_size
							A						   =   hidden_size
							A						   =   num_hidden_layers
							A						   =   num_attention_heads
							A						   =   hidden_act
							A						   =   intermediate_size
							A						   =   hidden_dropout_prob
							A						   =   attention_probs_dropout_prob
							A						   =   max_position_embeddings
							A						   =   type_vocab_size
							A						   =   initializer_range
							A						   =   initializer_factor
							A						   =   layer_norm_eps
							A						   =   position_embedding_type
							A						   =   use_cache
							A						   =   project_dim







class 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


						_lowerCamelCase:    Optional[int]      =    '''altclip_vision_model'''


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

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




						@classmethod
						def 						_SCREAMING_SNAKE_CASE      ( cls     :      List[Any]  ,A_     :      Union[str, os.PathLike]  ,**A_     :      Dict      )     ->   "PretrainedConfig":
							cls._set_token_in_kwargs(A_      )

							A   ,      A						   =   cls.get_config_dict(A_  ,**A_      )

							# get the vision config dict if we are loading from AltCLIPConfig
							if config_dict.get('model_type'      ) == "altclip":
								A						   =   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(A_  ,**A_      )







class 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


						_lowerCamelCase:    int      =    '''altclip'''
						_lowerCamelCase:    Union[str, Any]      =    True


						def __init__( self     :      List[str]  ,A_     :      Optional[Any]=None  ,A_     :      List[Any]=None  ,A_     :      Optional[int]=768  ,A_     :      Optional[Any]=2.65_92  ,**A_     :      str      )     ->   Optional[Any]:
							# If `_config_dict` exist, we use them for the backward compatibility.
							# We pop out these 2 attributes before calling `super().__init__` to avoid them being saved (which causes a lot
							# of confusion!).
							A						   =   kwargs.pop('text_config_dict'  ,A_      )
							A						   =   kwargs.pop('vision_config_dict'  ,A_      )

							super().__init__(**A_      )

							# Instead of simply assigning `[text|vision]_config_dict` to `[text|vision]_config`, we use the values in
							# `[text|vision]_config_dict` to update the values in `[text|vision]_config`. The values should be same in most
							# cases, but we don't want to break anything regarding `_config_dict` that existed before commit `8827e1b2`.
							if text_config_dict is not None:
								if text_config is None:
									A						   =   {}

								# This is the complete result when using `text_config_dict`.
								A						   =   AltCLIPTextConfig(**A_      ).to_dict()

								# Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
								for key, value in _text_config_dict.items():
									if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
										# If specified in `text_config_dict`
										if key in text_config_dict:
											A						   =   (
											    F'`{key}` is found in both `text_config_dict` and `text_config` but with different values. '
											    F'The value `text_config_dict["{key}"]` will be used instead.'
											)
										# If inferred from default argument values (just to be super careful)
										else:
											A						   =   (
											    F'`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The '
											    F'value `text_config["{key}"]` will be overriden.'
											)
										logger.warning(A_      )

            # Update all values in `text_config` with the ones in `_text_config_dict`.
								text_config.update(_text_config_dict      )

							if vision_config_dict is not None:
								if vision_config is None:
									A						   =   {}

								# This is the complete result when using `vision_config_dict`.
								A						   =   AltCLIPVisionConfig(**A_      ).to_dict()
								# convert keys to string instead of integer
								if "id2label" in _vision_config_dict:
									A						   =   {
									    str(A_      ): value for key, value in _vision_config_dict['id2label'].items()
									}

								# Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
								for key, value in _vision_config_dict.items():
									if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
										# If specified in `vision_config_dict`
										if key in vision_config_dict:
											A						   =   (
											    F'`{key}` is found in both `vision_config_dict` and `vision_config` but with different '
											    F'values. The value `vision_config_dict["{key}"]` will be used instead.'
											)
										# If inferred from default argument values (just to be super careful)
										else:
											A						   =   (
											    F'`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. '
											    F'The value `vision_config["{key}"]` will be overriden.'
											)
										logger.warning(A_      )

            # Update all values in `vision_config` with the ones in `_vision_config_dict`.
								vision_config.update(_vision_config_dict      )

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

							if vision_config is None:
								A						   =   {}
								logger.info('`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values.'      )

							A						   =   AltCLIPTextConfig(**A_      )
							A						   =   AltCLIPVisionConfig(**A_      )

							A						   =   projection_dim
							A						   =   logit_scale_init_value
							A						   =   1.0


						@classmethod
						def 						_SCREAMING_SNAKE_CASE      ( cls     :      Dict  ,A_     :      AltCLIPTextConfig  ,A_     :      AltCLIPVisionConfig  ,**A_     :      List[Any]      )     ->   Any:
							return cls(text_config=text_config.to_dict()  ,vision_config=vision_config.to_dict()  ,**A_      )




						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any      )     ->   Any:
							A						   =   copy.deepcopy(self.__dict__      )
							A						   =   self.text_config.to_dict()
							A						   =   self.vision_config.to_dict()
							A						   =   self.__class__.model_type
							return output

"""simple docstring"""


def       _snake_case				(		snake_case__   :     list	,      snake_case__   :     list	,      snake_case__   :     int     ):
	A						   =   len(snake_case__     )
	A						   =   [[0] * n for i in range(snake_case__     )]
	for i in range(snake_case__     ):
		A						   =   y_points[i]

	for i in range(2	,      snake_case__     ):
		for j in range(snake_case__	,      snake_case__     ):
			A						   =   (
			    (xa - x_points[j - i + 1]) * q[j][i - 1]
			    - (xa - x_points[j]) * q[j - 1][i - 1]
			) / (x_points[j] - x_points[j - i + 1])

	return [q[n - 1][n - 1], q]


if __name__ == "__main__":
		import doctest

		doctest.testmod()