
from timeit import timeit

__lowerCAmelCase					:			Tuple			      =		{
    "MALAYALAM": True,
    "String": False,
    "rotor": True,
    "level": True,
    "A": True,
    "BB": True,
    "ABC": False,
    "amanaplanacanalpanama": True,  # "a man a plan a canal panama"
}
# Ensure our test data is valid
assert all((key == key[::-1]) is value for key, value in test_data.items())


def     UpperCAmelCase_  (						__lowerCAmelCase	) ->						bool:
    __lowercase		:			Dict	    =       0
    __lowercase		:			str	    =       len(__lowerCAmelCase	) - 1
    while start_i < end_i:
        if s[start_i] == s[end_i]:
            start_i += 1
            end_i -= 1
        else:
            return False
    return True


def     UpperCAmelCase_  (						__lowerCAmelCase	) ->						bool:
    __lowercase		:			int	    =       len(__lowerCAmelCase	) // 2
    __lowercase		:			int	    =       len(__lowerCAmelCase	)

    # We need to traverse till half of the length of string
    # as we can get access of the i'th last element from
    # i'th index.
    # eg: [0,1,2,3,4,5] => 4th index can be accessed
    # with the help of 1st index (i==n-i-1)
    # where n is length of string
    return all(s[i] == s[n - i - 1] for i in range(__lowerCAmelCase	)	)


def     UpperCAmelCase_  (						__lowerCAmelCase	) ->						bool:
    if len(__lowerCAmelCase	) <= 2:
        return True
    if s[0] == s[len(__lowerCAmelCase	) - 1]:
        return is_palindrome_recursive(s[1:-1]	)
    else:
        return False


def     UpperCAmelCase_  (						__lowerCAmelCase	) ->						bool:
    return s == s[::-1]


def     UpperCAmelCase_  (						__lowerCAmelCase	) ->						None:
    __lowercase		:			Dict	    =       F'all({name}(key) is value for key, value in test_data.items())'
    __lowercase		:			Optional[int]	    =       F'from __main__ import test_data, {name}'
    __lowercase		:			Optional[int]	    =       500_000
    __lowercase		:			str	    =       timeit(stmt=__lowerCAmelCase	,					setup=__lowerCAmelCase	,					number=__lowerCAmelCase	)
    print(F'{name:<35} finished {number:,} runs in {result:.5f} seconds'	)


if __name__ == "__main__":
 for key, value in test_data.items():
  assert is_palindrome(key) is is_palindrome_recursive(key)
  assert is_palindrome(key) is is_palindrome_slice(key)
  print(F'{key:21} {value}')
 print("a man a plan a canal panama")

 # finished 500,000 runs in 0.46793 seconds
 benchmark_function("is_palindrome_slice")
 # finished 500,000 runs in 0.85234 seconds
 benchmark_function("is_palindrome")
 # finished 500,000 runs in 1.32028 seconds
 benchmark_function("is_palindrome_recursive")
 # finished 500,000 runs in 2.08679 seconds
 benchmark_function("is_palindrome_traversal")




import unittest

from datasets import load_dataset

from transformers import BloomTokenizerFast
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin


