"""simple docstring"""







import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import (
						    OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    OpenAIGPTConfig,
						    OpenAIGPTDoubleHeadsModel,
						    OpenAIGPTForSequenceClassification,
						    OpenAIGPTLMHeadModel,
						    OpenAIGPTModel,
						)



class  _lowerCamelCase			:







				def __init__( self    :       List[str]			,					lowerCamelCase_    :       str			,					lowerCamelCase_    :       Any=1_3			,					lowerCamelCase_    :       List[str]=7			,					lowerCamelCase_    :       Optional[int]=True			,					lowerCamelCase_    :       str=True			,					lowerCamelCase_    :       Dict=True			,					lowerCamelCase_    :       int=9_9			,					lowerCamelCase_    :       Dict=3_2			,					lowerCamelCase_    :       str=5			,					lowerCamelCase_    :       List[Any]=4			,					lowerCamelCase_    :       List[Any]=3_7			,					lowerCamelCase_    :       Dict="gelu"			,					lowerCamelCase_    :       List[Any]=0.1			,					lowerCamelCase_    :       str=0.1			,					lowerCamelCase_    :       Any=5_1_2			,					lowerCamelCase_    :       Union[str, Any]=1_6			,					lowerCamelCase_    :       Optional[Any]=2			,					lowerCamelCase_    :       str=0.02			,					lowerCamelCase_    :       str=3			,					lowerCamelCase_    :       Optional[int]=4			,					lowerCamelCase_    :       Optional[int]=None			,					):

					"""simple docstring"""






					_lowercase :    Dict							=							parent
					_lowercase :    List[str]							=							batch_size
					_lowercase :    str							=							seq_length
					_lowercase :    Optional[Any]							=							is_training
					_lowercase :    Dict							=							use_token_type_ids
					_lowercase :    str							=							use_labels
					_lowercase :    Tuple							=							vocab_size
					_lowercase :    int							=							hidden_size
					_lowercase :    Optional[int]							=							num_hidden_layers
					_lowercase :    Union[str, Any]							=							num_attention_heads
					_lowercase :    Any							=							intermediate_size
					_lowercase :    Optional[Any]							=							hidden_act
					_lowercase :    Tuple							=							hidden_dropout_prob
					_lowercase :    List[str]							=							attention_probs_dropout_prob
					_lowercase :    Dict							=							max_position_embeddings
					_lowercase :    Any							=							type_vocab_size
					_lowercase :    Dict							=							type_sequence_label_size
					_lowercase :    Dict							=							initializer_range
					_lowercase :    int							=							num_labels
					_lowercase :    Optional[int]							=							num_choices
					_lowercase :    Optional[Any]							=							scope
					_lowercase :    int							=							self.vocab_size - 1







				def 							__UpperCAmelCase					( self    :       int						):

					"""simple docstring"""






					_lowercase :    Optional[Any]							=							ids_tensor([self.batch_size, self.seq_length]			,					self.vocab_size						)

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

					_lowercase :    List[Any]							=							None
					_lowercase :    Optional[Any]							=							None
					_lowercase :    List[Any]							=							None
					if self.use_labels:
						_lowercase :    str							=							ids_tensor([self.batch_size]			,					self.type_sequence_label_size						)
						_lowercase :    Tuple							=							ids_tensor([self.batch_size, self.seq_length]			,					self.num_labels						)
						_lowercase :    Optional[int]							=							ids_tensor([self.batch_size]			,					self.num_choices						)

					_lowercase :    List[Any]							=							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			,					)

					_lowercase :    Dict							=							ids_tensor([self.num_hidden_layers, self.num_attention_heads]			,					2						)

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







				def 							__UpperCAmelCase					( self    :       int			,					lowerCamelCase_    :       Optional[int]			,					lowerCamelCase_    :       Any			,					lowerCamelCase_    :       List[Any]			,					lowerCamelCase_    :       Optional[int]			,					*lowerCamelCase_    :       str						):

					"""simple docstring"""






					_lowercase :    int							=							OpenAIGPTModel(config=lowerCamelCase_						)
					model.to(lowerCamelCase_						)
					model.eval()

					_lowercase :    Tuple							=							model(lowerCamelCase_			,					token_type_ids=lowerCamelCase_			,					head_mask=lowerCamelCase_						)
					_lowercase :    Union[str, Any]							=							model(lowerCamelCase_			,					token_type_ids=lowerCamelCase_						)
					_lowercase :    Optional[Any]							=							model(lowerCamelCase_						)

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







				def 							__UpperCAmelCase					( self    :       int			,					lowerCamelCase_    :       Dict			,					lowerCamelCase_    :       Union[str, Any]			,					lowerCamelCase_    :       str			,					lowerCamelCase_    :       Optional[Any]			,					*lowerCamelCase_    :       Union[str, Any]						):

					"""simple docstring"""






					_lowercase :    Union[str, Any]							=							OpenAIGPTLMHeadModel(lowerCamelCase_						)
					model.to(lowerCamelCase_						)
					model.eval()

					_lowercase :    Dict							=							model(lowerCamelCase_			,					token_type_ids=lowerCamelCase_			,					labels=lowerCamelCase_						)
					self.parent.assertEqual(result.loss.shape			,					()						)
					self.parent.assertEqual(result.logits.shape			,					(self.batch_size, self.seq_length, self.vocab_size)						)







				def 							__UpperCAmelCase					( self    :       List[str]			,					lowerCamelCase_    :       int			,					lowerCamelCase_    :       Optional[Any]			,					lowerCamelCase_    :       Any			,					lowerCamelCase_    :       Tuple			,					*lowerCamelCase_    :       List[str]						):

					"""simple docstring"""






					_lowercase :    List[Any]							=							OpenAIGPTDoubleHeadsModel(lowerCamelCase_						)
					model.to(lowerCamelCase_						)
					model.eval()

					_lowercase :    List[str]							=							model(lowerCamelCase_			,					token_type_ids=lowerCamelCase_			,					labels=lowerCamelCase_						)
					self.parent.assertEqual(result.loss.shape			,					()						)
					self.parent.assertEqual(result.logits.shape			,					(self.batch_size, self.seq_length, self.vocab_size)						)







				def 							__UpperCAmelCase					( self    :       Any			,					lowerCamelCase_    :       List[Any]			,					lowerCamelCase_    :       Optional[Any]			,					lowerCamelCase_    :       Optional[Any]			,					lowerCamelCase_    :       Optional[Any]			,					*lowerCamelCase_    :       Optional[int]						):

					"""simple docstring"""






					_lowercase :    Union[str, Any]							=							self.num_labels
					_lowercase :    List[Any]							=							OpenAIGPTForSequenceClassification(lowerCamelCase_						)
					model.to(lowerCamelCase_						)
					model.eval()

					_lowercase :    Optional[Any]							=							ids_tensor([self.batch_size]			,					self.type_sequence_label_size						)
					_lowercase :    Optional[int]							=							model(lowerCamelCase_			,					token_type_ids=lowerCamelCase_			,					labels=lowerCamelCase_						)
					self.parent.assertEqual(result.logits.shape			,					(self.batch_size, self.num_labels)						)







				def 							__UpperCAmelCase					( self    :       Optional[int]						):

					"""simple docstring"""






					_lowercase :    str							=							self.prepare_config_and_inputs()
					(
					    (
					    _lowercase
					)				,      (
					    _lowercase
					)				,      (
					    _lowercase
					)				,      (
					    _lowercase
					)				,      (
					    _lowercase
					)				,      (
					    _lowercase
					)				,      (
					    _lowercase
					)				,      
					) :    List[str]							=							config_and_inputs
					_lowercase :    Optional[int]							=							{
					    'input_ids': input_ids,
					    'token_type_ids': token_type_ids,
					    'head_mask': head_mask,
					}

					return config, inputs_dict



