
from __future__ import annotations

import unittest

from transformers import 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 numpy
		import tensorflow as tf

		from transformers import (
		    TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    BertConfig,
		    DPRConfig,
		    TFDPRContextEncoder,
		    TFDPRQuestionEncoder,
		    TFDPRReader,
		)



class    a_ :






			def __init__(      self				,			__UpperCamelCase				,			__UpperCamelCase=13				,			__UpperCamelCase=7				,			__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=512				,			__UpperCamelCase=16				,			__UpperCamelCase=2				,			__UpperCamelCase=0.02				,			__UpperCamelCase=3				,			__UpperCamelCase=4				,			__UpperCamelCase=None				,			__UpperCamelCase=0				,			):
									_lowercase					       =					parent
									_lowercase					       =					batch_size
									_lowercase					       =					seq_length
									_lowercase					       =					is_training
									_lowercase					       =					use_input_mask
									_lowercase					       =					use_token_type_ids
									_lowercase					       =					use_labels
									_lowercase					       =					vocab_size
									_lowercase					       =					hidden_size
									_lowercase					       =					num_hidden_layers
									_lowercase					       =					num_attention_heads
									_lowercase					       =					intermediate_size
									_lowercase					       =					hidden_act
									_lowercase					       =					hidden_dropout_prob
									_lowercase					       =					attention_probs_dropout_prob
									_lowercase					       =					max_position_embeddings
									_lowercase					       =					type_vocab_size
									_lowercase					       =					type_sequence_label_size
									_lowercase					       =					initializer_range
									_lowercase					       =					num_labels
									_lowercase					       =					num_choices
									_lowercase					       =					scope
									_lowercase					       =					projection_dim






			def    UpperCamelCase_				(      self  ):
									_lowercase					       =					ids_tensor([self.batch_size, self.seq_length]				,			self.vocab_size  )

									_lowercase					       =					None
									if self.use_input_mask:
															# follow test_modeling_tf_ctrl.py
															_lowercase					       =					random_attention_mask([self.batch_size, self.seq_length]  )

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

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

									_lowercase					       =					BertConfig(
									    vocab_size=self.vocab_size				,			hidden_size=self.hidden_size				,			num_hidden_layers=self.num_hidden_layers				,			num_attention_heads=self.num_attention_heads				,			intermediate_size=self.intermediate_size				,			hidden_act=self.hidden_act				,			hidden_dropout_prob=self.hidden_dropout_prob				,			attention_probs_dropout_prob=self.attention_probs_dropout_prob				,			max_position_embeddings=self.max_position_embeddings				,			type_vocab_size=self.type_vocab_size				,			is_decoder=lowerCAmelCase__				,			initializer_range=self.initializer_range				,			)
									_lowercase					       =					DPRConfig(projection_dim=self.projection_dim				,			**config.to_dict()  )

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






			def    UpperCamelCase_				(      self				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase  ):
									_lowercase					       =					TFDPRContextEncoder(config=lowerCAmelCase__  )
									_lowercase					       =					model(lowerCAmelCase__				,			attention_mask=lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__  )
									_lowercase					       =					model(lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__  )
									_lowercase					       =					model(lowerCAmelCase__  )
									self.parent.assertEqual(result.pooler_output.shape				,			(self.batch_size, self.projection_dim or self.hidden_size)  )






			def    UpperCamelCase_				(      self				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase  ):
									_lowercase					       =					TFDPRQuestionEncoder(config=lowerCAmelCase__  )
									_lowercase					       =					model(lowerCAmelCase__				,			attention_mask=lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__  )
									_lowercase					       =					model(lowerCAmelCase__				,			token_type_ids=lowerCAmelCase__  )
									_lowercase					       =					model(lowerCAmelCase__  )
									self.parent.assertEqual(result.pooler_output.shape				,			(self.batch_size, self.projection_dim or self.hidden_size)  )






			def    UpperCamelCase_				(      self				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase  ):
									_lowercase					       =					TFDPRReader(config=lowerCAmelCase__  )
									_lowercase					       =					model(lowerCAmelCase__				,			attention_mask=lowerCAmelCase__  )

									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)  )
									self.parent.assertEqual(result.relevance_logits.shape				,			(self.batch_size,)  )






			def    UpperCamelCase_				(      self  ):
									_lowercase					       =					self.prepare_config_and_inputs()
									(
									    (
									    _lowercase							
									)       ,						(
									    _lowercase							
									)       ,						(
									    _lowercase							
									)       ,						(
									    _lowercase							
									)       ,						(
									    _lowercase							
									)       ,						(
									    _lowercase							
									)       ,						(
									    _lowercase							
									)       ,													
									)					       =					config_and_inputs
									_lowercase					       =					{"""input_ids""": input_ids}
									return config, inputs_dict







