





"""simple docstring"""






from __future__ import annotations

import unittest

from transformers import OpenAIGPTConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
    import tensorflow as tf

    from transformers.models.openai.modeling_tf_openai import (
        TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFOpenAIGPTDoubleHeadsModel,
        TFOpenAIGPTForSequenceClassification,
        TFOpenAIGPTLMHeadModel,
        TFOpenAIGPTModel,
    )



class 						lowerCAmelCase       :






       def __init__( self     ,	a__     ,	):
              _UpperCAmelCase			     =  parent
              _UpperCAmelCase			     =  13
              _UpperCAmelCase			     =  7
              _UpperCAmelCase			     =  True
              _UpperCAmelCase			     =  True
              _UpperCAmelCase			     =  True
              _UpperCAmelCase			     =  True
              _UpperCAmelCase			     =  True
              _UpperCAmelCase			     =  99
              _UpperCAmelCase			     =  32
              _UpperCAmelCase			     =  2
              _UpperCAmelCase			     =  4
              _UpperCAmelCase			     =  37
              _UpperCAmelCase			     =  'gelu'
              _UpperCAmelCase			     =  0.1
              _UpperCAmelCase			     =  0.1
              _UpperCAmelCase			     =  5_12
              _UpperCAmelCase			     =  16
              _UpperCAmelCase			     =  2
              _UpperCAmelCase			     =  0.02
              _UpperCAmelCase			     =  3
              _UpperCAmelCase			     =  4
              _UpperCAmelCase			     =  None
              _UpperCAmelCase			     =  self.vocab_size - 1






       def 				__A			( self  ):
              _UpperCAmelCase			     =  ids_tensor([self.batch_size, self.seq_length]     ,	self.vocab_size  )

              _UpperCAmelCase			     =  None
              if self.use_input_mask:
                     _UpperCAmelCase			     =  random_attention_mask([self.batch_size, self.seq_length]  )

              _UpperCAmelCase			     =  None
              if self.use_token_type_ids:
                     _UpperCAmelCase			     =  ids_tensor([self.batch_size, self.seq_length]     ,	self.type_vocab_size  )

              _UpperCAmelCase			     =  None
              if self.use_mc_token_ids:
                     _UpperCAmelCase			     =  ids_tensor([self.batch_size, self.num_choices]     ,	self.seq_length  )

              _UpperCAmelCase			     =  None
              _UpperCAmelCase			     =  None
              _UpperCAmelCase			     =  None
              if self.use_labels:
                     _UpperCAmelCase			     =  ids_tensor([self.batch_size]     ,	self.type_sequence_label_size  )
                     _UpperCAmelCase			     =  ids_tensor([self.batch_size, self.seq_length]     ,	self.num_labels  )
                     _UpperCAmelCase			     =  ids_tensor([self.batch_size]     ,	self.num_choices  )

              _UpperCAmelCase			     =  OpenAIGPTConfig(
                  vocab_size=self.vocab_size     ,	n_embd=self.hidden_size     ,	n_layer=self.num_hidden_layers     ,	n_head=self.num_attention_heads     ,	n_positions=self.max_position_embeddings     ,	pad_token_id=self.pad_token_id     ,	)

              _UpperCAmelCase			     =  ids_tensor([self.num_hidden_layers, self.num_attention_heads]     ,	2  )

              return (
                  config,
                  input_ids,
                  input_mask,
                  head_mask,
                  token_type_ids,
                  mc_token_ids,
                  sequence_labels,
                  token_labels,
                  choice_labels,
              )






       def 				__A			( self     ,	a__     ,	a__     ,	a__     ,	a__     ,	a__     ,	*a__  ):
              _UpperCAmelCase			     =  TFOpenAIGPTModel(config=a__  )
              _UpperCAmelCase			     =  {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
              _UpperCAmelCase			     =  model(a__  )

              _UpperCAmelCase			     =  [input_ids, input_mask]
              _UpperCAmelCase			     =  model(a__  )

              _UpperCAmelCase			     =  model(a__  )

              self.parent.assertEqual(result.last_hidden_state.shape     ,	(self.batch_size, self.seq_length, self.hidden_size)  )






       def 				__A			( self     ,	a__     ,	a__     ,	a__     ,	a__     ,	a__     ,	*a__  ):
              _UpperCAmelCase			     =  TFOpenAIGPTLMHeadModel(config=a__  )
              _UpperCAmelCase			     =  {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
              _UpperCAmelCase			     =  model(a__  )
              self.parent.assertEqual(result.logits.shape     ,	(self.batch_size, self.seq_length, self.vocab_size)  )






       def 				__A			( self     ,	a__     ,	a__     ,	a__     ,	a__     ,	a__     ,	a__     ,	*a__  ):
              _UpperCAmelCase			     =  TFOpenAIGPTDoubleHeadsModel(config=a__  )

              _UpperCAmelCase			     =  tf.tile(tf.expand_dims(a__     ,	1  )     ,	(1, self.num_choices, 1)  )
              _UpperCAmelCase			     =  tf.tile(tf.expand_dims(a__     ,	1  )     ,	(1, self.num_choices, 1)  )
              _UpperCAmelCase			     =  tf.tile(tf.expand_dims(a__     ,	1  )     ,	(1, self.num_choices, 1)  )

              _UpperCAmelCase			     =  {
                  'input_ids': multiple_choice_inputs_ids,
                  'mc_token_ids': mc_token_ids,
                  'attention_mask': multiple_choice_input_mask,
                  'token_type_ids': multiple_choice_token_type_ids,
              }
              _UpperCAmelCase			     =  model(a__  )
              self.parent.assertEqual(
                  result.logits.shape     ,	(self.batch_size, self.num_choices, self.seq_length, self.vocab_size)  )
              self.parent.assertEqual(result.mc_logits.shape     ,	(self.batch_size, self.num_choices)  )






       def 				__A			( self     ,	a__     ,	a__     ,	a__     ,	a__     ,	a__     ,	*a__  ):
              _UpperCAmelCase			     =  self.num_labels
              _UpperCAmelCase			     =  ids_tensor([self.batch_size]     ,	self.type_sequence_label_size  )
              _UpperCAmelCase			     =  {
                  'input_ids': input_ids,
                  'attention_mask': input_mask,
                  'token_type_ids': token_type_ids,
                  'labels': sequence_labels,
              }
              _UpperCAmelCase			     =  TFOpenAIGPTForSequenceClassification(a__  )
              _UpperCAmelCase			     =  model(a__  )
              self.parent.assertEqual(result.logits.shape     ,	(self.batch_size, self.num_labels)  )






       def 				__A			( self  ):
              _UpperCAmelCase			     =  self.prepare_config_and_inputs()

              (
                  (
                  _UpperCAmelCase
              )     ,				(
                  _UpperCAmelCase
              )     ,				(
                  _UpperCAmelCase
              )     ,				(
                  _UpperCAmelCase
              )     ,				(
                  _UpperCAmelCase
              )     ,				(
                  _UpperCAmelCase
              )     ,				(
                  _UpperCAmelCase
              )     ,				(
                  _UpperCAmelCase
              )     ,				(
                  _UpperCAmelCase
              )     ,				
              )			     =  config_and_inputs

              _UpperCAmelCase			     =  {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
              return config, inputs_dict



@require_tf
class 						lowerCAmelCase       (   snake_case      ,						snake_case      ,						unittest.TestCase				):
       lowerCAmelCase__    			=	(
           (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
           if is_tf_available()
           else ()
       )
       lowerCAmelCase__    			=	(
           (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
       )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
       lowerCAmelCase__    			=	(
           {
               """feature-extraction""": TFOpenAIGPTModel,
               """text-classification""": TFOpenAIGPTForSequenceClassification,
               """text-generation""": TFOpenAIGPTLMHeadModel,
               """zero-shot""": TFOpenAIGPTForSequenceClassification,
           }
           if is_tf_available()
           else {}
       )
       lowerCAmelCase__    			=	False
       lowerCAmelCase__    			=	False






       def 				__A			( self     ,	a__     ,	a__     ,	a__     ,	a__     ,	a__  ):
              if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
                     # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
                     # `OpenAIGPTConfig` was never used in pipeline tests, either because of a missing checkpoint or because a
                     # tiny config could not be created.
                     return True

              return False






       def 				__A			( self  ):
              _UpperCAmelCase			     =  TFOpenAIGPTModelTester(self  )
              _UpperCAmelCase			     =  ConfigTester(self     ,	config_class=a__     ,	n_embd=37  )






       def 				__A			( self  ):
              self.config_tester.run_common_tests()






       def 				__A			( self  ):
              _UpperCAmelCase			     =  self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_openai_gpt_model(*a__  )






       def 				__A			( self  ):
              _UpperCAmelCase			     =  self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_openai_gpt_lm_head(*a__  )






       def 				__A			( self  ):
              _UpperCAmelCase			     =  self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_openai_gpt_double_head(*a__  )






       def 				__A			( self  ):
              _UpperCAmelCase			     =  self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*a__  )






       @slow
       def 				__A			( self  ):
              for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                     _UpperCAmelCase			     =  TFOpenAIGPTModel.from_pretrained(a__  )
                     self.assertIsNotNone(a__  )



@require_tf
class 						lowerCAmelCase       (   unittest.TestCase				):






       @slow
       def 				__A			( self  ):
              _UpperCAmelCase			     =  TFOpenAIGPTLMHeadModel.from_pretrained('openai-gpt'  )
              _UpperCAmelCase			     =  tf.convert_to_tensor([[4_81, 47_35, 5_44]]     ,	dtype=tf.intaa  )  # the president is
              _UpperCAmelCase			     =  [
                  4_81,
                  47_35,
                  5_44,
                  2_46,
                  9_63,
                  8_70,
                  7_62,
                  2_39,
                  2_44,
                  4_04_77,
                  2_44,
                  2_49,
                  7_19,
                  8_81,
                  4_87,
                  5_44,
                  2_40,
                  2_44,
                  6_03,
                  4_81,
              ]  # the president is a very good man. " \n " i\'m sure he is, " said the

              _UpperCAmelCase			     =  model.generate(a__     ,	do_sample=a__  )
              self.assertListEqual(output_ids[0].numpy().tolist()     ,	a__  )













"""simple docstring"""






def    __lowerCamelCase     (							SCREAMING_SNAKE_CASE				)		->							Dict:






       """simple docstring"""




       _UpperCAmelCase			     =  [701, 301, 132, 57, 23, 10, 4, 1]
       for gap in gaps:
              for i in range(SCREAMING_SNAKE_CASE,len(SCREAMING_SNAKE_CASE				)				):
                     _UpperCAmelCase			     =  collection[i]
                     _UpperCAmelCase			     =  i
                     while j >= gap and collection[j - gap] > insert_value:
                            _UpperCAmelCase			     =  collection[j - gap]
                            j -= gap
                     if j != i:
                            _UpperCAmelCase			     =  insert_value
       return collection


if __name__ == "__main__":
    from doctest import testmod

    testmod()
    lowerCAmelCase_      =				input('''Enter numbers separated by a comma:\n''').strip()
    lowerCAmelCase_      =				[int(item) for item in user_input.split(''',''')]
    print(shell_sort(unsorted))