@require_torch
class  _lowerCamelCase			(__lowerCamelCase						,							__lowerCamelCase						,							__lowerCamelCase						,							unittest.TestCase     ):
				_snake_case     =  (
				    (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification)
				    if is_torch_available()
				    else ()
				)
				_snake_case     =  (
				    (OpenAIGPTLMHeadModel,) if is_torch_available() else ()
				)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
				_snake_case     =  (
				    {
				        "feature-extraction": OpenAIGPTModel,
				        "text-classification": OpenAIGPTForSequenceClassification,
				        "text-generation": OpenAIGPTLMHeadModel,
				        "zero-shot": OpenAIGPTForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)







				def 							__UpperCAmelCase					( self    :       List[str]			,					lowerCamelCase_    :       Union[str, Any]			,					lowerCamelCase_    :       List[str]			,					lowerCamelCase_    :       Dict			,					lowerCamelCase_    :       Tuple			,					lowerCamelCase_    :       Optional[int]						):

					"""simple docstring"""






					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 							__UpperCAmelCase					( self    :       Any			,					lowerCamelCase_    :       Tuple			,					lowerCamelCase_    :       Optional[int]			,					lowerCamelCase_    :       List[str]=False						):

					"""simple docstring"""






					_lowercase :    List[Any]							=							super()._prepare_for_class(lowerCamelCase_			,					lowerCamelCase_			,					return_labels=lowerCamelCase_						)

					if return_labels:
						if model_class.__name__ == "OpenAIGPTDoubleHeadsModel":
							_lowercase :    Optional[int]							=							torch.zeros(
							    (self.model_tester.batch_size, self.model_tester.num_choices, self.model_tester.seq_length)			,					dtype=torch.long			,					device=lowerCamelCase_			,					)
							_lowercase :    Optional[int]							=							inputs_dict['labels']
							_lowercase :    Any							=							inputs_dict['labels']
							_lowercase :    Optional[int]							=							torch.zeros(
							    (self.model_tester.batch_size, self.model_tester.num_choices)			,					dtype=torch.long			,					device=lowerCamelCase_			,					)
							_lowercase :    Union[str, Any]							=							torch.zeros(
							    self.model_tester.batch_size			,					dtype=torch.long			,					device=lowerCamelCase_						)
					return inputs_dict







				def 							__UpperCAmelCase					( self    :       Optional[int]						):

					"""simple docstring"""






					_lowercase :    str							=							OpenAIGPTModelTester(self						)
					_lowercase :    str							=							ConfigTester(self			,					config_class=lowerCamelCase_			,					n_embd=3_7						)







				def 							__UpperCAmelCase					( self    :       Dict						):

					"""simple docstring"""






					self.config_tester.run_common_tests()







				def 							__UpperCAmelCase					( self    :       Tuple						):

					"""simple docstring"""






					_lowercase :    Dict							=							self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_openai_gpt_model(*lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       Any						):

					"""simple docstring"""






					_lowercase :    Tuple							=							self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_lm_head_model(*lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       Optional[int]						):

					"""simple docstring"""






					_lowercase :    str							=							self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_double_lm_head_model(*lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       str						):

					"""simple docstring"""






					_lowercase :    str							=							self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*lowerCamelCase_						)







				@slow
				def 							__UpperCAmelCase					( self    :       List[Any]						):

					"""simple docstring"""






					for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						_lowercase :    Optional[Any]							=							OpenAIGPTModel.from_pretrained(lowerCamelCase_						)
						self.assertIsNotNone(lowerCamelCase_						)



