





"""simple docstring"""


import json
import os
import unittest

from transformers import MgpstrTokenizer
from transformers.models.mgp_str.tokenization_mgp_str import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin



@require_tokenizers
class      __SCREAMING_SNAKE_CASE    (						_UpperCamelCase		,  unittest.TestCase   ):







  '''simple docstring'''


  SCREAMING_SNAKE_CASE__							:Optional[int]	     =					MgpstrTokenizer
  SCREAMING_SNAKE_CASE__							:Tuple	     =					False
  SCREAMING_SNAKE_CASE__							:Tuple	     =					{}
  SCREAMING_SNAKE_CASE__							:Optional[int]	     =					False

  def    __SCREAMING_SNAKE_CASE				(		self   :       Any	)		->				Tuple:
        super().setUp()

        # fmt: off
        _UpperCamelCase      :	Tuple						=       ["[GO]", "[s]", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
        # fmt: on
        _UpperCamelCase      :	List[str]						=       dict(zip(__a					,   range(len(__a	)	)	)	)

        _UpperCamelCase      :	List[str]						=       os.path.join(self.tmpdirname					,   VOCAB_FILES_NAMES["vocab_file"]	)
        with open(self.vocab_file					,   "w"					,   encoding="utf-8"	) as fp:
              fp.write(json.dumps(__a	) + "\n"	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       Optional[int]					,   **__a   :       Any	)		->				Optional[int]:
        return MgpstrTokenizer.from_pretrained(self.tmpdirname					,   **__a	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       Optional[Any]					,   __a   :       Optional[int]	)		->				Tuple:
        _UpperCamelCase      :	Tuple						=       "tester"
        _UpperCamelCase      :	Optional[int]						=       "tester"
        return input_text, output_text

  @unittest.skip("MGP-STR always lower cases letters."	)
  def    __SCREAMING_SNAKE_CASE				(		self   :       str	)		->				Any:
        pass

  def    __SCREAMING_SNAKE_CASE				(		self   :       Union[str, Any]	)		->				List[Any]:
        _UpperCamelCase      :	Optional[int]						=       self.get_tokenizers(do_lower_case=__a	)
        for tokenizer in tokenizers:
              with self.subTest(F'''{tokenizer.__class__.__name__}'''	):
                    _UpperCamelCase      :	Tuple						=       "[SPECIAL_TOKEN]"

                    tokenizer.add_special_tokens({"cls_token": special_token}	)
                    _UpperCamelCase      :	List[str]						=       tokenizer.encode([special_token]					,   add_special_tokens=__a	)
                    self.assertEqual(len(__a	)					,   1	)

                    _UpperCamelCase      :	str						=       tokenizer.decode(__a					,   skip_special_tokens=__a	)
                    self.assertTrue(special_token not in decoded	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       List[str]	)		->				Dict:
        _UpperCamelCase      :	int						=       self.get_tokenizers()
        for tokenizer in tokenizers:
              with self.subTest(F'''{tokenizer.__class__.__name__}'''	):
                    _UpperCamelCase      :	Dict						=       self.get_input_output_texts(__a	)

                    _UpperCamelCase      :	Tuple						=       tokenizer.tokenize(__a	)
                    _UpperCamelCase      :	Dict						=       tokenizer.convert_tokens_to_ids(__a	)
                    _UpperCamelCase      :	str						=       tokenizer.encode(__a					,   add_special_tokens=__a	)
                    self.assertListEqual(__a					,   __a	)

                    _UpperCamelCase      :	Dict						=       tokenizer.convert_ids_to_tokens(__a	)
                    self.assertNotEqual(len(__a	)					,   0	)
                    _UpperCamelCase      :	Dict						=       tokenizer.decode(__a	)
                    self.assertIsInstance(__a					,   __a	)

                    self.assertEqual(text_a.replace(" "					,   ""	)					,   __a	)

  @unittest.skip("MGP-STR tokenizer only handles one sequence."	)
  def    __SCREAMING_SNAKE_CASE				(		self   :       List[Any]	)		->				int:
        pass


  @unittest.skip("inputs cannot be pretokenized in MgpstrTokenizer"	)
  def    __SCREAMING_SNAKE_CASE				(		self   :       int	)		->				List[str]:
        pass







"""simple docstring"""


class      __SCREAMING_SNAKE_CASE    :







  '''simple docstring'''


  def __init__(		self   :       Optional[Any]					,   __a   :       list[int]	)		->				None:
        _UpperCamelCase      :	Tuple						=       len(__a	)
        _UpperCamelCase      :	Dict						=       [0] * len_array

        if len_array > 0:
              _UpperCamelCase      :	Optional[Any]						=       array[0]

        for i in range(1					,   __a	):
              _UpperCamelCase      :	Tuple						=       self.prefix_sum[i - 1] + array[i]

  def    __SCREAMING_SNAKE_CASE				(		self   :       Dict					,   __a   :       int					,   __a   :       int	)		->				int:
        if start == 0:
              return self.prefix_sum[end]

        return self.prefix_sum[end] - self.prefix_sum[start - 1]


  def    __SCREAMING_SNAKE_CASE				(		self   :       Optional[Any]					,   __a   :       int	)		->				bool:
        _UpperCamelCase      :	int						=       {0}
        for sum_item in self.prefix_sum:
              if sum_item - target_sum in sums:
                    return True

              sums.add(__a	)

        return False


if __name__ == "__main__":
  import doctest

  doctest.testmod()
