
'''simple docstring'''






def 		A_							(						_lowerCAmelCase :     List[Any]					,						_lowerCAmelCase :     Any				):



      """simple docstring"""




      return (pointa[0] - pointa[0]) ** 2 + (pointa[1] - pointa[1]) ** 2







def 		A_							(						_lowerCAmelCase :     Any					,						_lowerCAmelCase :     str=0				):



      """simple docstring"""




      return sorted(_lowerCAmelCase					,						key=lambda _lowerCAmelCase				: x[column]				)







def 		A_							(						_lowerCAmelCase :     Optional[int]					,						_lowerCAmelCase :     Optional[int]					,						_lowerCAmelCase :     Tuple=float("inf"				)				):



      """simple docstring"""




      for i in range(points_counts - 1				):
            for j in range(i + 1					,						_lowerCAmelCase				):
                  _lowerCamelCase					: Optional[Any]		    = euclidean_distance_sqr(points[i]					,						points[j]				)
                  if current_dis < min_dis:
                        _lowerCamelCase					: Optional[int]		    = current_dis
      return min_dis







def 		A_							(						_lowerCAmelCase :     List[str]					,						_lowerCAmelCase :     Any					,						_lowerCAmelCase :     str=float("inf"				)				):



      """simple docstring"""




      for i in range(min(6					,						points_counts - 1				)					,						_lowerCAmelCase				):
            for j in range(max(0					,						i - 6				)					,						_lowerCAmelCase				):
                  _lowerCamelCase					: Any		    = euclidean_distance_sqr(points[i]					,						points[j]				)
                  if current_dis < min_dis:
                        _lowerCamelCase					: Optional[int]		    = current_dis
      return min_dis







def 		A_							(						_lowerCAmelCase :     Tuple					,						_lowerCAmelCase :     Tuple					,						_lowerCAmelCase :     str				):



      """simple docstring"""




      if points_counts <= 3:
            return dis_between_closest_pair(_lowerCAmelCase					,						_lowerCAmelCase				)

      # recursion
      _lowerCamelCase					: int		    = points_counts // 2
      _lowerCamelCase					: Dict		    = closest_pair_of_points_sqr(
          _lowerCAmelCase					,						points_sorted_on_y[:mid]					,						_lowerCAmelCase				)
      _lowerCamelCase					: Optional[Any]		    = closest_pair_of_points_sqr(
          _lowerCAmelCase					,						points_sorted_on_y[mid:]					,						points_counts - mid				)
      _lowerCamelCase					: Tuple		    = min(_lowerCAmelCase					,						_lowerCAmelCase				)
      _lowerCamelCase					: Optional[Any]		    = []
      for point in points_sorted_on_x:
            if abs(point[0] - points_sorted_on_x[mid][0]				) < closest_pair_dis:
                  cross_strip.append(_lowerCAmelCase				)

      _lowerCamelCase					: Union[str, Any]		    = dis_between_closest_in_strip(
          _lowerCAmelCase					,						len(_lowerCAmelCase				)					,						_lowerCAmelCase				)
      return min(_lowerCAmelCase					,						_lowerCAmelCase				)







def 		A_							(						_lowerCAmelCase :     Tuple					,						_lowerCAmelCase :     List[str]				):



      """simple docstring"""




      _lowerCamelCase					: Tuple		    = column_based_sort(_lowerCAmelCase					,						column=0				)
      _lowerCamelCase					: int		    = column_based_sort(_lowerCAmelCase					,						column=1				)
      return (
          closest_pair_of_points_sqr(
              _lowerCAmelCase					,						_lowerCAmelCase					,						_lowerCAmelCase				)
      ) ** 0.5


if __name__ == "__main__":
 UpperCAmelCase_							: Tuple =							[(2, 3), (12, 30), (40, 50), (5, 1), (12, 10), (3, 4)]
 print('Distance:', closest_pair_of_points(points, len(points)))


'''simple docstring'''





import re

import jax.numpy as jnp
from flax.traverse_util import flatten_dict, unflatten_dict
from jax.random import PRNGKey

from ..utils import logging


UpperCamelCase_    						=       logging.get_logger(__name__)






