


"""simple docstring"""
from __future__ import annotations

import unittest

from transformers import MPNetConfig, 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.mpnet.modeling_tf_mpnet import (
			    TFMPNetForMaskedLM,
			    TFMPNetForMultipleChoice,
			    TFMPNetForQuestionAnswering,
			    TFMPNetForSequenceClassification,
			    TFMPNetForTokenClassification,
			    TFMPNetModel,
			)



class      _UpperCAmelCase					:






		'''simple docstring'''

		def __init__(self							,			a_							,			a_=13							,			a_=7							,			a_=True							,			a_=True							,			a_=False							,			a_=True							,			a_=99							,			a_=64							,			a_=2							,			a_=4							,			a_=64							,			a_="gelu"							,			a_=0.1							,			a_=0.1							,			a_=5_12							,			a_=16							,			a_=2							,			a_=0.02							,			a_=3							,			a_=4							,			a_=None							,			):





			'''simple docstring'''

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



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

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

			__snake_case      :		List[str]         =							None
			if self.use_input_mask:
				__snake_case      :		Any         =							random_attention_mask([self.batch_size, self.seq_length]   )

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

			__snake_case      :		Dict         =							MPNetConfig(
			    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							,			initializer_range=self.initializer_range							,			)
			return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels



		def 							SCREAMING_SNAKE_CASE    (self							,			a_							,			a_							,			a_							,			a_							,			a_							,			a_   ):





			'''simple docstring'''

			__snake_case      :		Optional[int]         =							TFMPNetModel(config=a_   )
			__snake_case      :		List[str]         =							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
			__snake_case      :		List[Any]         =							model(a_   )
			__snake_case      :		Union[str, Any]         =							[input_ids, input_mask]
			__snake_case      :		str         =							model(a_   )
			self.parent.assertEqual(result.last_hidden_state.shape							,			(self.batch_size, self.seq_length, self.hidden_size)   )



		def 							SCREAMING_SNAKE_CASE    (self							,			a_							,			a_							,			a_							,			a_							,			a_							,			a_   ):





			'''simple docstring'''

			__snake_case      :		Optional[Any]         =							TFMPNetForMaskedLM(config=a_   )
			__snake_case      :		List[Any]         =							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
			__snake_case      :		int         =							model(a_   )
			self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.seq_length, self.vocab_size)   )



		def 							SCREAMING_SNAKE_CASE    (self							,			a_							,			a_							,			a_							,			a_							,			a_							,			a_   ):





			'''simple docstring'''

			__snake_case      :		List[str]         =							TFMPNetForQuestionAnswering(config=a_   )
			__snake_case      :		Optional[Any]         =							{
			    '''input_ids''': input_ids,
			    '''attention_mask''': input_mask,
			}
			__snake_case      :		Optional[int]         =							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 							SCREAMING_SNAKE_CASE    (self							,			a_							,			a_							,			a_							,			a_							,			a_							,			a_   ):





			'''simple docstring'''

			__snake_case      :		List[Any]         =							self.num_labels
			__snake_case      :		Optional[int]         =							TFMPNetForSequenceClassification(a_   )
			__snake_case      :		Dict         =							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
			__snake_case      :		Optional[Any]         =							model(a_   )
			self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.num_labels)   )



		def 							SCREAMING_SNAKE_CASE    (self							,			a_							,			a_							,			a_							,			a_							,			a_							,			a_   ):





			'''simple docstring'''

			__snake_case      :		Tuple         =							self.num_choices
			__snake_case      :		List[str]         =							TFMPNetForMultipleChoice(a_   )
			__snake_case      :		List[str]         =							tf.tile(tf.expand_dims(a_							,			1   )							,			(1, self.num_choices, 1)   )
			__snake_case      :		Tuple         =							tf.tile(tf.expand_dims(a_							,			1   )							,			(1, self.num_choices, 1)   )
			__snake_case      :		Tuple         =							{
			    '''input_ids''': multiple_choice_inputs_ids,
			    '''attention_mask''': multiple_choice_input_mask,
			}
			__snake_case      :		str         =							model(a_   )
			self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.num_choices)   )



		def 							SCREAMING_SNAKE_CASE    (self							,			a_							,			a_							,			a_							,			a_							,			a_							,			a_   ):





			'''simple docstring'''

			__snake_case      :		int         =							self.num_labels
			__snake_case      :		Tuple         =							TFMPNetForTokenClassification(a_   )
			__snake_case      :		Union[str, Any]         =							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
			__snake_case      :		Optional[Any]         =							model(a_   )
			self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.seq_length, self.num_labels)   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Union[str, Any]         =							self.prepare_config_and_inputs()
			((__snake_case)      ,				(__snake_case)      ,				(__snake_case)      ,				(__snake_case)      ,				(__snake_case)      ,				(__snake_case))      :		Tuple         =							config_and_inputs
			__snake_case      :		Optional[int]         =							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
			return config, inputs_dict



