



'''simple docstring'''





import argparse
import collections
import os
import re

from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_table.py
_lowerCAmelCase										=     '''src/transformers'''
_lowerCAmelCase										=     '''docs/source/en'''
_lowerCAmelCase										=     '''.'''
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase      ):



    """simple docstring"""





    with open(UpperCamelCase							,   """r"""							,   encoding="""utf-8"""							,   newline="""\n"""      ) as f:
        lowerCAmelCase__			:  Dict											= f.readlines()
    # Find the start prompt.
    lowerCAmelCase__			:  Optional[Any]											= 0
    while not lines[start_index].startswith(UpperCamelCase      ):
        start_index += 1
    start_index += 1

    lowerCAmelCase__			:  str											= start_index
    while not lines[end_index].startswith(UpperCamelCase      ):
        end_index += 1
    end_index -= 1

    while len(lines[start_index]      ) <= 1:
        start_index += 1
    while len(lines[end_index]      ) <= 1:
        end_index -= 1
    end_index += 1
    return "".join(lines[start_index:end_index]      ), start_index, end_index, lines


# Add here suffixes that are used to identify models, separated by |
_lowerCAmelCase										=     '''Model|Encoder|Decoder|ForConditionalGeneration'''
# Regexes that match TF/Flax/PT model names.
_lowerCAmelCase										=     re.compile(R'''TF(.*)(?:Model|Encoder|Decoder|ForConditionalGeneration)''')
_lowerCAmelCase										=     re.compile(R'''Flax(.*)(?:Model|Encoder|Decoder|ForConditionalGeneration)''')
# Will match any TF or Flax model too so need to be in an else branch afterthe two previous regexes.
_lowerCAmelCase										=     re.compile(R'''(.*)(?:Model|Encoder|Decoder|ForConditionalGeneration)''')


# This is to make sure the transformers module imported is the one in the repo.
_lowerCAmelCase										=     direct_transformers_import(TRANSFORMERS_PATH)
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase      ):



    """simple docstring"""





    lowerCAmelCase__			:  int											= re.finditer(""".+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)"""							,   UpperCamelCase      )
    return [m.group(0      ) for m in matches]
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase							,   UpperCamelCase      ):



    """simple docstring"""





    lowerCAmelCase__			:  Optional[Any]											= 2 if text == """✅""" or text == """❌""" else len(UpperCamelCase      )
    lowerCAmelCase__			:  Union[str, Any]											= (width - text_length) // 2
    lowerCAmelCase__			:  Union[str, Any]											= width - text_length - left_indent
    return " " * left_indent + text + " " * right_indent
