


'''simple docstring'''






import json
import os
import unittest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_ftfy, require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin






@require_tokenizers
class  __magic_name__							(		lowerCAmelCase ,unittest.TestCase    ):
       UpperCAmelCase										=CLIPTokenizer
       UpperCAmelCase										=CLIPTokenizerFast
       UpperCAmelCase										=True
       UpperCAmelCase										={}
       UpperCAmelCase										=False






       def       lowerCAmelCase		(      self)						->  Tuple:




          '''simple docstring'''
          super().setUp()

          # fmt: off
          _UpperCAmelCase       :       int							   =['l', 'o', 'w', 'e', 'r', 's', 't', 'i', 'd', 'n', 'lo', 'l</w>', 'w</w>', 'r</w>', 't</w>', 'low</w>', 'er</w>', 'lowest</w>', 'newer</w>', 'wider', '<unk>', '<|startoftext|>', '<|endoftext|>']
          # fmt: on
          _UpperCAmelCase       :       List[str]							   =dict(zip(snake_case  ,							range(len(snake_case))))
          _UpperCAmelCase       :       Optional[int]							   =['#version: 0.2', 'l o', 'lo w</w>', 'e r</w>']
          _UpperCAmelCase       :       Any							   ={'unk_token': '<unk>'}

          _UpperCAmelCase       :       int							   =os.path.join(self.tmpdirname  ,							VOCAB_FILES_NAMES['vocab_file'])
          _UpperCAmelCase       :       Dict							   =os.path.join(self.tmpdirname  ,							VOCAB_FILES_NAMES['merges_file'])
          with open(self.vocab_file  ,							'w'  ,							encoding='utf-8') as fp:
             fp.write(json.dumps(snake_case) + '\n')
          with open(self.merges_file  ,							'w'  ,							encoding='utf-8') as fp:
             fp.write('\n'.join(snake_case))






       def       lowerCAmelCase		(      self  ,							**snake_case)						->  Optional[int]:




          '''simple docstring'''
          kwargs.update(self.special_tokens_map)
          return CLIPTokenizer.from_pretrained(self.tmpdirname  ,							**snake_case)






       def       lowerCAmelCase		(      self  ,							**snake_case)						->  int:




          '''simple docstring'''
          kwargs.update(self.special_tokens_map)
          return CLIPTokenizerFast.from_pretrained(self.tmpdirname  ,							**snake_case)






       def       lowerCAmelCase		(      self  ,							snake_case)						->  Tuple:




          '''simple docstring'''
          _UpperCAmelCase       :       Optional[int]							   ='lower newer'
          _UpperCAmelCase       :       int							   ='lower newer'
          return input_text, output_text






       def       lowerCAmelCase		(      self)						->  str:




          '''simple docstring'''
          _UpperCAmelCase       :       Union[str, Any]							   =CLIPTokenizer(self.vocab_file  ,							self.merges_file  ,							**self.special_tokens_map)
          _UpperCAmelCase       :       Dict							   ='lower newer'
          _UpperCAmelCase       :       Union[str, Any]							   =['lo', 'w', 'er</w>', 'n', 'e', 'w', 'er</w>']
          _UpperCAmelCase       :       str							   =tokenizer.tokenize(snake_case)
          self.assertListEqual(snake_case  ,							snake_case)

          _UpperCAmelCase       :       int							   =tokens + [tokenizer.unk_token]
          _UpperCAmelCase       :       Optional[int]							   =[1_0, 2, 1_6, 9, 3, 2, 1_6, 2_0]
          self.assertListEqual(tokenizer.convert_tokens_to_ids(snake_case)  ,							snake_case)






       @require_ftfy
       def       lowerCAmelCase		(      self)						->  List[Any]:




          '''simple docstring'''
          for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
             with self.subTest(f"{tokenizer.__class__.__name__} ({pretrained_name})"):
                _UpperCAmelCase       :       Tuple							   =self.tokenizer_class.from_pretrained(snake_case  ,							**snake_case)
                _UpperCAmelCase       :       List[str]							   =self.rust_tokenizer_class.from_pretrained(snake_case  ,							**snake_case)

                _UpperCAmelCase       :       Dict							   ='A\n\'ll 11p223RF☆ho!!to?\'d\'d\'\'d of a cat to-$\'\'d.'
                _UpperCAmelCase       :       List[str]							   =tokenizer_s.tokenize(snake_case)
                _UpperCAmelCase       :       Optional[Any]							   =tokenizer_r.tokenize(snake_case)

                self.assertListEqual(snake_case  ,							snake_case)

                # Test that the tokenization is identical on an example containing a character (Latin Small Letter A
                # with Tilde) encoded in 2 different ways
                _UpperCAmelCase       :       Optional[Any]							   ='xa\u0303y' + ' ' + 'x\xe3y'
                _UpperCAmelCase       :       int							   =tokenizer_s.tokenize(snake_case)
                _UpperCAmelCase       :       str							   =tokenizer_r.tokenize(snake_case)

                self.assertListEqual(snake_case  ,							snake_case)

                # Test that the tokenization is identical on unicode of space type
                _UpperCAmelCase       :       Optional[Any]							   =[
                    '\u0009',  # (horizontal tab, '\t')
                    '\u000B',  # (vertical tab)
                    '\u000C',  # (form feed)
                    '\u0020',  # (space, ' ')
                    '\u200E',  # (left-to-right mark):w
                    '\u200F',  # (right-to-left mark)
                ]
                for unicode_seq in spaces_unicodes:
                   _UpperCAmelCase       :       List[str]							   =tokenizer_s.tokenize(snake_case)
                   _UpperCAmelCase       :       Union[str, Any]							   =tokenizer_r.tokenize(snake_case)

                   self.assertListEqual(snake_case  ,							snake_case)

                # Test that the tokenization is identical on unicode of line break type
                _UpperCAmelCase       :       int							   =[
                    '\u000A',  # (line feed, '\n')
                    '\r\n',  # (carriage return and line feed, '\r\n')
                    '\u000D',  # (carriage return, '\r')
                    '\r',  # (carriage return, '\r')
                    '\u000D',  # (carriage return, '\r')
                    '\u2028',  # (line separator)
                    '\u2029',  # (paragraph separator)
                    # "\u0085", # (next line)
                ]

                # The tokenization is not identical for the character "\u0085" (next line). The slow version using ftfy transforms
                # it into the Horizontal Ellipsis character "…" ("\u2026") while the fast version transforms it into a
                # space (and thus into an empty list).

                for unicode_seq in line_break_unicodes:
                   _UpperCAmelCase       :       Union[str, Any]							   =tokenizer_s.tokenize(snake_case)
                   _UpperCAmelCase       :       Tuple							   =tokenizer_r.tokenize(snake_case)

                   self.assertListEqual(snake_case  ,							snake_case)






       def       lowerCAmelCase		(      self)						->  List[Any]:




          '''simple docstring'''
          # Test which aims to verify that the offsets are well adapted to the argument `add_prefix_space`
          for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
             with self.subTest(f"{tokenizer.__class__.__name__} ({pretrained_name})"):
                _UpperCAmelCase       :       Any							   ='hello'  # `hello` is a token in the vocabulary of `pretrained_name`
                _UpperCAmelCase       :       List[Any]							   =f"{text_of_1_token} {text_of_1_token}"

                _UpperCAmelCase       :       Tuple							   =self.rust_tokenizer_class.from_pretrained(
                    snake_case  ,							use_fast=snake_case  ,							)
                _UpperCAmelCase       :       Optional[int]							   =tokenizer_r(snake_case  ,							return_offsets_mapping=snake_case  ,							add_special_tokens=snake_case)
                self.assertEqual(encoding.offset_mapping[0]  ,							(0, len(snake_case)))
                self.assertEqual(
                    encoding.offset_mapping[1]  ,							(len(snake_case) + 1, len(snake_case) + 1 + len(snake_case))  ,							)

                _UpperCAmelCase       :       Dict							   =f" {text}"

                _UpperCAmelCase       :       str							   =self.rust_tokenizer_class.from_pretrained(
                    snake_case  ,							use_fast=snake_case  ,							)
                _UpperCAmelCase       :       Optional[Any]							   =tokenizer_r(snake_case  ,							return_offsets_mapping=snake_case  ,							add_special_tokens=snake_case)
                self.assertEqual(encoding.offset_mapping[0]  ,							(1, 1 + len(snake_case)))
                self.assertEqual(
                    encoding.offset_mapping[1]  ,							(1 + len(snake_case) + 1, 1 + len(snake_case) + 1 + len(snake_case))  ,							)






       def       lowerCAmelCase		(      self)						->  List[Any]:




          '''simple docstring'''
          # Test related to the breaking change introduced in transformers v4.17.0
          # We need to check that an error in raised when the user try to load a previous version of the tokenizer.
          with self.assertRaises(snake_case) as context:
             self.rust_tokenizer_class.from_pretrained('robot-test/old-clip-tokenizer')

          self.assertTrue(
              context.exception.args[0].startswith(
                  'The `backend_tokenizer` provided does not match the expected format.'))






       @require_ftfy
       def       lowerCAmelCase		(      self)						->  List[str]:




          '''simple docstring'''
          super().test_tokenization_python_rust_equals()






       def       lowerCAmelCase		(      self)						->  Union[str, Any]:




          '''simple docstring'''
          # CLIP always lower cases letters
          pass





