





'''simple docstring'''

from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

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 import (
          TFFunnelBaseModel,
          TFFunnelForMaskedLM,
          TFFunnelForMultipleChoice,
          TFFunnelForPreTraining,
          TFFunnelForQuestionAnswering,
          TFFunnelForSequenceClassification,
          TFFunnelForTokenClassification,
          TFFunnelModel,
      )


class 					a_     :

    '''simple docstring'''


    def __init__(		self ,		A ,		A=13 ,		A=7 ,		A=True ,		A=True ,		A=True ,		A=True ,		A=99 ,		A=[1, 1, 2] ,		A=1 ,		A=32 ,		A=4 ,		A=8 ,		A=37 ,		A="gelu_new" ,		A=0.1 ,		A=0.1 ,		A=0.0 ,		A=512 ,		A=3 ,		A=0.02 ,		A=3 ,		A=4 ,		A=None ,		A=False ,		)		->   Dict:
        _SCREAMING_SNAKE_CASE									=			parent
        _SCREAMING_SNAKE_CASE									=			batch_size
        _SCREAMING_SNAKE_CASE									=			seq_length
        _SCREAMING_SNAKE_CASE									=			is_training
        _SCREAMING_SNAKE_CASE									=			use_input_mask
        _SCREAMING_SNAKE_CASE									=			use_token_type_ids
        _SCREAMING_SNAKE_CASE									=			use_labels
        _SCREAMING_SNAKE_CASE									=			vocab_size
        _SCREAMING_SNAKE_CASE									=			block_sizes
        _SCREAMING_SNAKE_CASE									=			num_decoder_layers
        _SCREAMING_SNAKE_CASE									=			d_model
        _SCREAMING_SNAKE_CASE									=			n_head
        _SCREAMING_SNAKE_CASE									=			d_head
        _SCREAMING_SNAKE_CASE									=			d_inner
        _SCREAMING_SNAKE_CASE									=			hidden_act
        _SCREAMING_SNAKE_CASE									=			hidden_dropout
        _SCREAMING_SNAKE_CASE									=			attention_dropout
        _SCREAMING_SNAKE_CASE									=			activation_dropout
        _SCREAMING_SNAKE_CASE									=			max_position_embeddings
        _SCREAMING_SNAKE_CASE									=			type_vocab_size
        _SCREAMING_SNAKE_CASE									=			2
        _SCREAMING_SNAKE_CASE									=			num_labels
        _SCREAMING_SNAKE_CASE									=			num_choices
        _SCREAMING_SNAKE_CASE									=			scope
        _SCREAMING_SNAKE_CASE									=			initializer_std

        # Used in the tests to check the size of the first attention layer
        _SCREAMING_SNAKE_CASE									=			n_head
        # Used in the tests to check the size of the first hidden state
        _SCREAMING_SNAKE_CASE									=			self.d_model
        # Used in the tests to check the number of output hidden states/attentions
        _SCREAMING_SNAKE_CASE									=			sum(self.block_sizes       ) + (0 if base else self.num_decoder_layers)
        # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
        # the last hidden state of the first block (which is the first hidden state of the decoder).
        if not base:
            _SCREAMING_SNAKE_CASE									=			self.num_hidden_layers + 2


    def 			snake_case_(		self       )		->   int:
        _SCREAMING_SNAKE_CASE									=			ids_tensor([self.batch_size, self.seq_length] ,		self.vocab_size       )

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

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

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

        _SCREAMING_SNAKE_CASE									=			FunnelConfig(
            vocab_size=self.vocab_size ,		block_sizes=self.block_sizes ,		num_decoder_layers=self.num_decoder_layers ,		d_model=self.d_model ,		n_head=self.n_head ,		d_head=self.d_head ,		d_inner=self.d_inner ,		hidden_act=self.hidden_act ,		hidden_dropout=self.hidden_dropout ,		attention_dropout=self.attention_dropout ,		activation_dropout=self.activation_dropout ,		max_position_embeddings=self.max_position_embeddings ,		type_vocab_size=self.type_vocab_size ,		initializer_std=self.initializer_std ,		)

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


    def 			snake_case_(		self ,		A ,		A ,		A ,		A ,		A ,		A ,		A ,		)		->   Optional[Any]:
        _SCREAMING_SNAKE_CASE									=			TFFunnelModel(config=_A       )
        _SCREAMING_SNAKE_CASE									=			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
        _SCREAMING_SNAKE_CASE									=			model(_A       )

        _SCREAMING_SNAKE_CASE									=			[input_ids, input_mask]
        _SCREAMING_SNAKE_CASE									=			model(_A       )

        _SCREAMING_SNAKE_CASE									=			model(_A       )
        self.parent.assertEqual(result.last_hidden_state.shape ,		(self.batch_size, self.seq_length, self.d_model)       )

        _SCREAMING_SNAKE_CASE									=			False
        _SCREAMING_SNAKE_CASE									=			TFFunnelModel(config=_A       )
        _SCREAMING_SNAKE_CASE									=			model(_A       )
        self.parent.assertEqual(result.last_hidden_state.shape ,		(self.batch_size, self.seq_length, self.d_model)       )

        _SCREAMING_SNAKE_CASE									=			False
        _SCREAMING_SNAKE_CASE									=			TFFunnelModel(config=_A       )
        _SCREAMING_SNAKE_CASE									=			model(_A       )
        self.parent.assertEqual(result.last_hidden_state.shape ,		(self.batch_size, self.seq_length, self.d_model)       )


    def 			snake_case_(		self ,		A ,		A ,		A ,		A ,		A ,		A ,		A ,		)		->   Optional[Any]:
        _SCREAMING_SNAKE_CASE									=			TFFunnelBaseModel(config=_A       )
        _SCREAMING_SNAKE_CASE									=			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
        _SCREAMING_SNAKE_CASE									=			model(_A       )

        _SCREAMING_SNAKE_CASE									=			[input_ids, input_mask]
        _SCREAMING_SNAKE_CASE									=			model(_A       )

        _SCREAMING_SNAKE_CASE									=			model(_A       )
        self.parent.assertEqual(result.last_hidden_state.shape ,		(self.batch_size, 2, self.d_model)       )

        _SCREAMING_SNAKE_CASE									=			False
        _SCREAMING_SNAKE_CASE									=			TFFunnelBaseModel(config=_A       )
        _SCREAMING_SNAKE_CASE									=			model(_A       )
        self.parent.assertEqual(result.last_hidden_state.shape ,		(self.batch_size, 3, self.d_model)       )

        _SCREAMING_SNAKE_CASE									=			False
        _SCREAMING_SNAKE_CASE									=			TFFunnelBaseModel(config=_A       )
        _SCREAMING_SNAKE_CASE									=			model(_A       )
        self.parent.assertEqual(result.last_hidden_state.shape ,		(self.batch_size, 2, self.d_model)       )


    def 			snake_case_(		self ,		A ,		A ,		A ,		A ,		A ,		A ,		A ,		)		->   List[Any]:
        _SCREAMING_SNAKE_CASE									=			TFFunnelForPreTraining(config=_A       )
        _SCREAMING_SNAKE_CASE									=			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
        _SCREAMING_SNAKE_CASE									=			model(_A       )
        self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.seq_length)       )


    def 			snake_case_(		self ,		A ,		A ,		A ,		A ,		A ,		A ,		A ,		)		->   List[str]:
        _SCREAMING_SNAKE_CASE									=			TFFunnelForMaskedLM(config=_A       )
        _SCREAMING_SNAKE_CASE									=			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
        _SCREAMING_SNAKE_CASE									=			model(_A       )
        self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.seq_length, self.vocab_size)       )


    def 			snake_case_(		self ,		A ,		A ,		A ,		A ,		A ,		A ,		A ,		)		->   Dict:
        _SCREAMING_SNAKE_CASE									=			self.num_labels
        _SCREAMING_SNAKE_CASE									=			TFFunnelForSequenceClassification(config=_A       )
        _SCREAMING_SNAKE_CASE									=			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
        _SCREAMING_SNAKE_CASE									=			model(_A       )
        self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.num_labels)       )


    def 			snake_case_(		self ,		A ,		A ,		A ,		A ,		A ,		A ,		A ,		)		->   Optional[Any]:
        _SCREAMING_SNAKE_CASE									=			self.num_choices
        _SCREAMING_SNAKE_CASE									=			TFFunnelForMultipleChoice(config=_A       )
        _SCREAMING_SNAKE_CASE									=			tf.tile(tf.expand_dims(_A ,		1       ) ,		(1, self.num_choices, 1)       )
        _SCREAMING_SNAKE_CASE									=			tf.tile(tf.expand_dims(_A ,		1       ) ,		(1, self.num_choices, 1)       )
        _SCREAMING_SNAKE_CASE									=			tf.tile(tf.expand_dims(_A ,		1       ) ,		(1, self.num_choices, 1)       )
        _SCREAMING_SNAKE_CASE									=			{
            "input_ids": multiple_choice_inputs_ids,
            "attention_mask": multiple_choice_input_mask,
            "token_type_ids": multiple_choice_token_type_ids,
        }
        _SCREAMING_SNAKE_CASE									=			model(_A       )
        self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.num_choices)       )


    def 			snake_case_(		self ,		A ,		A ,		A ,		A ,		A ,		A ,		A ,		)		->   Union[str, Any]:
        _SCREAMING_SNAKE_CASE									=			self.num_labels
        _SCREAMING_SNAKE_CASE									=			TFFunnelForTokenClassification(config=_A       )
        _SCREAMING_SNAKE_CASE									=			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
        _SCREAMING_SNAKE_CASE									=			model(_A       )
        self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.seq_length, self.num_labels)       )


    def 			snake_case_(		self ,		A ,		A ,		A ,		A ,		A ,		A ,		A ,		)		->   List[Any]:
        _SCREAMING_SNAKE_CASE									=			TFFunnelForQuestionAnswering(config=_A       )
        _SCREAMING_SNAKE_CASE									=			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
        _SCREAMING_SNAKE_CASE									=			model(_A       )
        self.parent.assertEqual(result.start_logits.shape ,		(self.batch_size, self.seq_length)       )
        self.parent.assertEqual(result.end_logits.shape ,		(self.batch_size, self.seq_length)       )





    def 			snake_case_(		self       )		->   Any:
        _SCREAMING_SNAKE_CASE									=			self.prepare_config_and_inputs()
        (
            _SCREAMING_SNAKE_CASE    
        )									=			config_and_inputs
        _SCREAMING_SNAKE_CASE									=			{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
        return config, inputs_dict




@require_tf
class 					a_     (				A__      ,    A__      ,    unittest.TestCase       ):

    '''simple docstring'''
    UpperCamelCase     = (
        (
            TFFunnelModel,
            TFFunnelForMaskedLM,
            TFFunnelForPreTraining,
            TFFunnelForQuestionAnswering,
            TFFunnelForTokenClassification,
        )
        if is_tf_available()
        else ()
    )
    UpperCamelCase     = (
        {
            '''feature-extraction''': (TFFunnelBaseModel, TFFunnelModel),
            '''fill-mask''': TFFunnelForMaskedLM,
            '''question-answering''': TFFunnelForQuestionAnswering,
            '''text-classification''': TFFunnelForSequenceClassification,
            '''token-classification''': TFFunnelForTokenClassification,
            '''zero-shot''': TFFunnelForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )
    UpperCamelCase     = False
    UpperCamelCase     = False


    def 			snake_case_(		self       )		->   str:
        _SCREAMING_SNAKE_CASE									=			TFFunnelModelTester(self       )
        _SCREAMING_SNAKE_CASE									=			ConfigTester(self ,		config_class=_A       )


    def 			snake_case_(		self       )		->   List[str]:
        self.config_tester.run_common_tests()


    def 			snake_case_(		self       )		->   Union[str, Any]:
        _SCREAMING_SNAKE_CASE									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*_A       )


    def 			snake_case_(		self       )		->   List[Any]:
        _SCREAMING_SNAKE_CASE									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_pretraining(*_A       )


    def 			snake_case_(		self       )		->   Tuple:
        _SCREAMING_SNAKE_CASE									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*_A       )


    def 			snake_case_(		self       )		->   List[str]:
        _SCREAMING_SNAKE_CASE									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*_A       )





    def 			snake_case_(		self       )		->   Tuple:
        _SCREAMING_SNAKE_CASE									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*_A       )