@require_tf
class      _UpperCAmelCase					(				__snake_case,							__snake_case,							unittest.TestCase							):






		'''simple docstring'''

		lowerCamelCase__           =(
		    (
		        TFMPNetForMaskedLM,
		        TFMPNetForMultipleChoice,
		        TFMPNetForQuestionAnswering,
		        TFMPNetForSequenceClassification,
		        TFMPNetForTokenClassification,
		        TFMPNetModel,
		    )
		    if is_tf_available()
		    else ()
		)
		lowerCamelCase__           =(
		    {
		        'feature-extraction': TFMPNetModel,
		        'fill-mask': TFMPNetForMaskedLM,
		        'question-answering': TFMPNetForQuestionAnswering,
		        'text-classification': TFMPNetForSequenceClassification,
		        'token-classification': TFMPNetForTokenClassification,
		        'zero-shot': TFMPNetForSequenceClassification,
		    }
		    if is_tf_available()
		    else {}
		)
		lowerCamelCase__           =False
		lowerCamelCase__           =False



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Optional[int]         =							TFMPNetModelTester(self   )
			__snake_case      :		int         =							ConfigTester(self							,			config_class=a_							,			hidden_size=37   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			self.config_tester.run_common_tests()



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Optional[int]         =							self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_mpnet_model(*a_   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Optional[int]         =							self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_mpnet_for_masked_lm(*a_   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Union[str, Any]         =							self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_mpnet_for_question_answering(*a_   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Dict         =							self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_mpnet_for_sequence_classification(*a_   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Dict         =							self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_mpnet_for_multiple_choice(*a_   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Dict         =							self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_mpnet_for_token_classification(*a_   )



		@slow
		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			for model_name in ["microsoft/mpnet-base"]:
				__snake_case      :		Tuple         =							TFMPNetModel.from_pretrained(a_   )
				self.assertIsNotNone(a_   )



@require_tf
class      _UpperCAmelCase					(				unittest.TestCase							):






		'''simple docstring'''

		@slow
		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Optional[int]         =							TFMPNetModel.from_pretrained('''microsoft/mpnet-base'''   )
			__snake_case      :		Tuple         =							tf.constant([[0, 1, 2, 3, 4, 5]]   )
			__snake_case      :		List[str]         =							model(a_   )[0]

			__snake_case      :		List[str]         =							[1, 6, 7_68]
			self.assertEqual(output.shape							,			a_   )

			__snake_case      :		Optional[int]         =							tf.constant(
			    [
			        [
			            [-0.106_7172, 0.0821_6473, 0.002_4543],
			            [-0.0346_5879, 0.835_4118, -0.0325_2288],
			            [-0.0656_9476, -0.1242_4111, -0.049_4436],
			        ]
			    ]   )
			tf.debugging.assert_near(output[:, :3, :3]							,			a_							,			atol=1E-4   )












'''simple docstring'''


from __future__ import annotations




def       A							(      _UpperCAmelCase   :				list[int]						,_UpperCAmelCase   :				int					)  ->				int:


  '''simple docstring'''




  __lowerCAmelCase     ,					__lowerCAmelCase		:    Dict			     =  0, len(_UpperCAmelCase					) - 1
  while start_ind <= end_ind:
    if array[start_ind] == search_item:
      return start_ind
    elif array[end_ind] == search_item:
      return end_ind
    else:
      start_ind += 1
      end_ind -= 1
    # returns -1 if search_item is not found in array
  return -1


if __name__ == "__main__":
    print(double_linear_search(list(range(1_00)), 40))