'''simple docstring'''






from __future__ import annotations

import bisect





def lowerCamelCase__      (						__lowerCamelCase	:							list[int]	,   __lowerCamelCase	:							int	,   __lowerCamelCase	:							int = 0	,   __lowerCamelCase	:							int = -1							):







   '''simple docstring'''




   if hi < 0:
      _UpperCAmelCase       :       int							   =len(__lowerCamelCase							)

   while lo < hi:
      _UpperCAmelCase       :       Dict							   =lo + (hi - lo) // 2
      if sorted_collection[mid] < item:
         _UpperCAmelCase       :       int							   =mid + 1
      else:
         _UpperCAmelCase       :       Union[str, Any]							   =mid

   return lo





def lowerCamelCase__      (						__lowerCamelCase	:							list[int]	,   __lowerCamelCase	:							int	,   __lowerCamelCase	:							int = 0	,   __lowerCamelCase	:							int = -1							):







   '''simple docstring'''




   if hi < 0:
      _UpperCAmelCase       :       str							   =len(__lowerCamelCase							)

   while lo < hi:
      _UpperCAmelCase       :       List[Any]							   =lo + (hi - lo) // 2
      if sorted_collection[mid] <= item:
         _UpperCAmelCase       :       Dict							   =mid + 1
      else:
         _UpperCAmelCase       :       Tuple							   =mid

   return lo





