





"""simple docstring"""




from typing import Any





class 			A__   :




   """simple docstring"""



   def __init__( self ,  lowercase)      ->						List[str]:







          '''simple docstring'''

          a__						:     Any			=    data
          a__						:     str			=    None

   def __repr__( self)      ->						str:







          '''simple docstring'''

          return F'Node({self.data})'





class 			A__   :




   """simple docstring"""



   def __init__( self)      ->						Any:







          '''simple docstring'''

          a__						:     Dict			=    None

   def __iter__( self)      ->						Any:







          '''simple docstring'''

          a__						:     Optional[int]			=    self.head
          while node:
                 yield node.data
                 a__						:     Dict			=    node.next

   def __len__( self)      ->						int:







          '''simple docstring'''

          return sum(1 for _ in self)

   def __repr__( self)      ->						str:







          '''simple docstring'''

          return "->".join([str(lowercase) for item in self])

   def __getitem__( self ,  lowercase)      ->						Any:







          '''simple docstring'''

          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 ,  lowercase ,  lowercase)      ->						None:







          '''simple docstring'''

          if not 0 <= index < len(self):
                 raise ValueError('list index out of range.')
          a__						:     Any			=    self.head
          for _ in range(lowercase):
                 a__						:     int			=    current.next
          a__						:     Union[str, Any]			=    data

   def 							__lowercase		( self ,  lowercase)      ->						None:







          '''simple docstring'''

          self.insert_nth(len(self) ,  lowercase)

   def 							__lowercase		( self ,  lowercase)      ->						None:







          '''simple docstring'''

          self.insert_nth(0 ,  lowercase)

   def 							__lowercase		( self ,  lowercase ,  lowercase)      ->						None:







          '''simple docstring'''

          if not 0 <= index <= len(self):
                 raise IndexError('list index out of range')
          a__						:     Any			=    Node(lowercase)
          if self.head is None:
                 a__						:     str			=    new_node
          elif index == 0:
                 a__						:     List[Any]			=    self.head  # link new_node to head
                 a__						:     List[Any]			=    new_node
          else:
                 a__						:     Tuple			=    self.head
                 for _ in range(index - 1):
                        a__						:     Optional[int]			=    temp.next
                 a__						:     Optional[Any]			=    temp.next
                 a__						:     Tuple			=    new_node

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







          '''simple docstring'''

          print(self)

   def 							__lowercase		( self)      ->						Any:







          '''simple docstring'''

          return self.delete_nth(0)

   def 							__lowercase		( self)      ->						Any:  # delete from tail







          '''simple docstring'''

          return self.delete_nth(len(self) - 1)

   def 							__lowercase		( self ,  lowercase = 0)      ->						Any:







          '''simple docstring'''

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

   def 							__lowercase		( self)      ->						bool:







          '''simple docstring'''

          return self.head is None

   def 							__lowercase		( self)      ->						None:







          '''simple docstring'''

          a__						:     Tuple			=    None
          a__						:     Tuple			=    self.head

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



