

'''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__    :





  def __init__(		self      :	str							,					_a      :	List[Any]							,					_a      :	int=13							,					_a      :	int=7							,					_a      :	Optional[Any]=True							,					_a      :	Tuple=True							,					_a      :	Optional[int]=True							,					_a      :	Dict=True							,					_a      :	Optional[Any]=99							,					_a      :	Optional[Any]=[1, 1, 2]							,					_a      :	Union[str, Any]=1							,					_a      :	Optional[Any]=32							,					_a      :	Dict=4							,					_a      :	Tuple=8							,					_a      :	int=37							,					_a      :	Optional[Any]="gelu_new"							,					_a      :	str=0.1							,					_a      :	Optional[Any]=0.1							,					_a      :	Tuple=0.0							,					_a      :	Union[str, Any]=512							,					_a      :	Union[str, Any]=3							,					_a      :	Dict=0.02							,					_a      :	str=3							,					_a      :	str=4							,					_a      :	Optional[int]=None							,					_a      :	Dict=False							,					)	->    Optional[Any]:





       '''simple docstring'''






       _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 						A  (		self      :	Optional[Any] )	->    int:





       '''simple docstring'''






       _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 						A  (		self      :	Any							,					_a      :	Any							,					_a      :	Optional[int]							,					_a      :	Tuple							,					_a      :	int							,					_a      :	Optional[int]							,					_a      :	List[Any]							,					_a      :	Any							,					)	->    Any:





       '''simple docstring'''






       _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 						A  (		self      :	List[str]							,					_a      :	Tuple							,					_a      :	List[Any]							,					_a      :	Optional[int]							,					_a      :	Tuple							,					_a      :	Dict							,					_a      :	Any							,					_a      :	int							,					)	->    Dict:





       '''simple docstring'''






       _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 						A  (		self      :	Any							,					_a      :	Optional[Any]							,					_a      :	str							,					_a      :	str							,					_a      :	Optional[int]							,					_a      :	Dict							,					_a      :	Union[str, Any]							,					_a      :	str							,					)	->    Optional[int]:





       '''simple docstring'''






       _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 						A  (		self      :	Union[str, Any]							,					_a      :	Optional[Any]							,					_a      :	Optional[Any]							,					_a      :	Dict							,					_a      :	int							,					_a      :	List[str]							,					_a      :	Dict							,					_a      :	Dict							,					)	->    Optional[Any]:





       '''simple docstring'''






       _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 						A  (		self      :	str							,					_a      :	Optional[Any]							,					_a      :	str							,					_a      :	List[str]							,					_a      :	Tuple							,					_a      :	str							,					_a      :	List[str]							,					_a      :	Optional[Any]							,					)	->    Union[str, Any]:





       '''simple docstring'''






       _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 						A  (		self      :	Tuple							,					_a      :	Any							,					_a      :	Union[str, Any]							,					_a      :	List[str]							,					_a      :	Optional[int]							,					_a      :	List[Any]							,					_a      :	Optional[int]							,					_a      :	int							,					)	->    Optional[Any]:





       '''simple docstring'''






       _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 						A  (		self      :	str							,					_a      :	int							,					_a      :	List[Any]							,					_a      :	int							,					_a      :	Tuple							,					_a      :	str							,					_a      :	List[Any]							,					_a      :	Optional[Any]							,					)	->    List[Any]:





       '''simple docstring'''






       _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 						A  (		self      :	Optional[Any]							,					_a      :	Dict							,					_a      :	Union[str, Any]							,					_a      :	Tuple							,					_a      :	Optional[Any]							,					_a      :	Tuple							,					_a      :	int							,					_a      :	List[Any]							,					)	->    Tuple:





       '''simple docstring'''






       _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 						A  (		self      :	int )	->    Optional[Any]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.prepare_config_and_inputs()
       (
           (
           _SCREAMING_SNAKE_CASE
       )    ,						(
           _SCREAMING_SNAKE_CASE
       )    ,						(
           _SCREAMING_SNAKE_CASE
       )    ,						(
           _SCREAMING_SNAKE_CASE
       )    ,						(
           _SCREAMING_SNAKE_CASE
       )    ,						(
           _SCREAMING_SNAKE_CASE
       )    ,						(
           _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  ):
  A__		 =				(
      (
          TFFunnelModel,
          TFFunnelForMaskedLM,
          TFFunnelForPreTraining,
          TFFunnelForQuestionAnswering,
          TFFunnelForTokenClassification,
      )
      if is_tf_available()
      else ()
  )
  A__		 =				(
      {
          'feature-extraction': (TFFunnelBaseModel, TFFunnelModel),
          'fill-mask': TFFunnelForMaskedLM,
          'question-answering': TFFunnelForQuestionAnswering,
          'text-classification': TFFunnelForSequenceClassification,
          'token-classification': TFFunnelForTokenClassification,
          'zero-shot': TFFunnelForSequenceClassification,
      }
      if is_tf_available()
      else {}
  )
  A__		 =				False
  A__		 =				False





  def 						A  (		self      :	Dict )	->    Optional[int]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =TFFunnelModelTester(self )
       _SCREAMING_SNAKE_CASE							    =ConfigTester(self							,					config_class=_a )





  def 						A  (		self      :	Any )	->    List[Any]:





       '''simple docstring'''






       self.config_tester.run_common_tests()





  def 						A  (		self      :	Tuple )	->    str:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*_a )





  def 						A  (		self      :	str )	->    int:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_pretraining(*_a )





  def 						A  (		self      :	Optional[Any] )	->    str:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*_a )





  def 						A  (		self      :	Tuple )	->    List[Any]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*_a )





  def 						A  (		self      :	int )	->    Any:





       '''simple docstring'''






       _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  ):
  A__		 =				(
      (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
  )
  A__		 =				False
  A__		 =				False





  def 						A  (		self      :	List[Any] )	->    List[str]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =TFFunnelModelTester(self							,					base=_a )
       _SCREAMING_SNAKE_CASE							    =ConfigTester(self							,					config_class=_a )





  def 						A  (		self      :	Tuple )	->    int:





       '''simple docstring'''






       self.config_tester.run_common_tests()





  def 						A  (		self      :	Dict )	->    Dict:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_base_model(*_a )





  def 						A  (		self      :	Any )	->    Any:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*_a )





  def 						A  (		self      :	int )	->    int:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_multiple_choice(*_a )








from __future__ import annotations

from itertools import permutations
from random import randint
from timeit import repeat


def __A    (      )->  tuple[list[int], int]:





						"""simple docstring"""



						_UpperCAmelCase									=			[randint(-1_000 ,		1_000	) for i in range(10	)]
						_UpperCAmelCase									=			randint(-5_000 ,		5_000	)
						return (arr, r)


_a      	=  make_dataset()


def __A    (      __lowerCAmelCase ,		__lowerCAmelCase	)->  tuple[int, ...]:





						"""simple docstring"""



						for triplet in permutations(__lowerCAmelCase ,		3	):
												if sum(__lowerCAmelCase	) == target:
																		return tuple(sorted(__lowerCAmelCase	)	)
						return (0, 0, 0)


def __A    (      __lowerCAmelCase ,		__lowerCAmelCase	)->  tuple[int, int, int]:





						"""simple docstring"""



						arr.sort()
						_UpperCAmelCase									=			len(__lowerCAmelCase	)
						for i in range(n - 1	):
												_UpperCAmelCase					, _UpperCAmelCase									=			i + 1, n - 1
												while left < right:
																		if arr[i] + arr[left] + arr[right] == target:
																								return (arr[i], arr[left], arr[right])
																		elif arr[i] + arr[left] + arr[right] < target:
																								left += 1
																		elif arr[i] + arr[left] + arr[right] > target:
																								right -= 1
						return (0, 0, 0)


def __A    (      )->  tuple[float, float]:





						"""simple docstring"""



						_UpperCAmelCase									=			'\nfrom __main__ import dataset, triplet_sum1, triplet_sum2\n'
						_UpperCAmelCase									=			'\ntriplet_sum1(*dataset)\n'
						_UpperCAmelCase									=			'\ntriplet_sum2(*dataset)\n'
						_UpperCAmelCase									=			repeat(setup=__lowerCAmelCase ,		stmt=__lowerCAmelCase ,		repeat=5 ,		number=10_000	)
						_UpperCAmelCase									=			repeat(setup=__lowerCAmelCase ,		stmt=__lowerCAmelCase ,		repeat=5 ,		number=10_000	)
						return (min(__lowerCAmelCase	), min(__lowerCAmelCase	))


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

		testmod()
		_a      	=  solution_times()
		print(F'''The time for naive implementation is {times[0]}.''')
		print(F'''The time for optimized implementation is {times[1]}.''')
