



"""simple docstring"""







import os
import unittest

from transformers import BatchEncoding
from transformers.models.bert.tokenization_bert import (
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.models.prophetnet.tokenization_prophetnet import VOCAB_FILES_NAMES, ProphetNetTokenizer
from transformers.testing_utils import require_torch, slow

from ...test_tokenization_common import TokenizerTesterMixin







class 				UpperCamelCase__       (     A_, unittest.TestCase  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE      =					ProphetNetTokenizer
      _SCREAMING_SNAKE_CASE      =					False



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Any	):
        super().setUp()

        lowerCAmelCase_       :    Dict								=			[
            "[UNK]",
            "[CLS]",
            "[SEP]",
            "[PAD]",
            "[MASK]",
            "want",
            "##want",
            "##ed",
            "wa",
            "un",
            "runn",
            "##ing",
            ",",
            "low",
            "lowest",
        ]
        lowerCAmelCase_       :    Optional[int]								=			os.path.join(self.tmpdirname   ,      VOCAB_FILES_NAMES['vocab_file']	)
        with open(self.vocab_file   ,      'w'   ,      encoding='utf-8'	) as vocab_writer:
          vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]	)	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Tuple   ,      SCREAMING_SNAKE_CASE_    :				str	):
        lowerCAmelCase_       :    int								=			"UNwant\u00E9d,running"
        lowerCAmelCase_       :    Dict								=			"unwanted, running"
        return input_text, output_text



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Union[str, Any]	):
        lowerCAmelCase_       :    Optional[int]								=			self.tokenizer_class(self.vocab_file	)

        lowerCAmelCase_       :    int								=			tokenizer.tokenize('UNwant\u00E9d,running'	)
        self.assertListEqual(snake_case__   ,      ['un', '##want', '##ed', ',', 'runn', '##ing']	)
        self.assertListEqual(tokenizer.convert_tokens_to_ids(snake_case__	)   ,      [9, 6, 7, 1_2, 1_0, 1_1]	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Tuple	):
        lowerCAmelCase_       :    str								=			BasicTokenizer()

        self.assertListEqual(tokenizer.tokenize('ah\u535A\u63A8zz'	)   ,      ['ah', '\u535A', '\u63A8', 'zz']	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Any	):
        lowerCAmelCase_       :    Optional[Any]								=			BasicTokenizer(do_lower_case=snake_case__	)

        self.assertListEqual(
            tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '	)   ,      ['hello', '!', 'how', 'are', 'you', '?']	)
        self.assertListEqual(tokenizer.tokenize('H\u00E9llo'	)   ,      ['hello']	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Tuple	):
        lowerCAmelCase_       :    Any								=			BasicTokenizer(do_lower_case=snake_case__   ,      strip_accents=snake_case__	)

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '	)   ,      ['hällo', '!', 'how', 'are', 'you', '?']	)
        self.assertListEqual(tokenizer.tokenize('H\u00E9llo'	)   ,      ['h\u00E9llo']	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Tuple	):
        lowerCAmelCase_       :    Tuple								=			BasicTokenizer(do_lower_case=snake_case__   ,      strip_accents=snake_case__	)

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '	)   ,      ['hallo', '!', 'how', 'are', 'you', '?']	)
        self.assertListEqual(tokenizer.tokenize('H\u00E9llo'	)   ,      ['hello']	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Optional[Any]	):
        lowerCAmelCase_       :    Any								=			BasicTokenizer(do_lower_case=snake_case__	)

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '	)   ,      ['hallo', '!', 'how', 'are', 'you', '?']	)
        self.assertListEqual(tokenizer.tokenize('H\u00E9llo'	)   ,      ['hello']	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[Any]	):
        lowerCAmelCase_       :    Tuple								=			BasicTokenizer(do_lower_case=snake_case__	)

        self.assertListEqual(
            tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '	)   ,      ['HeLLo', '!', 'how', 'Are', 'yoU', '?']	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Any	):
        lowerCAmelCase_       :    List[Any]								=			BasicTokenizer(do_lower_case=snake_case__   ,      strip_accents=snake_case__	)

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '	)   ,      ['HäLLo', '!', 'how', 'Are', 'yoU', '?']	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Optional[int]	):
        lowerCAmelCase_       :    Any								=			BasicTokenizer(do_lower_case=snake_case__   ,      strip_accents=snake_case__	)

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '	)   ,      ['HaLLo', '!', 'how', 'Are', 'yoU', '?']	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Optional[int]	):
        lowerCAmelCase_       :    Tuple								=			BasicTokenizer(do_lower_case=snake_case__   ,      never_split=['[UNK]']	)

        self.assertListEqual(
            tokenizer.tokenize(' \tHeLLo!how  \n Are yoU? [UNK]'	)   ,      ['HeLLo', '!', 'how', 'Are', 'yoU', '?', '[UNK]']	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Optional[Any]	):
        lowerCAmelCase_       :    Tuple								=			["[UNK]", "[CLS]", "[SEP]", "want", "##want", "##ed", "wa", "un", "runn", "##ing"]

        lowerCAmelCase_       :    List[str]								=			{}
        for i, token in enumerate(snake_case__	):
          lowerCAmelCase_       :    Optional[int]								=			i
        lowerCAmelCase_       :    Tuple								=			WordpieceTokenizer(vocab=snake_case__   ,      unk_token='[UNK]'	)

        self.assertListEqual(tokenizer.tokenize(''	)   ,      []	)

        self.assertListEqual(tokenizer.tokenize('unwanted running'	)   ,      ['un', '##want', '##ed', 'runn', '##ing']	)

        self.assertListEqual(tokenizer.tokenize('unwantedX running'	)   ,      ['[UNK]', 'runn', '##ing']	)



      @require_torch
      def 					SCREAMING_SNAKE_CASE__			(				self    :				int	):
        lowerCAmelCase_       :    Union[str, Any]								=			self.tokenizer_class.from_pretrained('microsoft/prophetnet-large-uncased'	)

        lowerCAmelCase_       :    Optional[Any]								=			["A long paragraph for summarization.", "Another paragraph for summarization."]
        lowerCAmelCase_       :    Union[str, Any]								=			[1_0_3_7, 2_1_4_6, 2_0_4_2_3, 2_0_0_5, 7_6_8_0, 7_8_4_9, 3_9_8_9, 1_0_1_2, 1_0_2]
        lowerCAmelCase_       :    Optional[Any]								=			tokenizer(snake_case__   ,      padding=snake_case__   ,      return_tensors='pt'	)
        self.assertIsInstance(snake_case__   ,      snake_case__	)
        lowerCAmelCase_       :    Any								=			list(batch.input_ids.numpy()[0]	)
        self.assertListEqual(snake_case__   ,      snake_case__	)

        self.assertEqual((2, 9)   ,      batch.input_ids.shape	)
        self.assertEqual((2, 9)   ,      batch.attention_mask.shape	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Tuple	):
        self.assertTrue(_is_whitespace(' '	)	)
        self.assertTrue(_is_whitespace('\t'	)	)
        self.assertTrue(_is_whitespace('\r'	)	)
        self.assertTrue(_is_whitespace('\n'	)	)
        self.assertTrue(_is_whitespace('\u00A0'	)	)

        self.assertFalse(_is_whitespace('A'	)	)
        self.assertFalse(_is_whitespace('-'	)	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Union[str, Any]	):
        self.assertTrue(_is_control('\u0005'	)	)

        self.assertFalse(_is_control('A'	)	)
        self.assertFalse(_is_control(' '	)	)
        self.assertFalse(_is_control('\t'	)	)
        self.assertFalse(_is_control('\r'	)	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[Any]	):
        self.assertTrue(_is_punctuation('-'	)	)
        self.assertTrue(_is_punctuation('$'	)	)
        self.assertTrue(_is_punctuation('`'	)	)
        self.assertTrue(_is_punctuation('.'	)	)

        self.assertFalse(_is_punctuation('A'	)	)
        self.assertFalse(_is_punctuation(' '	)	)





      @slow
      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[Any]	):
        lowerCAmelCase_       :    Tuple								=			self.tokenizer_class.from_pretrained('microsoft/prophetnet-large-uncased'	)

        lowerCAmelCase_       :    Tuple								=			tokenizer.encode('sequence builders'   ,      add_special_tokens=snake_case__	)
        lowerCAmelCase_       :    List[Any]								=			tokenizer.encode('multi-sequence build'   ,      add_special_tokens=snake_case__	)

        lowerCAmelCase_       :    int								=			tokenizer.build_inputs_with_special_tokens(snake_case__	)
        lowerCAmelCase_       :    Optional[Any]								=			tokenizer.build_inputs_with_special_tokens(snake_case__   ,      snake_case__	)

        assert encoded_sentence == text + [1_0_2]
        assert encoded_pair == text + [1_0_2] + text_a + [1_0_2]





"""simple docstring"""







def     UpperCamelCase_   (   lowerCAmelCase__				:    Optional[Any]   ,       lowerCAmelCase__				:    str						)						->       List[Any]:

  """simple docstring"""




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

def     UpperCamelCase_   (   lowerCAmelCase__				:    List[Any]   ,       lowerCAmelCase__				:    str=0						)						->       Union[str, Any]:

  """simple docstring"""




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

def     UpperCamelCase_   (   lowerCAmelCase__				:    Dict   ,       lowerCAmelCase__				:    Optional[int]   ,       lowerCAmelCase__				:    Optional[Any]=float('inf'						)						)						->       Optional[int]:

  """simple docstring"""




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

def     UpperCamelCase_   (   lowerCAmelCase__				:    List[Any]   ,       lowerCAmelCase__				:    Dict   ,       lowerCAmelCase__				:    Union[str, Any]=float('inf'						)						)						->       Dict:

  """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_       :    Union[str, Any]								=			current_dis
  return min_dis

def     UpperCamelCase_   (   lowerCAmelCase__				:    Dict   ,       lowerCAmelCase__				:    int   ,       lowerCAmelCase__				:    Optional[int]						)						->       Dict:

  """simple docstring"""




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

  # recursion
  lowerCAmelCase_       :    int								=			points_counts // 2
  lowerCAmelCase_       :    Optional[Any]								=			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_       :    Any								=			min(lowerCAmelCase__   ,       lowerCAmelCase__						)
  lowerCAmelCase_       :    str								=			[]
  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_       :    List[Any]								=			dis_between_closest_in_strip(
      lowerCAmelCase__   ,       len(lowerCAmelCase__						)   ,       lowerCAmelCase__						)
  return min(lowerCAmelCase__   ,       lowerCAmelCase__						)

def     UpperCamelCase_   (   lowerCAmelCase__				:    str   ,       lowerCAmelCase__				:    Tuple						)						->       List[Any]:

  """simple docstring"""




  lowerCAmelCase_       :    List[str]								=			column_based_sort(lowerCAmelCase__   ,       column=0						)
  lowerCAmelCase_       :    Dict								=			column_based_sort(lowerCAmelCase__   ,       column=1						)
  return (
      closest_pair_of_points_sqr(
          lowerCAmelCase__   ,       lowerCAmelCase__   ,       lowerCAmelCase__						)
  ) ** 0.5


if __name__ == "__main__":
     lowercase__		:    List[str]				   =     [(2, 3), (1_2, 3_0), (4_0, 5_0), (5, 1), (1_2, 1_0), (3, 4)]
     print("""Distance:""", closest_pair_of_points(points, len(points)))





