






import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig
from ..clip.configuration_clip import CLIPVisionConfig


_a       =    logging.get_logger(__name__)





class __lowerCamelCase					( snake_case__):





	"""simple docstring"""






	UpperCamelCase__								= "vision-text-dual-encoder"
	UpperCamelCase__								= True

	def __init__(				self			,       UpperCAmelCase=512			,       UpperCAmelCase=2.65_92			,       **UpperCAmelCase       ):
							"""simple docstring"""







							super().__init__(**UpperCAmelCase       )

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

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

							_UpperCAmelCase							   =     kwargs.pop('vision_config'       )
							_UpperCAmelCase							   =     kwargs.pop('text_config'       )

							_UpperCAmelCase							   =     vision_config.pop('model_type'       )
							_UpperCAmelCase							   =     text_config.pop('model_type'       )

							if vision_model_type == "clip":
													_UpperCAmelCase							   =     AutoConfig.for_model(UpperCAmelCase			,       **UpperCAmelCase       ).vision_config
							elif vision_model_type == "clip_vision_model":
													_UpperCAmelCase							   =     CLIPVisionConfig(**UpperCAmelCase       )
							else:
													_UpperCAmelCase							   =     AutoConfig.for_model(UpperCAmelCase			,       **UpperCAmelCase       )

							_UpperCAmelCase							   =     AutoConfig.for_model(UpperCAmelCase			,       **UpperCAmelCase       )

							_UpperCAmelCase							   =     projection_dim
							_UpperCAmelCase							   =     logit_scale_init_value

	@classmethod
	def 			UpperCamelCase       (				cls			,       UpperCAmelCase			,       UpperCAmelCase			,       **UpperCAmelCase       ):
							"""simple docstring"""







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

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							_UpperCAmelCase							   =     copy.deepcopy(self.__dict__       )
							_UpperCAmelCase							   =     self.vision_config.to_dict()
							_UpperCAmelCase							   =     self.text_config.to_dict()
							_UpperCAmelCase							   =     self.__class__.model_type
							return output




from __future__ import annotations
def 							UpperCAmelCase_   (				__snake_case		)	->     list[int]:







 """simple docstring"""


 if not list_of_ints:
  return []

 if min(__snake_case		) < 0:
  raise ValueError('''All numbers must be positive'''		)

 _lowercase				 =max(len(bin(__snake_case		)[2:]		) for x in list_of_ints		)
 return _msd_radix_sort(__snake_case	,		__snake_case		)
def 							UpperCAmelCase_   (				__snake_case	,		__snake_case		)	->     list[int]:







 """simple docstring"""


 if bit_position == 0 or len(__snake_case		) in [0, 1]:
  return list_of_ints

 _lowercase				 =[]
 _lowercase				 =[]
 # Split numbers based on bit at bit_position from the right
 for number in list_of_ints:
  if (number >> (bit_position - 1)) & 1:
   # number has a one at bit bit_position
   ones.append(__snake_case		)
  else:
   # number has a zero at bit bit_position
   zeros.append(__snake_case		)

    # recursively split both lists further
 _lowercase				 =_msd_radix_sort(__snake_case	,		bit_position - 1		)
 _lowercase				 =_msd_radix_sort(__snake_case	,		bit_position - 1		)

 # recombine lists
 _lowercase				 =zeros
 res.extend(__snake_case		)

 return res
def 							UpperCAmelCase_   (				__snake_case		)	->     List[str]:







 """simple docstring"""


 _lowercase				 =len(__snake_case		)
 if not list_of_ints or length == 1:
  return

 if min(__snake_case		) < 0:
  raise ValueError('''All numbers must be positive'''		)

 _lowercase				 =max(len(bin(__snake_case		)[2:]		) for x in list_of_ints		)
 _msd_radix_sort_inplace(__snake_case	,		__snake_case	,		0	,		__snake_case		)
def 							UpperCAmelCase_   (				__snake_case	,		__snake_case	,		__snake_case	,		__snake_case		)	->     Any:







 """simple docstring"""


 if bit_position == 0 or end_index - begin_index <= 1:
  return

 bit_position -= 1

 _lowercase				 =begin_index
 _lowercase				 =end_index - 1
 while i <= j:
  _lowercase				 =False
  if not (list_of_ints[i] >> bit_position) & 1:
   # found zero at the beginning
   i += 1
   _lowercase				 =True
  if (list_of_ints[j] >> bit_position) & 1:
   # found one at the end
   j -= 1
   _lowercase				 =True

  if changed:
   continue

  _lowercase ,       _lowercase				 =list_of_ints[j], list_of_ints[i]
  j -= 1
  if j != i:
   i += 1

 _msd_radix_sort_inplace(__snake_case	,		__snake_case	,		__snake_case	,		__snake_case		)
 _msd_radix_sort_inplace(__snake_case	,		__snake_case	,		__snake_case	,		__snake_case		)


if __name__ == "__main__":
  import doctest

  doctest.testmod()