def        _SCREAMING_SNAKE_CASE  (	):



    """simple docstring"""





    lowerCAmelCase__			:  Tuple											= transformers_module.models.auto.configuration_auto.CONFIG_MAPPING_NAMES
    lowerCAmelCase__			:  List[Any]											= {
        name: config_maping_names[code]
        for code, name in transformers_module.MODEL_NAMES_MAPPING.items()
        if code in config_maping_names
    }
    lowerCAmelCase__			:  Tuple											= {name: config.replace("""Config"""							,   """"""      ) for name, config in model_name_to_config.items()}

    # Dictionaries flagging if each model prefix has a slow/fast tokenizer, backend in PT/TF/Flax.
    lowerCAmelCase__			:  Optional[Any]											= collections.defaultdict(UpperCamelCase      )
    lowerCAmelCase__			:  Any											= collections.defaultdict(UpperCamelCase      )
    lowerCAmelCase__			:  Union[str, Any]											= collections.defaultdict(UpperCamelCase      )
    lowerCAmelCase__			:  List[str]											= collections.defaultdict(UpperCamelCase      )
    lowerCAmelCase__			:  Optional[Any]											= collections.defaultdict(UpperCamelCase      )

    # Let's lookup through all transformers object (once).
    for attr_name in dir(UpperCamelCase      ):
        lowerCAmelCase__			:  Any											= None
        if attr_name.endswith("""Tokenizer"""      ):
            lowerCAmelCase__			:  Union[str, Any]											= slow_tokenizers
            lowerCAmelCase__			:  Optional[Any]											= attr_name[:-9]
        elif attr_name.endswith("""TokenizerFast"""      ):
            lowerCAmelCase__			:  Dict											= fast_tokenizers
            lowerCAmelCase__			:  List[Any]											= attr_name[:-13]
        elif _re_tf_models.match(UpperCamelCase      ) is not None:
            lowerCAmelCase__			:  List[str]											= tf_models
            lowerCAmelCase__			:  Optional[int]											= _re_tf_models.match(UpperCamelCase      ).groups()[0]
        elif _re_flax_models.match(UpperCamelCase      ) is not None:
            lowerCAmelCase__			:  Dict											= flax_models
            lowerCAmelCase__			:  List[str]											= _re_flax_models.match(UpperCamelCase      ).groups()[0]
        elif _re_pt_models.match(UpperCamelCase      ) is not None:
            lowerCAmelCase__			:  Dict											= pt_models
            lowerCAmelCase__			:  Dict											= _re_pt_models.match(UpperCamelCase      ).groups()[0]

        if lookup_dict is not None:
            while len(UpperCamelCase      ) > 0:
                if attr_name in model_name_to_prefix.values():
                    lowerCAmelCase__			:  str											= True
                    break
                # Try again after removing the last word in the name
                lowerCAmelCase__			:  str											= """""".join(camel_case_split(UpperCamelCase      )[:-1]      )

    # Let's build that table!
    lowerCAmelCase__			:  Dict											= list(model_name_to_config.keys()      )
    model_names.sort(key=str.lower      )
    lowerCAmelCase__			:  Any											= ["""Model""", """Tokenizer slow""", """Tokenizer fast""", """PyTorch support""", """TensorFlow support""", """Flax Support"""]
    # We'll need widths to properly display everything in the center (+2 is to leave one extra space on each side).
    lowerCAmelCase__			:  List[Any]											= [len(UpperCamelCase      ) + 2 for c in columns]
    lowerCAmelCase__			:  str											= max([len(UpperCamelCase      ) for name in model_names]      ) + 2

    # Build the table per se
    lowerCAmelCase__			:  Union[str, Any]											= """|""" + """|""".join([_center_text(UpperCamelCase							,   UpperCamelCase      ) for c, w in zip(UpperCamelCase							,   UpperCamelCase      )]      ) + """|\n"""
    # Use ":-----:" format to center-aligned table cell texts
    table += "|" + "|".join([""":""" + """-""" * (w - 2) + """:""" for w in widths]      ) + "|\n"

    lowerCAmelCase__			:  Union[str, Any]											= {True: """✅""", False: """❌"""}
    for name in model_names:
        lowerCAmelCase__			:  List[str]											= model_name_to_prefix[name]
        lowerCAmelCase__			:  Optional[int]											= [
            name,
            check[slow_tokenizers[prefix]],
            check[fast_tokenizers[prefix]],
            check[pt_models[prefix]],
            check[tf_models[prefix]],
            check[flax_models[prefix]],
        ]
        table += "|" + "|".join([_center_text(UpperCamelCase							,   UpperCamelCase      ) for l, w in zip(UpperCamelCase							,   UpperCamelCase      )]      ) + "|\n"
    return table
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase=False      ):



    """simple docstring"""





    lowerCAmelCase__				,       lowerCAmelCase__				,       lowerCAmelCase__				,       lowerCAmelCase__			:  List[Any]											= _find_text_in_file(
        filename=os.path.join(UpperCamelCase							,   """index.md"""      )							,   start_prompt="""<!--This table is updated automatically from the auto modules"""							,   end_prompt="""<!-- End table-->"""							,   )
    lowerCAmelCase__			:  str											= get_model_table_from_auto_modules()

    if current_table != new_table:
        if overwrite:
            with open(os.path.join(UpperCamelCase							,   """index.md"""      )							,   """w"""							,   encoding="""utf-8"""							,   newline="""\n"""      ) as f:
                f.writelines(lines[:start_index] + [new_table] + lines[end_index:]      )
        else:
            raise ValueError(
                """The model table in the `index.md` has not been updated. Run `make fix-copies` to fix this."""      )


if __name__ == "__main__":
 _lowerCAmelCase										=     argparse.ArgumentParser()
 parser.add_argument('''--fix_and_overwrite''', action='''store_true''', help='''Whether to fix inconsistencies.''')
 _lowerCAmelCase										=     parser.parse_args()

 check_model_table(args.fix_and_overwrite)







'''simple docstring'''





from typing import Any






class 	lowerCAmelCase_:
  '''simple docstring'''




  def __init__(   self  ,__UpperCAmelCase				)   ->		Any:
      lowerCAmelCase__			:  Optional[Any]											= data
      lowerCAmelCase__			:  str											= None






  def __repr__(   self				)   ->		str:
      return F"""Node({self.data})"""