def 				_lowerCAmelCase			(   __magic_name__						:     List[str]						)				->  Dict:
						lowercase :							List[str]    		=R'''\w+[.]\d+'''
						lowercase :							List[str]    		=re.findall(__magic_name__   , __magic_name__						)
						for pat in pats:
												lowercase :							Optional[int]    		=key.replace(__magic_name__   , '''_'''.join(pat.split('''.'''						)						)						)
						return key






def 				_lowerCAmelCase			(   __magic_name__						:     List[str]   , __magic_name__						:     Union[str, Any]   , __magic_name__						:     Dict						)				->  str:
						lowercase :							Dict    		=pt_tuple_key[:-1] + ('''scale''',)
						if (
						    any('''norm''' in str_ for str_ in pt_tuple_key						)
						    and (pt_tuple_key[-1] == "bias")
						    and (pt_tuple_key[:-1] + ("bias",) not in random_flax_state_dict)
						    and (pt_tuple_key[:-1] + ("scale",) in random_flax_state_dict)
						):
												lowercase :							str    		=pt_tuple_key[:-1] + ('''scale''',)
												return renamed_pt_tuple_key, pt_tensor
						elif pt_tuple_key[-1] in ["weight", "gamma"] and pt_tuple_key[:-1] + ("scale",) in random_flax_state_dict:
												lowercase :							str    		=pt_tuple_key[:-1] + ('''scale''',)
												return renamed_pt_tuple_key, pt_tensor

						# embedding
						if pt_tuple_key[-1] == "weight" and pt_tuple_key[:-1] + ("embedding",) in random_flax_state_dict:
												lowercase :							Dict    		=pt_tuple_key[:-1] + ('''embedding''',)
												return renamed_pt_tuple_key, pt_tensor

						# conv layer
						lowercase :							Tuple    		=pt_tuple_key[:-1] + ('''kernel''',)
						if pt_tuple_key[-1] == "weight" and pt_tensor.ndim == 4:
												lowercase :							Tuple    		=pt_tensor.transpose(2   , 3   , 1   , 0						)
												return renamed_pt_tuple_key, pt_tensor

						# linear layer
						lowercase :							str    		=pt_tuple_key[:-1] + ('''kernel''',)
						if pt_tuple_key[-1] == "weight":
												lowercase :							Optional[Any]    		=pt_tensor.T
												return renamed_pt_tuple_key, pt_tensor

						# old PyTorch layer norm weight
						lowercase :							Dict    		=pt_tuple_key[:-1] + ('''weight''',)
						if pt_tuple_key[-1] == "gamma":
												return renamed_pt_tuple_key, pt_tensor

						# old PyTorch layer norm bias
						lowercase :							Union[str, Any]    		=pt_tuple_key[:-1] + ('''bias''',)
						if pt_tuple_key[-1] == "beta":
												return renamed_pt_tuple_key, pt_tensor

						return pt_tuple_key, pt_tensor







def 				_lowerCAmelCase			(   __magic_name__						:     int   , __magic_name__						:     Optional[Any]   , __magic_name__						:     Union[str, Any]=42						)				->  List[str]:
						# Step 1: Convert pytorch tensor to numpy
						lowercase :							Optional[Any]    		={k: v.numpy() for k, v in pt_state_dict.items()}

						# Step 2: Since the model is stateless, get random Flax params
						lowercase :							str    		=flax_model.init_weights(PRNGKey(__magic_name__						)						)

						lowercase :							Dict    		=flatten_dict(__magic_name__						)
						lowercase :							Dict    		={}

						# Need to change some parameters name to match Flax names
						for pt_key, pt_tensor in pt_state_dict.items():
												lowercase :							Dict    		=rename_key(__magic_name__						)
												lowercase :							Optional[int]    		=tuple(renamed_pt_key.split('''.'''						)						)

												# Correctly rename weight parameters
												lowercase		,	lowercase :							Any    		=rename_key_and_reshape_tensor(__magic_name__   , __magic_name__   , __magic_name__						)

												if flax_key in random_flax_state_dict:
																		if flax_tensor.shape != random_flax_state_dict[flax_key].shape:
																								raise ValueError(
																								    f'''PyTorch checkpoint seems to be incorrect. Weight {pt_key} was expected to be of shape '''
																								    f'''{random_flax_state_dict[flax_key].shape}, but is {flax_tensor.shape}.'''						)

        # also add unexpected weight so that warning is thrown
												lowercase :							Tuple    		=jnp.asarray(__magic_name__						)

						return unflatten_dict(__magic_name__						)