@require_tf
class    a_ (			_a					,			_a					,			unittest.TestCase    ):
			a	:			str					   =							(
			    (
			        TFDPRContextEncoder,
			        TFDPRQuestionEncoder,
			        TFDPRReader,
			    )
			    if is_tf_available()
			    else ()
			)
			a	:			List[Any]					   =							{'feature-extraction': TFDPRQuestionEncoder} if is_tf_available() else {}

			a	:			Optional[int]					   =							False
			a	:			Any					   =							False
			a	:			Dict					   =							False
			a	:			Dict					   =							False
			a	:			Any					   =							False






			def    UpperCamelCase_				(      self  ):
									_lowercase					       =					TFDPRModelTester(self  )
									_lowercase					       =					ConfigTester(self				,			config_class=lowerCAmelCase__				,			hidden_size=37  )






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






			def    UpperCamelCase_				(      self  ):
									_lowercase					       =					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_dpr_context_encoder(*lowerCAmelCase__  )






			def    UpperCamelCase_				(      self  ):
									_lowercase					       =					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_dpr_question_encoder(*lowerCAmelCase__  )






			def    UpperCamelCase_				(      self  ):
									_lowercase					       =					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_dpr_reader(*lowerCAmelCase__  )






			@slow
			def    UpperCamelCase_				(      self  ):




									for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															_lowercase					       =					TFDPRContextEncoder.from_pretrained(lowerCAmelCase__  )
															self.assertIsNotNone(lowerCAmelCase__  )

									for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															_lowercase					       =					TFDPRContextEncoder.from_pretrained(lowerCAmelCase__  )
															self.assertIsNotNone(lowerCAmelCase__  )

									for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															_lowercase					       =					TFDPRQuestionEncoder.from_pretrained(lowerCAmelCase__  )
															self.assertIsNotNone(lowerCAmelCase__  )

									for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															_lowercase					       =					TFDPRReader.from_pretrained(lowerCAmelCase__  )
															self.assertIsNotNone(lowerCAmelCase__  )







@require_tf
class    a_ (			unittest.TestCase    ):






			@slow
			def    UpperCamelCase_				(      self  ):
									_lowercase					       =					TFDPRQuestionEncoder.from_pretrained("""facebook/dpr-question_encoder-single-nq-base"""  )

									_lowercase					       =					tf.constant(
									    [[101, 7_592, 1_010, 2_003, 2_026, 3_899, 10_140, 1_029, 102]]  )  # [CLS] hello, is my dog cute? [SEP]
									_lowercase					       =					model(lowerCAmelCase__  )[0]  # embedding shape = (1, 768)
									# compare the actual values for a slice.
									_lowercase					       =					tf.constant(
									    [
									        [
									            0.03_23_62_53,
									            0.12_75_33_35,
									            0.16_81_85_09,
									            0.00_27_97_86,
									            0.3_89_69_33,
									            0.24_26_49_45,
									            0.2_17_89_71,
									            -0.02_33_52_27,
									            -0.08_48_19_59,
									            -0.14_32_41_17,
									        ]
									    ]  )
									self.assertTrue(numpy.allclose(output[:, :10].numpy()				,			expected_slice.numpy()				,			atol=1E-4  )  )






'''simple docstring'''

from __future__ import annotations







def    a__							(							lowercase   :	list,   lowercase   :	int )						->						List[Any]:





     """simple docstring"""

     if len(lowercase ) <= 1 or n <= 1:
          return

     insert_next(lowercase,   n - 1 )
     rec_insertion_sort(lowercase,   n - 1 )







def    a__							(							lowercase   :	list,   lowercase   :	int )						->						Optional[Any]:





     """simple docstring"""

     if index >= len(lowercase ) or collection[index - 1] <= collection[index]:
          return

     # Swaps adjacent elements since they are not in ascending order
     _UpperCamelCase       ,							_UpperCamelCase							       =			(
         collection[index],
         collection[index - 1],
     )

     insert_next(lowercase,   index + 1 )


if __name__ == "__main__":
   lowercase__		:     str			=							input('Enter integers separated by spaces: ')
   lowercase__		:     list[int]			=							[int(num) for num in numbers.split()]
   rec_insertion_sort(number_list, len(number_list))
   print(number_list)