class 	lowerCAmelCase_:
  '''simple docstring'''




  def __init__(   self				)   ->		List[Any]:
      lowerCAmelCase__			:  List[str]											= None




  def __iter__(   self				)   ->		Any:
      lowerCAmelCase__			:  int											= self.head
      while node:
          yield node.data
          lowerCAmelCase__			:  Optional[Any]											= node.next




  def __len__(   self				)   ->		int:
      return sum(1 for _ in self				)




  def __repr__(   self				)   ->		str:
      return "->".join([str(__UpperCAmelCase				) for item in self]				)




  def __getitem__(   self  ,__UpperCAmelCase				)   ->		Any:
      if not 0 <= index < len(self				):
          raise ValueError("""list index out of range."""				)
      for i, node in enumerate(self				):
          if i == index:
              return node
      return None




  def __setitem__(   self  ,__UpperCAmelCase  ,__UpperCAmelCase				)   ->		None:
      if not 0 <= index < len(self				):
          raise ValueError("""list index out of range."""				)
      lowerCAmelCase__			:  List[Any]											= self.head
      for _ in range(__UpperCAmelCase				):
          lowerCAmelCase__			:  List[str]											= current.next
      lowerCAmelCase__			:  Dict											= data




  def 							UpperCAmelCase_     (   self  ,__UpperCAmelCase				)   ->		None:
      self.insert_nth(len(self				)  ,__UpperCAmelCase				)




  def 							UpperCAmelCase_     (   self  ,__UpperCAmelCase				)   ->		None:
      self.insert_nth(0  ,__UpperCAmelCase				)




  def 							UpperCAmelCase_     (   self  ,__UpperCAmelCase  ,__UpperCAmelCase				)   ->		None:
      if not 0 <= index <= len(self				):
          raise IndexError("""list index out of range"""				)
      lowerCAmelCase__			:  str											= Node(__UpperCAmelCase				)
      if self.head is None:
          lowerCAmelCase__			:  List[Any]											= new_node
      elif index == 0:
          lowerCAmelCase__			:  Dict											= self.head  # link new_node to head
          lowerCAmelCase__			:  int											= new_node
      else:
          lowerCAmelCase__			:  Any											= self.head
          for _ in range(index - 1				):
              lowerCAmelCase__			:  Tuple											= temp.next
          lowerCAmelCase__			:  str											= temp.next
          lowerCAmelCase__			:  Optional[int]											= new_node




  def 							UpperCAmelCase_     (   self				)   ->		None:  # print every node data
      print(self				)




  def 							UpperCAmelCase_     (   self				)   ->		Any:
      return self.delete_nth(0				)




  def 							UpperCAmelCase_     (   self				)   ->		Any:  # delete from tail
      return self.delete_nth(len(self				) - 1				)




  def 							UpperCAmelCase_     (   self  ,__UpperCAmelCase = 0				)   ->		Any:
      if not 0 <= index <= len(self				) - 1:  # test if index is valid
          raise IndexError("""List index out of range."""				)
      lowerCAmelCase__			:  List[Any]											= self.head  # default first node
      if index == 0:
          lowerCAmelCase__			:  str											= self.head.next
      else:
          lowerCAmelCase__			:  int											= self.head
          for _ in range(index - 1				):
              lowerCAmelCase__			:  Union[str, Any]											= temp.next
          lowerCAmelCase__			:  Optional[Any]											= temp.next
          lowerCAmelCase__			:  Any											= temp.next.next
      return delete_node.data




  def 							UpperCAmelCase_     (   self				)   ->		bool:
      return self.head is None






  def 							UpperCAmelCase_     (   self				)   ->		None:
      lowerCAmelCase__			:  Optional[int]											= None
      lowerCAmelCase__			:  str											= self.head

      while current:
          # Store the current node's next node.
          lowerCAmelCase__			:  Optional[Any]											= current.next
          # Make the current node's next point backwards
          lowerCAmelCase__			:  Optional[int]											= prev
          # Make the previous node be the current node
          lowerCAmelCase__			:  Optional[Any]											= current
          # Make the current node the next node (to progress iteration)
          lowerCAmelCase__			:  Optional[int]											= next_node
      # Return prev in order to put the head at the end
      lowerCAmelCase__			:  List[str]											= prev







def        _SCREAMING_SNAKE_CASE  (	):



    """simple docstring"""





    lowerCAmelCase__			:  Dict											= LinkedList()
    assert linked_list.is_empty() is True
    assert str(UpperCamelCase      ) == ""

    try:
        linked_list.delete_head()
        raise AssertionError  # This should not happen.
    except IndexError:
        assert True  # This should happen.

    try:
        linked_list.delete_tail()
        raise AssertionError  # This should not happen.
    except IndexError:
        assert True  # This should happen.

    for i in range(10      ):
        assert len(UpperCamelCase      ) == i
        linked_list.insert_nth(UpperCamelCase							,   i + 1      )
    assert str(UpperCamelCase      ) == "->".join(str(UpperCamelCase      ) for i in range(1							,   11      )      )

    linked_list.insert_head(0      )
    linked_list.insert_tail(11      )
    assert str(UpperCamelCase      ) == "->".join(str(UpperCamelCase      ) for i in range(0							,   12      )      )

    assert linked_list.delete_head() == 0
    assert linked_list.delete_nth(9      ) == 10
    assert linked_list.delete_tail() == 11
    assert len(UpperCamelCase      ) == 9
    assert str(UpperCamelCase      ) == "->".join(str(UpperCamelCase      ) for i in range(1							,   10      )      )

    assert all(linked_list[i] == i + 1 for i in range(0							,   9      )      ) is True

    for i in range(0							,   9      ):
        lowerCAmelCase__			:  str											= -i
    assert all(linked_list[i] == -i for i in range(0							,   9      )      ) is True

    linked_list.reverse()
    assert str(UpperCamelCase      ) == "->".join(str(UpperCamelCase      ) for i in range(-8							,   1      )      )