@require_tf
class 					a_     (				A__      ,    unittest.TestCase       ):

    '''simple docstring'''
    UpperCamelCase     = (
        (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
    )
    UpperCamelCase     = False
    UpperCamelCase     = False


    def 			snake_case_(		self       )		->   int:
        _SCREAMING_SNAKE_CASE									=			TFFunnelModelTester(self ,		base=_A       )
        _SCREAMING_SNAKE_CASE									=			ConfigTester(self ,		config_class=_A       )


    def 			snake_case_(		self       )		->   List[Any]:
        self.config_tester.run_common_tests()


    def 			snake_case_(		self       )		->   Union[str, Any]:
        _SCREAMING_SNAKE_CASE									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_base_model(*_A       )


    def 			snake_case_(		self       )		->   List[Any]:
        _SCREAMING_SNAKE_CASE									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*_A       )





    def 			snake_case_(		self       )		->   List[Any]:
        _SCREAMING_SNAKE_CASE									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*_A       )




def       _snake_case	(   lowerCAmelCase							:   list	):
		"""simple docstring"""







		SCREAMING_SNAKE_CASE_  :		Dict				      =    len(lowerCAmelCase	)
		for i in range(1   , lowerCAmelCase	):
				SCREAMING_SNAKE_CASE_  :		int				      =    collection[i]
				SCREAMING_SNAKE_CASE_  :		Any				      =    0
				SCREAMING_SNAKE_CASE_  :		Tuple				      =    i - 1

				while low <= high:
						SCREAMING_SNAKE_CASE_  :		int				      =    (low + high) // 2
						if val < collection[mid]:
								SCREAMING_SNAKE_CASE_  :		Optional[Any]				      =    mid - 1
						else:
								SCREAMING_SNAKE_CASE_  :		Tuple				      =    mid + 1
				for j in range(lowerCAmelCase   , lowerCAmelCase   , -1	):
						SCREAMING_SNAKE_CASE_  :		Union[str, Any]				      =    collection[j - 1]
				SCREAMING_SNAKE_CASE_  :		int				      =    val
		return collection


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