




from __future__ import annotations

import unittest

from transformers import RoFormerConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
     import tensorflow as tf

     from transformers import (
         TFRoFormerForCausalLM,
         TFRoFormerForMaskedLM,
         TFRoFormerForMultipleChoice,
         TFRoFormerForQuestionAnswering,
         TFRoFormerForSequenceClassification,
         TFRoFormerForTokenClassification,
         TFRoFormerModel,
     )
     from transformers.models.roformer.modeling_tf_roformer import (
         TFRoFormerSelfAttention,
         TFRoFormerSinusoidalPositionalEmbedding,
     )

class   __a:






    """simple docstring"""





    def __init__(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE=13       ,_SCREAMING_SNAKE_CASE=7       ,_SCREAMING_SNAKE_CASE=True       ,_SCREAMING_SNAKE_CASE=True       ,_SCREAMING_SNAKE_CASE=True       ,_SCREAMING_SNAKE_CASE=True       ,_SCREAMING_SNAKE_CASE=99       ,_SCREAMING_SNAKE_CASE=32       ,_SCREAMING_SNAKE_CASE=2       ,_SCREAMING_SNAKE_CASE=4       ,_SCREAMING_SNAKE_CASE=37       ,_SCREAMING_SNAKE_CASE="gelu"       ,_SCREAMING_SNAKE_CASE=0.1       ,_SCREAMING_SNAKE_CASE=0.1       ,_SCREAMING_SNAKE_CASE=512       ,_SCREAMING_SNAKE_CASE=16       ,_SCREAMING_SNAKE_CASE=2       ,_SCREAMING_SNAKE_CASE=0.02       ,_SCREAMING_SNAKE_CASE=3       ,_SCREAMING_SNAKE_CASE=4       ,_SCREAMING_SNAKE_CASE=None       ,)			->		List[str]:
         UpperCAmelCase_      :							int       =      parent
         UpperCAmelCase_      :							Union[str, Any]       =      13
         UpperCAmelCase_      :							List[str]       =      7
         UpperCAmelCase_      :							List[Any]       =      True
         UpperCAmelCase_      :							Optional[int]       =      True
         UpperCAmelCase_      :							Union[str, Any]       =      True
         UpperCAmelCase_      :							Union[str, Any]       =      True
         UpperCAmelCase_      :							Optional[Any]       =      99
         UpperCAmelCase_      :							List[str]       =      32
         UpperCAmelCase_      :							List[str]       =      2
         UpperCAmelCase_      :							List[Any]       =      4
         UpperCAmelCase_      :							Tuple       =      37
         UpperCAmelCase_      :							Tuple       =      '''gelu'''
         UpperCAmelCase_      :							Optional[int]       =      0.1
         UpperCAmelCase_      :							List[Any]       =      0.1
         UpperCAmelCase_      :							Union[str, Any]       =      512
         UpperCAmelCase_      :							Tuple       =      16
         UpperCAmelCase_      :							Optional[int]       =      2
         UpperCAmelCase_      :							Any       =      0.02
         UpperCAmelCase_      :							str       =      3
         UpperCAmelCase_      :							Optional[int]       =      4
         UpperCAmelCase_      :							List[str]       =      None





    def 							a__				(				self  )			->		List[Any]:
         UpperCAmelCase_      :							Optional[Any]       =      ids_tensor([self.batch_size, self.seq_length]       ,self.vocab_size  )

         UpperCAmelCase_      :							int       =      None
         if self.use_input_mask:
              UpperCAmelCase_      :							Tuple       =      random_attention_mask([self.batch_size, self.seq_length]  )

         UpperCAmelCase_      :							List[str]       =      None
         if self.use_token_type_ids:
              UpperCAmelCase_      :							Tuple       =      ids_tensor([self.batch_size, self.seq_length]       ,self.type_vocab_size  )

         UpperCAmelCase_      :							Tuple       =      None
         UpperCAmelCase_      :							List[Any]       =      None
         UpperCAmelCase_      :							Optional[int]       =      None
         if self.use_labels:
              UpperCAmelCase_      :							Tuple       =      ids_tensor([self.batch_size]       ,self.type_sequence_label_size  )
              UpperCAmelCase_      :							str       =      ids_tensor([self.batch_size, self.seq_length]       ,self.num_labels  )
              UpperCAmelCase_      :							int       =      ids_tensor([self.batch_size]       ,self.num_choices  )

         UpperCAmelCase_      :							Optional[Any]       =      RoFormerConfig(
             vocab_size=self.vocab_size       ,hidden_size=self.hidden_size       ,num_hidden_layers=self.num_hidden_layers       ,num_attention_heads=self.num_attention_heads       ,intermediate_size=self.intermediate_size       ,hidden_act=self.hidden_act       ,hidden_dropout_prob=self.hidden_dropout_prob       ,attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,max_position_embeddings=self.max_position_embeddings       ,type_vocab_size=self.type_vocab_size       ,initializer_range=self.initializer_range       ,return_dict=_SCREAMING_SNAKE_CASE       ,)

         return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		Optional[Any]:
         UpperCAmelCase_      :							List[str]       =      TFRoFormerModel(config=_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							str       =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

         UpperCAmelCase_      :							List[str]       =      [input_ids, input_mask]
         UpperCAmelCase_      :							Tuple       =      model(_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							Tuple       =      model(_SCREAMING_SNAKE_CASE  )

         self.parent.assertEqual(result.last_hidden_state.shape       ,(self.batch_size, self.seq_length, self.hidden_size)  )





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		Any:
         UpperCAmelCase_      :							List[str]       =      True
         UpperCAmelCase_      :							int       =      TFRoFormerForCausalLM(config=_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							Optional[int]       =      {
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }
         UpperCAmelCase_      :							Any       =      model(_SCREAMING_SNAKE_CASE  )['''logits''']
         self.parent.assertListEqual(
             list(prediction_scores.numpy().shape  )       ,[self.batch_size, self.seq_length, self.vocab_size]  )





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		Tuple:
         UpperCAmelCase_      :							Optional[int]       =      TFRoFormerForMaskedLM(config=_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							int       =      {
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }
         UpperCAmelCase_      :							Union[str, Any]       =      model(_SCREAMING_SNAKE_CASE  )
         self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.seq_length, self.vocab_size)  )





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		List[Any]:
         UpperCAmelCase_      :							List[Any]       =      self.num_labels
         UpperCAmelCase_      :							Dict       =      TFRoFormerForSequenceClassification(config=_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							List[str]       =      {
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }

         UpperCAmelCase_      :							Dict       =      model(_SCREAMING_SNAKE_CASE  )
         self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.num_labels)  )





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		List[Any]:
         UpperCAmelCase_      :							str       =      self.num_choices
         UpperCAmelCase_      :							Optional[int]       =      TFRoFormerForMultipleChoice(config=_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							int       =      tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE       ,1  )       ,(1, self.num_choices, 1)  )
         UpperCAmelCase_      :							List[str]       =      tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE       ,1  )       ,(1, self.num_choices, 1)  )
         UpperCAmelCase_      :							List[str]       =      tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE       ,1  )       ,(1, self.num_choices, 1)  )
         UpperCAmelCase_      :							Union[str, Any]       =      {
             '''input_ids''': multiple_choice_inputs_ids,
             '''attention_mask''': multiple_choice_input_mask,
             '''token_type_ids''': multiple_choice_token_type_ids,
         }
         UpperCAmelCase_      :							Dict       =      model(_SCREAMING_SNAKE_CASE  )
         self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.num_choices)  )





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		List[str]:
         UpperCAmelCase_      :							Dict       =      self.num_labels
         UpperCAmelCase_      :							int       =      TFRoFormerForTokenClassification(config=_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							int       =      {
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }
         UpperCAmelCase_      :							Dict       =      model(_SCREAMING_SNAKE_CASE  )
         self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.seq_length, self.num_labels)  )





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		Optional[Any]:
         UpperCAmelCase_      :							int       =      TFRoFormerForQuestionAnswering(config=_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							Any       =      {
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }

         UpperCAmelCase_      :							Optional[int]       =      model(_SCREAMING_SNAKE_CASE  )
         self.parent.assertEqual(result.start_logits.shape       ,(self.batch_size, self.seq_length)  )
         self.parent.assertEqual(result.end_logits.shape       ,(self.batch_size, self.seq_length)  )





    def 							a__				(				self  )			->		Dict:
         UpperCAmelCase_      :							Union[str, Any]       =      self.prepare_config_and_inputs()
         (
             (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   
         )      :							str       =      config_and_inputs
         UpperCAmelCase_      :							int       =      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
         return config, inputs_dict


@require_tf
class   __a(					_a    ,						_a    ,						unittest.TestCase       ):






    """simple docstring"""





    lowerCAmelCase        =				(
        (
            TFRoFormerModel,
            TFRoFormerForCausalLM,
            TFRoFormerForMaskedLM,
            TFRoFormerForQuestionAnswering,
            TFRoFormerForSequenceClassification,
            TFRoFormerForTokenClassification,
            TFRoFormerForMultipleChoice,
        )
        if is_tf_available()
        else ()
    )
    lowerCAmelCase        =				(
        {
            '''feature-extraction''': TFRoFormerModel,
            '''fill-mask''': TFRoFormerForMaskedLM,
            '''question-answering''': TFRoFormerForQuestionAnswering,
            '''text-classification''': TFRoFormerForSequenceClassification,
            '''text-generation''': TFRoFormerForCausalLM,
            '''token-classification''': TFRoFormerForTokenClassification,
            '''zero-shot''': TFRoFormerForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )

    lowerCAmelCase        =				False
    lowerCAmelCase        =				False





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		Any:
         if pipeline_test_casse_name == "TextGenerationPipelineTests":
              return True

         return False





    def 							a__				(				self  )			->		Tuple:
         UpperCAmelCase_      :							List[Any]       =      TFRoFormerModelTester(self  )
         UpperCAmelCase_      :							List[str]       =      ConfigTester(self       ,config_class=_SCREAMING_SNAKE_CASE       ,hidden_size=37  )





    def 							a__				(				self  )			->		Union[str, Any]:
         self.config_tester.run_common_tests()





    def 							a__				(				self  )			->		Dict:
         UpperCAmelCase_      :							int       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		Dict:
         UpperCAmelCase_      :							List[Any]       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		int:
         UpperCAmelCase_      :							List[Any]       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_lm_head(*_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		int:
         UpperCAmelCase_      :							Any       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		str:
         UpperCAmelCase_      :							List[str]       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		Optional[int]:
         UpperCAmelCase_      :							str       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		Optional[int]:
         UpperCAmelCase_      :							Union[str, Any]       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*_SCREAMING_SNAKE_CASE  )





    @slow
    def 							a__				(				self  )			->		Optional[Any]:
         UpperCAmelCase_      :							List[str]       =      TFRoFormerModel.from_pretrained('''junnyu/roformer_chinese_base'''  )
         self.assertIsNotNone(_SCREAMING_SNAKE_CASE  )


@require_tf
class   __a(					unittest.TestCase       ):






    """simple docstring"""





    @slow
    def 							a__				(				self  )			->		int:
         UpperCAmelCase_      :							Union[str, Any]       =      TFRoFormerForMaskedLM.from_pretrained('''junnyu/roformer_chinese_base'''  )
         UpperCAmelCase_      :							List[Any]       =      tf.constant([[0, 1, 2, 3, 4, 5]]  )
         UpperCAmelCase_      :							List[Any]       =      model(_SCREAMING_SNAKE_CASE  )[0]

         # TODO Replace vocab size
         UpperCAmelCase_      :							str       =      50_000

         UpperCAmelCase_      :							Optional[int]       =      [1, 6, vocab_size]
         self.assertEqual(output.shape       ,_SCREAMING_SNAKE_CASE  )

         print(output[:, :3, :3]  )

         # TODO Replace values below with what was printed above.
         UpperCAmelCase_      :							List[Any]       =      tf.constant(
             [
                 [
                     [-0.12_05_33_41, -1.0_26_49_01, 0.29_22_19_46],
                     [-1.5_13_37_83, 0.19_74_33, 0.15_19_06_07],
                     [-5.0_13_54_03, -3.90_02_56, -0.84_03_87_64],
                 ]
             ]  )
         tf.debugging.assert_near(output[:, :3, :3]       ,_SCREAMING_SNAKE_CASE       ,atol=1e-4  )


@require_tf
class   __a(					unittest.TestCase       ):






    """simple docstring"""





    lowerCAmelCase        =				1E-4





    def 							a__				(				self  )			->		int:
         UpperCAmelCase_      :							Union[str, Any]       =      tf.constant([[4, 10]]  )
         UpperCAmelCase_      :							Any       =      TFRoFormerSinusoidalPositionalEmbedding(num_positions=6       ,embedding_dim=6  )

         UpperCAmelCase_      :							Dict       =      emba(input_ids.shape  )
         UpperCAmelCase_      :							Any       =      tf.constant(
             [[0.00_00, 0.00_00, 0.00_00, 1.00_00, 1.00_00, 1.00_00], [0.84_15, 0.04_64, 0.00_22, 0.54_03, 0.99_89, 1.00_00]]  )

         tf.debugging.assert_near(_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,atol=self.tolerance  )





    def 							a__				(				self  )			->		Tuple:
         UpperCAmelCase_      :							Union[str, Any]       =      tf.constant(
             [
                 [0.00_00, 0.00_00, 0.00_00, 0.00_00, 0.00_00],
                 [0.84_15, 0.82_19, 0.80_20, 0.78_19, 0.76_17],
                 [0.90_93, 0.93_64, 0.95_81, 0.97_49, 0.98_70],
             ]  )
         UpperCAmelCase_      :							Optional[Any]       =      TFRoFormerSinusoidalPositionalEmbedding(num_positions=512       ,embedding_dim=512  )
         emba([2, 16, 512]  )
         UpperCAmelCase_      :							Union[str, Any]       =      emba.weight[:3, :5]

         tf.debugging.assert_near(_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,atol=self.tolerance  )


@require_tf
class   __a(					unittest.TestCase       ):






    """simple docstring"""





    lowerCAmelCase        =				1E-4





    def 							a__				(				self  )			->		List[str]:
         # 2,12,16,64
         UpperCAmelCase_      :							List[Any]       =      tf.reshape(tf.range(2 * 12 * 16 * 64       ,dtype=tf.floataa  )       ,shape=(2, 12, 16, 64)  ) / 100

         UpperCAmelCase_      :							str       =      -tf.reshape(tf.range(2 * 12 * 16 * 64       ,dtype=tf.floataa  )       ,shape=(2, 12, 16, 64)  ) / 100

         UpperCAmelCase_      :							Optional[Any]       =      TFRoFormerSinusoidalPositionalEmbedding(num_positions=32       ,embedding_dim=64  )
         UpperCAmelCase_      :							Union[str, Any]       =      embed_positions([2, 16, 768]  )[None, None, :, :]

         UpperCAmelCase_,   UpperCAmelCase_      :							Tuple       =      TFRoFormerSelfAttention.apply_rotary_position_embeddings(
             _SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							str       =      tf.constant(
             [
                 [0.00_00, 0.01_00, 0.02_00, 0.03_00, 0.04_00, 0.05_00, 0.06_00, 0.07_00],
                 [-0.20_12, 0.88_97, 0.02_63, 0.94_01, 0.20_74, 0.94_63, 0.34_81, 0.93_43],
                 [-1.70_57, 0.62_71, -1.21_45, 1.38_97, -0.63_03, 1.76_47, -0.11_73, 1.89_85],
                 [-2.17_31, -1.63_97, -2.73_58, 0.28_54, -2.18_40, 1.71_83, -1.30_18, 2.48_71],
                 [0.27_17, -3.61_73, -2.92_06, -2.19_88, -3.66_38, 0.38_58, -2.91_55, 2.29_80],
                 [3.98_59, -2.15_80, -0.79_84, -4.49_04, -4.11_81, -2.02_52, -4.47_82, 1.12_53],
             ]  )
         UpperCAmelCase_      :							Union[str, Any]       =      tf.constant(
             [
                 [0.00_00, -0.01_00, -0.02_00, -0.03_00, -0.04_00, -0.05_00, -0.06_00, -0.07_00],
                 [0.20_12, -0.88_97, -0.02_63, -0.94_01, -0.20_74, -0.94_63, -0.34_81, -0.93_43],
                 [1.70_57, -0.62_71, 1.21_45, -1.38_97, 0.63_03, -1.76_47, 0.11_73, -1.89_85],
                 [2.17_31, 1.63_97, 2.73_58, -0.28_54, 2.18_40, -1.71_83, 1.30_18, -2.48_71],
                 [-0.27_17, 3.61_73, 2.92_06, 2.19_88, 3.66_38, -0.38_58, 2.91_55, -2.29_80],
                 [-3.98_59, 2.15_80, 0.79_84, 4.49_04, 4.11_81, 2.02_52, 4.47_82, -1.12_53],
             ]  )

         tf.debugging.assert_near(query_layer[0, 0, :6, :8]       ,_SCREAMING_SNAKE_CASE       ,atol=self.tolerance  )
         tf.debugging.assert_near(key_layer[0, 0, :6, :8]       ,_SCREAMING_SNAKE_CASE       ,atol=self.tolerance  )





def lowerCamelCase__       (      _lowercase			,						_lowercase				):

     '''simple docstring'''


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







def lowerCamelCase__       (      _lowercase			,						_lowercase=0				):

     '''simple docstring'''


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







def lowerCamelCase__       (      _lowercase			,						_lowercase			,						_lowercase=float('''inf'''				)				):

     '''simple docstring'''


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







def lowerCamelCase__       (      _lowercase			,						_lowercase			,						_lowercase=float('''inf'''				)				):

     '''simple docstring'''


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







def lowerCamelCase__       (      _lowercase			,						_lowercase			,						_lowercase				):

     '''simple docstring'''


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

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

     UpperCAmelCase_      :							Optional[Any]       =      dis_between_closest_in_strip(
         _lowercase			,						len(_lowercase				)			,						_lowercase				)
     return min(_lowercase			,						_lowercase				)







def lowerCamelCase__       (      _lowercase			,						_lowercase				):

     '''simple docstring'''


     UpperCAmelCase_      :							Tuple       =      column_based_sort(_lowercase			,						column=0				)
     UpperCAmelCase_      :							List[Any]       =      column_based_sort(_lowercase			,						column=1				)
     return (
         closest_pair_of_points_sqr(
             _lowercase			,						_lowercase			,						_lowercase				)
     ) ** 0.5


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