def        _SCREAMING_SNAKE_CASE  (	):



    """simple docstring"""





    lowerCAmelCase__			:  Any											= [
        -9,
        100,
        Node(77345112      ),
        """dlrow olleH""",
        7,
        5555,
        0,
        -192.5_5555,
        """Hello, world!""",
        77.9,
        Node(10      ),
        None,
        None,
        12.20,
    ]
    lowerCAmelCase__			:  List[Any]											= LinkedList()

    for i in test_input:
        linked_list.insert_tail(UpperCamelCase      )

    # Check if it's empty or not
    assert linked_list.is_empty() is False
    assert (
        str(UpperCamelCase      ) == "-9->100->Node(77345112)->dlrow olleH->7->5555->0->"
        "-192.55555->Hello, world!->77.9->Node(10)->None->None->12.2"
    )

    # Delete the head
    lowerCAmelCase__			:  List[str]											= linked_list.delete_head()
    assert result == -9
    assert (
        str(UpperCamelCase      ) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
        "Hello, world!->77.9->Node(10)->None->None->12.2"
    )

    # Delete the tail
    lowerCAmelCase__			:  Union[str, Any]											= linked_list.delete_tail()
    assert result == 12.2
    assert (
        str(UpperCamelCase      ) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
        "Hello, world!->77.9->Node(10)->None->None"
    )

    # Delete a node in specific location in linked list
    lowerCAmelCase__			:  str											= linked_list.delete_nth(10      )
    assert result is None
    assert (
        str(UpperCamelCase      ) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
        "Hello, world!->77.9->Node(10)->None"
    )

    # Add a Node instance to its head
    linked_list.insert_head(Node("""Hello again, world!"""      )      )
    assert (
        str(UpperCamelCase      )
        == "Node(Hello again, world!)->100->Node(77345112)->dlrow olleH->"
        "7->5555->0->-192.55555->Hello, world!->77.9->Node(10)->None"
    )

    # Add None to its tail
    linked_list.insert_tail(UpperCamelCase      )
    assert (
        str(UpperCamelCase      )
        == "Node(Hello again, world!)->100->Node(77345112)->dlrow olleH->"
        "7->5555->0->-192.55555->Hello, world!->77.9->Node(10)->None->None"
    )

    # Reverse the linked list
    linked_list.reverse()
    assert (
        str(UpperCamelCase      )
        == "None->None->Node(10)->77.9->Hello, world!->-192.55555->0->5555->"
        "7->dlrow olleH->Node(77345112)->100->Node(Hello again, world!)"
    )
def        _SCREAMING_SNAKE_CASE  (	):



    """simple docstring"""





    from doctest import testmod

    testmod()

    lowerCAmelCase__			:  str											= LinkedList()
    linked_list.insert_head(input("""Inserting 1st at head """      ).strip()      )
    linked_list.insert_head(input("""Inserting 2nd at head """      ).strip()      )
    print("""\nPrint list:"""      )
    linked_list.print_list()
    linked_list.insert_tail(input("""\nInserting 1st at tail """      ).strip()      )
    linked_list.insert_tail(input("""Inserting 2nd at tail """      ).strip()      )
    print("""\nPrint list:"""      )
    linked_list.print_list()
    print("""\nDelete head"""      )
    linked_list.delete_head()
    print("""Delete tail"""      )
    linked_list.delete_tail()
    print("""\nPrint list:"""      )
    linked_list.print_list()
    print("""\nReverse linked list"""      )
    linked_list.reverse()
    print("""\nPrint list:"""      )
    linked_list.print_list()
    print("""\nString representation of linked list:"""      )
    print(UpperCamelCase      )
    print("""\nReading/changing Node data using indexing:"""      )
    print(f"""Element at Position 1: {linked_list[1]}"""      )
    lowerCAmelCase__			:  Dict											= input("""Enter New Value: """      ).strip()
    print("""New list:"""      )
    print(UpperCamelCase      )
    print(f"""length of linked_list is : {len(UpperCamelCase      )}"""      )


if __name__ == "__main__":
 main()