def A_     (		)  ->		None:
       a__						:     List[str]			=    LinkedList()
       assert linked_list.is_empty() is True
       assert str(A__    ) == ""

       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(A__    ) == i
              linked_list.insert_nth(A__		,				i + 1    )
       assert str(A__    ) == "->".join(str(A__    ) for i in range(1		,				11    )    )

       linked_list.insert_head(0    )
       linked_list.insert_tail(11    )
       assert str(A__    ) == "->".join(str(A__    ) 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(A__    ) == 9
       assert str(A__    ) == "->".join(str(A__    ) 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    ):
              a__						:     List[Any]			=    -i
       assert all(linked_list[i] == -i for i in range(0		,				9    )    ) is True

       linked_list.reverse()
       assert str(A__    ) == "->".join(str(A__    ) for i in range(-8		,				1    )    )



def A_     (		)  ->		None:
       a__						:     List[Any]			=    [
           -9,
           100,
           Node(7734_5112    ),
           'dlrow olleH',
           7,
           5555,
           0,
           -192.5_5555,
           'Hello, world!',
           77.9,
           Node(10    ),
           None,
           None,
           12.20,
       ]
       a__						:     Dict			=    LinkedList()

       for i in test_input:
              linked_list.insert_tail(A__    )

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

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

       # Delete the tail
       a__						:     Tuple			=    linked_list.delete_tail()
       assert result == 12.2
       assert (
           str(A__    ) == "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
       a__						:     List[str]			=    linked_list.delete_nth(10    )
       assert result is None
       assert (
           str(A__    ) == "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(A__    )
           == "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(A__    )
       assert (
           str(A__    )
           == "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(A__    )
           == "None->None->Node(10)->77.9->Hello, world!->-192.55555->0->5555->"
           "7->dlrow olleH->Node(77345112)->100->Node(Hello again, world!)"
       )



def A_     (		)  ->		str:
       from doctest import testmod

       testmod()

       a__						:     Union[str, Any]			=    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(A__    )
       print('\nReading/changing Node data using indexing:'    )
       print(F'Element at Position 1: {linked_list[1]}'    )
       a__						:     Union[str, Any]			=    input('Enter New Value: '    ).strip()
       print('New list:'    )
       print(A__    )
       print(F'length of linked_list is : {len(A__    )}'    )


if __name__ == "__main__":
    main()









import argparse
import os
import pickle
import sys

import torch

from transformers import TransfoXLConfig, TransfoXLLMHeadModel, load_tf_weights_in_transfo_xl
from transformers.models.transfo_xl import tokenization_transfo_xl as data_utils
from transformers.models.transfo_xl.tokenization_transfo_xl import CORPUS_NAME, VOCAB_FILES_NAMES
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()

# We do this to be able to load python 2 datasets pickles
# See e.g. https://stackoverflow.com/questions/2121874/python-pickling-after-changing-a-modules-directory/2121918#2121918
lowercase				:	Union[str, Any]      						=  data_utils.TransfoXLTokenizer
lowercase				:	Optional[int]      						=  data_utils.TransfoXLCorpus
lowercase				:	List[Any]      						=  data_utils
lowercase				:	Tuple      						=  data_utils



def A_     (		A__		,				A__		,				A__		,				A__    )  ->		Optional[Any]:
       if transfo_xl_dataset_file:
              # Convert a pre-processed corpus (see original TensorFlow repo)
              with open(A__		,				'rb'    ) as fp:
                     a__						:     int			=    pickle.load(A__		,				encoding='latin1'    )
              # Save vocabulary and dataset cache as Dictionaries (should be better than pickles for the long-term)
              a__						:     int			=    pytorch_dump_folder_path + '/' + VOCAB_FILES_NAMES['pretrained_vocab_file']
              print(F'Save vocabulary to {pytorch_vocab_dump_path}'    )
              a__						:     List[Any]			=    corpus.vocab.__dict__
              torch.save(A__		,				A__    )

              a__						:     Dict			=    corpus.__dict__
              corpus_dict_no_vocab.pop('vocab'		,				A__    )
              a__						:     Optional[int]			=    pytorch_dump_folder_path + '/' + CORPUS_NAME
              print(F'Save dataset to {pytorch_dataset_dump_path}'    )
              torch.save(A__		,				A__    )

       if tf_checkpoint_path:
              # Convert a pre-trained TensorFlow model
              a__						:     Union[str, Any]			=    os.path.abspath(A__    )
              a__						:     Optional[Any]			=    os.path.abspath(A__    )

              print(F'Converting Transformer XL checkpoint from {tf_path} with config at {config_path}.'    )
              # Initialise PyTorch model
              if transfo_xl_config_file == "":
                     a__						:     Dict			=    TransfoXLConfig()
              else:
                     a__						:     Dict			=    TransfoXLConfig.from_json_file(A__    )
              print(F'Building PyTorch model from configuration: {config}'    )
              a__						:     Optional[int]			=    TransfoXLLMHeadModel(A__    )

              a__						:     int			=    load_tf_weights_in_transfo_xl(A__		,				A__		,				A__    )
              # Save pytorch-model
              a__						:     Any			=    os.path.join(A__		,				A__    )
              a__						:     Dict			=    os.path.join(A__		,				A__    )
              print(F'Save PyTorch model to {os.path.abspath(A__    )}'    )
              torch.save(model.state_dict()		,				A__    )
              print(F'Save configuration file to {os.path.abspath(A__    )}'    )
              with open(A__		,				'w'		,				encoding='utf-8'    ) as f:
                     f.write(config.to_json_string()    )


if __name__ == "__main__":
    lowercase				:	List[Any]      						=  argparse.ArgumentParser()
    parser.add_argument(
        """--pytorch_dump_folder_path""",
        default=None,
        type=str,
        required=True,
        help="""Path to the folder to store the PyTorch model or dataset/vocab.""",
    )
    parser.add_argument(
        """--tf_checkpoint_path""",
        default="""""",
        type=str,
        help="""An optional path to a TensorFlow checkpoint path to be converted.""",
    )
    parser.add_argument(
        """--transfo_xl_config_file""",
        default="""""",
        type=str,
        help=(
            """An optional config json file corresponding to the pre-trained BERT model. \n"""
            """This specifies the model architecture."""
        ),
    )
    parser.add_argument(
        """--transfo_xl_dataset_file""",
        default="""""",
        type=str,
        help="""An optional dataset file to be converted in a vocabulary.""",
    )
    lowercase				:	Any      						=  parser.parse_args()
    convert_transfo_xl_checkpoint_to_pytorch(
        args.tf_checkpoint_path,
        args.transfo_xl_config_file,
        args.pytorch_dump_folder_path,
        args.transfo_xl_dataset_file,
    )