@require_tokenizers
class 						__lowerCAmelCase	(	lowerCAmelCase_ , unittest.TestCase      ):



      """simple docstring"""







      A__	:			Dict        =    None
      A__	:			Any        =    BloomTokenizerFast
      A__	:			Optional[Any]        =    BloomTokenizerFast
      A__	:			List[Any]        =    True
      A__	:			int        =    False
      A__	:			Any        =    '''tokenizer_file'''
      A__	:			Optional[int]        =    {'''bos_token''': '''<s>''', '''eos_token''': '''</s>''', '''unk_token''': '''<unk>''', '''pad_token''': '''<pad>'''}




      def 		snake_case_			(      self		:       Any				):
          super().setUp()
          __lowercase		:			int	    =       BloomTokenizerFast.from_pretrained('''bigscience/tokenizer'''				)
          tokenizer.save_pretrained(self.tmpdirname				)




      def 		snake_case_			(      self		:       Dict				,       **_snake_case		:       Any				):
          kwargs.update(self.special_tokens_map				)
          return BloomTokenizerFast.from_pretrained(self.tmpdirname				,       **_snake_case				)




      def 		snake_case_			(      self		:       Any				):
          __lowercase		:			Dict	    =       self.get_rust_tokenizer()

          __lowercase		:			Optional[int]	    =       ['''The quick brown fox</s>''', '''jumps over the lazy dog</s>''']
          __lowercase		:			Union[str, Any]	    =       [[2175, 2_3714, 7_3173, 14_4252, 2], [77, 13_2619, 3478, 368, 10_9586, 3_5433, 2]]

          __lowercase		:			Optional[int]	    =       tokenizer.batch_encode_plus(_snake_case				)['''input_ids''']
          self.assertListEqual(_snake_case				,       _snake_case				)

          __lowercase		:			List[Any]	    =       tokenizer.batch_decode(_snake_case				)
          self.assertListEqual(_snake_case				,       _snake_case				)




      def 		snake_case_			(      self		:       str				,       _snake_case		:       int=6				):
          for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
              with self.subTest(F'{tokenizer.__class__.__name__} ({pretrained_name})'				):
                  __lowercase		:			Dict	    =       self.rust_tokenizer_class.from_pretrained(_snake_case				,       **_snake_case				)
                  # tokenizer_r.pad_token = None # Hotfixing padding = None
                  # Simple input
                  __lowercase		:			List[Any]	    =       '''This is a simple input'''
                  __lowercase		:			List[str]	    =       ['''This is a simple input 1''', '''This is a simple input 2''']
                  __lowercase		:			Optional[Any]	    =       ('''This is a simple input''', '''This is a pair''')
                  __lowercase		:			Any	    =       [
                      ('''This is a simple input 1''', '''This is a simple input 2'''),
                      ('''This is a simple pair 1''', '''This is a simple pair 2'''),
                  ]

                  # Simple input tests
                  try:
                      tokenizer_r.encode(_snake_case				,       max_length=_snake_case				)
                      tokenizer_r.encode_plus(_snake_case				,       max_length=_snake_case				)

                      tokenizer_r.batch_encode_plus(_snake_case				,       max_length=_snake_case				)
                      tokenizer_r.encode(_snake_case				,       max_length=_snake_case				)
                      tokenizer_r.batch_encode_plus(_snake_case				,       max_length=_snake_case				)
                  except ValueError:
                      self.fail('''Bloom Tokenizer should be able to deal with padding'''				)

                  __lowercase		:			Dict	    =       None  # Hotfixing padding = None
                  self.assertRaises(_snake_case				,       tokenizer_r.encode				,       _snake_case				,       max_length=_snake_case				,       padding='''max_length'''				)

                  # Simple input
                  self.assertRaises(_snake_case				,       tokenizer_r.encode_plus				,       _snake_case				,       max_length=_snake_case				,       padding='''max_length'''				)

                  # Simple input
                  self.assertRaises(
                      _snake_case				,       tokenizer_r.batch_encode_plus				,       _snake_case				,       max_length=_snake_case				,       padding='''max_length'''				,       )

                  # Pair input
                  self.assertRaises(_snake_case				,       tokenizer_r.encode				,       _snake_case				,       max_length=_snake_case				,       padding='''max_length'''				)

                  # Pair input
                  self.assertRaises(_snake_case				,       tokenizer_r.encode_plus				,       _snake_case				,       max_length=_snake_case				,       padding='''max_length'''				)

                  # Pair input
                  self.assertRaises(
                      _snake_case				,       tokenizer_r.batch_encode_plus				,       _snake_case				,       max_length=_snake_case				,       padding='''max_length'''				,       )




      def 		snake_case_			(      self		:       Optional[int]				):
          __lowercase		:			List[Any]	    =       self.get_rust_tokenizer()
          __lowercase		:			int	    =       load_dataset('''xnli'''				,       '''all_languages'''				,       split='''test'''				,       streaming=_snake_case				)

          __lowercase		:			Optional[Any]	    =       next(iter(_snake_case				)				)['''premise''']  # pick up one data
          __lowercase		:			List[str]	    =       list(sample_data.values()				)

          __lowercase		:			List[str]	    =       list(map(tokenizer.encode				,       _snake_case				)				)
          __lowercase		:			Tuple	    =       [tokenizer.decode(_snake_case				,       clean_up_tokenization_spaces=_snake_case				) for x in output_tokens]
          self.assertListEqual(_snake_case				,       _snake_case				)




      def 		snake_case_			(      self		:       List[Any]				):
          # The test has to be overriden because BLOOM uses ALiBi positional embeddings that does not have
          # any sequence length constraints. This test of the parent class will fail since it relies on the
          # maximum sequence length of the positoonal embeddings.
          self.assertGreaterEqual(len(self.tokenizer_class.pretrained_vocab_files_map				)				,       1				)
          self.assertGreaterEqual(len(list(self.tokenizer_class.pretrained_vocab_files_map.values()				)[0]				)				,       1				)