@require_torch
class  _lowerCamelCase			(unittest.TestCase     ):







				@slow
				def 							__UpperCAmelCase					( self    :       Tuple						):

					"""simple docstring"""






					_lowercase :    int							=							OpenAIGPTLMHeadModel.from_pretrained('openai-gpt'						)
					model.to(lowerCamelCase_						)
					_lowercase :    Optional[Any]							=							torch.tensor([[4_8_1, 4_7_3_5, 5_4_4]]			,					dtype=torch.long			,					device=lowerCamelCase_						)  # the president is
					_lowercase :    Tuple							=							[
					    4_8_1,
					    4_7_3_5,
					    5_4_4,
					    2_4_6,
					    9_6_3,
					    8_7_0,
					    7_6_2,
					    2_3_9,
					    2_4_4,
					    4_0_4_7_7,
					    2_4_4,
					    2_4_9,
					    7_1_9,
					    8_8_1,
					    4_8_7,
					    5_4_4,
					    2_4_0,
					    2_4_4,
					    6_0_3,
					    4_8_1,
					]  # the president is a very good man. " \n " i\'m sure he is, " said the

					_lowercase :    Tuple							=							model.generate(lowerCamelCase_			,					do_sample=lowerCamelCase_						)
					self.assertListEqual(output_ids[0].tolist()			,					lowerCamelCase_						)




"""simple docstring"""







def      __lowerCAmelCase(		__UpperCAmelCase			):






	"""simple docstring"""





	stooge(__UpperCAmelCase     ,0     ,len(__UpperCAmelCase			) - 1			)
	return arr


def      __lowerCAmelCase(		__UpperCAmelCase     ,__UpperCAmelCase     ,__UpperCAmelCase			):






	"""simple docstring"""





	if i >= h:
		return

	# If first element is smaller than the last then swap them
	if arr[i] > arr[h]:
		_lowercase				,      _lowercase :    List[str]							=							arr[h], arr[i]

	# If there are more than 2 elements in the array
	if h - i + 1 > 2:
		_lowercase :    Optional[int]							=							(int)((h - i + 1) / 3			)

		# Recursively sort first 2/3 elements
		stooge(__UpperCAmelCase     ,__UpperCAmelCase     ,(h - t)			)

		# Recursively sort last 2/3 elements
		stooge(__UpperCAmelCase     ,i + t     ,(__UpperCAmelCase)			)

		# Recursively sort first 2/3 elements
		stooge(__UpperCAmelCase     ,__UpperCAmelCase     ,(h - t)			)


if __name__ == "__main__":
						SCREAMING_SNAKE_CASE									=						input('Enter numbers separated by a comma:\n').strip()
						SCREAMING_SNAKE_CASE									=						[int(item) for item in user_input.split(',')]
						print(stooge_sort(unsorted))



