



'''simple docstring'''





import warnings
from typing import Dict, List, Optional, Tuple

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


_lowerCAmelCase 		=      logging.get_logger(__name__)






class 			lowerCAmelCase_(							__lowerCAmelCase	):
  '''simple docstring'''




  __lowercase				: Dict           = ['''input_ids''', '''attention_mask''']




  def __init__(       self    ,__UpperCAmelCase="</s>"    ,__UpperCAmelCase="<unk>"    ,__UpperCAmelCase="<pad>"    ,__UpperCAmelCase=125    ,__UpperCAmelCase=None    ,**__UpperCAmelCase    ,)       ->						Dict:
      # Add extra_ids to the special token list
      if extra_ids > 0 and additional_special_tokens is None:
          lowerCAmelCase__					:    Tuple				 =   [F"""<extra_id_{i}>""" for i in range(_UpperCAmelCase )]
      elif extra_ids > 0 and additional_special_tokens is not None:
          # Check that we have the right number of extra_id special tokens
          lowerCAmelCase__					:    List[Any]				 =   len(set(filter(lambda __UpperCAmelCase : bool("""extra_id""" in str(_UpperCAmelCase ) )    ,_UpperCAmelCase ) ) )
          if extra_tokens != extra_ids:
              raise ValueError(
                  F"""Both extra_ids ({extra_ids}) and additional_special_tokens ({additional_special_tokens}) are"""
                  """ provided to ByT5Tokenizer. In this case the additional_special_tokens must include the"""
                  """ extra_ids tokens""" )

      lowerCAmelCase__					:    Tuple				 =   AddedToken(_UpperCAmelCase    ,lstrip=_UpperCAmelCase    ,rstrip=_UpperCAmelCase ) if isinstance(_UpperCAmelCase    ,_UpperCAmelCase ) else pad_token
      lowerCAmelCase__					:    List[str]				 =   AddedToken(_UpperCAmelCase    ,lstrip=_UpperCAmelCase    ,rstrip=_UpperCAmelCase ) if isinstance(_UpperCAmelCase    ,_UpperCAmelCase ) else eos_token
      lowerCAmelCase__					:    Tuple				 =   AddedToken(_UpperCAmelCase    ,lstrip=_UpperCAmelCase    ,rstrip=_UpperCAmelCase ) if isinstance(_UpperCAmelCase    ,_UpperCAmelCase ) else unk_token

      super().__init__(
          eos_token=_UpperCAmelCase    ,unk_token=_UpperCAmelCase    ,pad_token=_UpperCAmelCase    ,extra_ids=_UpperCAmelCase    ,additional_special_tokens=_UpperCAmelCase    ,**_UpperCAmelCase    ,)

      lowerCAmelCase__					:    Tuple				 =   extra_ids

      lowerCAmelCase__					:    Dict				 =   2**8  # utf is 8 bits

      # define special tokens dict
      lowerCAmelCase__					:    List[str]				 =   {
          self.pad_token: 0,
          self.eos_token: 1,
          self.unk_token: 2,
      }
      lowerCAmelCase__					:    Optional[int]				 =   len(self.special_tokens_encoder )
      lowerCAmelCase__					:    List[Any]				 =   len(_UpperCAmelCase )
      for i, token in enumerate(_UpperCAmelCase ):
          lowerCAmelCase__					:    Any				 =   self.vocab_size + i - n
      lowerCAmelCase__					:    Dict				 =   {v: k for k, v in self.special_tokens_encoder.items()}




  @property
  def 				UpperCAmelCase_      (       self )       ->						str:
      return self._utf_vocab_size + self._num_special_tokens + self._extra_ids




  def 				UpperCAmelCase_      (       self    ,__UpperCAmelCase    ,__UpperCAmelCase = None    ,__UpperCAmelCase = False )       ->						str:
      if already_has_special_tokens:
          return super().get_special_tokens_mask(
              token_ids_a=_UpperCAmelCase    ,token_ids_a=_UpperCAmelCase    ,already_has_special_tokens=_UpperCAmelCase )

      # normal case: some special tokens
      if token_ids_a is None:
          return ([0] * len(_UpperCAmelCase )) + [1]
      return ([0] * len(_UpperCAmelCase )) + [1] + ([0] * len(_UpperCAmelCase )) + [1]




  def 				UpperCAmelCase_      (       self    ,__UpperCAmelCase )       ->						Optional[int]:
      if len(_UpperCAmelCase ) > 0 and token_ids[-1] == self.eos_token_id:
          warnings.warn(
              F"""This sequence already has {self.eos_token}. In future versions this behavior may lead to duplicated"""
              """ eos tokens being added.""" )
          return token_ids
      else:
          return token_ids + [self.eos_token_id]




  def 				UpperCAmelCase_      (       self    ,__UpperCAmelCase    ,__UpperCAmelCase = None )       ->						Tuple:
      lowerCAmelCase__					:    int				 =   [self.eos_token_id]

      if token_ids_a is None:
          return len(token_ids_a + eos ) * [0]
      return len(token_ids_a + eos + token_ids_a + eos ) * [0]




  def 				UpperCAmelCase_      (       self    ,__UpperCAmelCase    ,__UpperCAmelCase = None )       ->						Any:
      lowerCAmelCase__					:    List[Any]				 =   self._add_eos_if_not_present(_UpperCAmelCase )
      if token_ids_a is None:
          return token_ids_a
      else:
          lowerCAmelCase__					:    int				 =   self._add_eos_if_not_present(_UpperCAmelCase )
          return token_ids_a + token_ids_a




  def 				UpperCAmelCase_      (       self    ,__UpperCAmelCase )       ->						int:
      lowerCAmelCase__					:    Optional[Any]				 =   [chr(_UpperCAmelCase ) for i in text.encode("""utf-8""" )]
      return tokens




  def 				UpperCAmelCase_      (       self    ,__UpperCAmelCase )       ->						Any:
      if token in self.special_tokens_encoder:
          lowerCAmelCase__					:    Union[str, Any]				 =   self.special_tokens_encoder[token]
      elif token in self.added_tokens_encoder:
          lowerCAmelCase__					:    List[str]				 =   self.added_tokens_encoder[token]
      elif len(_UpperCAmelCase ) != 1:
          lowerCAmelCase__					:    Any				 =   self.unk_token_id
      else:
          lowerCAmelCase__					:    Optional[Any]				 =   ord(_UpperCAmelCase ) + self._num_special_tokens
      return token_id




  def 				UpperCAmelCase_      (       self    ,__UpperCAmelCase )       ->						Optional[int]:
      if index in self.special_tokens_decoder:
          lowerCAmelCase__					:    str				 =   self.special_tokens_decoder[index]
      else:
          lowerCAmelCase__					:    Optional[int]				 =   chr(index - self._num_special_tokens )
      return token




  def 				UpperCAmelCase_      (       self    ,__UpperCAmelCase )       ->						Union[str, Any]:
      lowerCAmelCase__					:    List[str]				 =   B""""""
      for token in tokens:
          if token in self.special_tokens_decoder:
              lowerCAmelCase__					:    int				 =   self.special_tokens_decoder[token].encode("""utf-8""" )
          elif token in self.added_tokens_decoder:
              lowerCAmelCase__					:    Optional[Any]				 =   self.special_tokens_decoder[token].encode("""utf-8""" )
          elif token in self.special_tokens_encoder:
              lowerCAmelCase__					:    int				 =   token.encode("""utf-8""" )
          elif token in self.added_tokens_encoder:
              lowerCAmelCase__					:    List[str]				 =   token.encode("""utf-8""" )
          else:
              lowerCAmelCase__					:    str				 =   bytes([ord(_UpperCAmelCase )] )
          bstring += tok_string
      lowerCAmelCase__					:    Union[str, Any]				 =   bstring.decode("""utf-8"""    ,errors="""ignore""" )
      return string






  def 				UpperCAmelCase_      (       self    ,__UpperCAmelCase    ,__UpperCAmelCase = None )       ->						Tuple:
      return ()








"""simple docstring"""

def 		_snake_case	(   _snake_case				:   int							,    _snake_case				:   int				)       ->   int:






      '''simple docstring'''


      return int((input_a, input_a).count(1				) != 0				)






def 		_snake_case	(   )       ->   None:






      '''simple docstring'''


      assert or_gate(0							,    0				) == 0
      assert or_gate(0							,    1				) == 1
      assert or_gate(1							,    0				) == 1
      assert or_gate(1							,    1				) == 1


if __name__ == "__main__":
       print(or_gate(0, 1))
       print(or_gate(1, 0))
       print(or_gate(0, 0))
       print(or_gate(1, 1))