def lowerCamelCase__      (						__lowerCamelCase	:							list[int]	,   __lowerCamelCase	:							int	,   __lowerCamelCase	:							int = 0	,   __lowerCamelCase	:							int = -1							):







   '''simple docstring'''




   sorted_collection.insert(bisect_left(__lowerCamelCase	,   __lowerCamelCase	,   __lowerCamelCase	,   __lowerCamelCase							)	,   __lowerCamelCase							)





def lowerCamelCase__      (						__lowerCamelCase	:							list[int]	,   __lowerCamelCase	:							int	,   __lowerCamelCase	:							int = 0	,   __lowerCamelCase	:							int = -1							):







   '''simple docstring'''




   sorted_collection.insert(bisect_right(__lowerCamelCase	,   __lowerCamelCase	,   __lowerCamelCase	,   __lowerCamelCase							)	,   __lowerCamelCase							)





def lowerCamelCase__      (						__lowerCamelCase	:							list[int]	,   __lowerCamelCase	:							int							):







   '''simple docstring'''




   _UpperCAmelCase       :       Optional[int]							   =0
   _UpperCAmelCase       :       Any							   =len(__lowerCamelCase							) - 1

   while left <= right:
      _UpperCAmelCase       :       int							   =left + (right - left) // 2
      _UpperCAmelCase       :       Union[str, Any]							   =sorted_collection[midpoint]
      if current_item == item:
         return midpoint
      elif item < current_item:
         _UpperCAmelCase       :       Optional[Any]							   =midpoint - 1
      else:
         _UpperCAmelCase       :       int							   =midpoint + 1
   return None





def lowerCamelCase__      (						__lowerCamelCase	:							list[int]	,   __lowerCamelCase	:							int							):







   '''simple docstring'''




   _UpperCAmelCase       :       Any							   =bisect.bisect_left(__lowerCamelCase	,   __lowerCamelCase							)
   if index != len(__lowerCamelCase							) and sorted_collection[index] == item:
      return index
   return None





def lowerCamelCase__      (						__lowerCamelCase	:							list[int]	,   __lowerCamelCase	:							int	,   __lowerCamelCase	:							int	,   __lowerCamelCase	:							int							):







   '''simple docstring'''




   if right < left:
      return None

   _UpperCAmelCase       :       str							   =left + (right - left) // 2

   if sorted_collection[midpoint] == item:
      return midpoint
   elif sorted_collection[midpoint] > item:
      return binary_search_by_recursion(__lowerCamelCase	,   __lowerCamelCase	,   __lowerCamelCase	,   midpoint - 1							)
   else:
      return binary_search_by_recursion(__lowerCamelCase	,   __lowerCamelCase	,   midpoint + 1	,   __lowerCamelCase							)


if __name__ == "__main__":
 lowercase							=input('Enter numbers separated by comma:\n').strip()
 lowercase							=sorted(int(item) for item in user_input.split(','))
 lowercase							=int(input('Enter a single number to be found in the list:\n'))
 lowercase							=binary_search(collection, target)
 if result is None:
  print(F"""{target} was not found in {collection}.""")
 else:
  print(F"""{target} was found at position {result} in {collection}.""")

