





'''simple docstring'''

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 							__lowerCAmelCase	:






       """simple docstring"""





       def __init__(				self  :						Tuple			,					lowerCAmelCase__  :						Union[str, Any]			,					lowerCAmelCase__  :						List[Any]=13			,					lowerCAmelCase__  :						List[Any]=7			,					lowerCAmelCase__  :						Tuple=True			,					lowerCAmelCase__  :						Union[str, Any]=True			,					lowerCAmelCase__  :						Tuple=True			,					lowerCAmelCase__  :						Dict=True			,					lowerCAmelCase__  :						Optional[Any]=99			,					lowerCAmelCase__  :						Optional[Any]=32			,					lowerCAmelCase__  :						Tuple=2			,					lowerCAmelCase__  :						Union[str, Any]=4			,					lowerCAmelCase__  :						str=37			,					lowerCAmelCase__  :						Optional[int]="gelu"			,					lowerCAmelCase__  :						List[Any]=0.1			,					lowerCAmelCase__  :						str=0.1			,					lowerCAmelCase__  :						Optional[int]=512			,					lowerCAmelCase__  :						int=16			,					lowerCAmelCase__  :						List[Any]=2			,					lowerCAmelCase__  :						Optional[int]=0.02			,					lowerCAmelCase__  :						Union[str, Any]=3			,					lowerCAmelCase__  :						Optional[int]=4			,					lowerCAmelCase__  :						Dict=None			,					lowerCAmelCase__  :						Union[str, Any]=0			,					)       ->	Union[str, Any]:

            '''simple docstring'''




            _UpperCamelCase							       =			parent
            _UpperCamelCase							       =			batch_size
            _UpperCamelCase							       =			seq_length
            _UpperCamelCase							       =			is_training
            _UpperCamelCase							       =			use_input_mask
            _UpperCamelCase							       =			use_token_type_ids
            _UpperCamelCase							       =			use_labels
            _UpperCamelCase							       =			vocab_size
            _UpperCamelCase							       =			hidden_size
            _UpperCamelCase							       =			num_hidden_layers
            _UpperCamelCase							       =			num_attention_heads
            _UpperCamelCase							       =			intermediate_size
            _UpperCamelCase							       =			hidden_act
            _UpperCamelCase							       =			hidden_dropout_prob
            _UpperCamelCase							       =			attention_probs_dropout_prob
            _UpperCamelCase							       =			max_position_embeddings
            _UpperCamelCase							       =			type_vocab_size
            _UpperCamelCase							       =			type_sequence_label_size
            _UpperCamelCase							       =			initializer_range
            _UpperCamelCase							       =			num_labels
            _UpperCamelCase							       =			num_choices
            _UpperCamelCase							       =			scope
            _UpperCamelCase							       =			projection_dim





       def snake_case__		(				self  :						int	)       ->	Any:

            '''simple docstring'''




            _UpperCamelCase							       =			ids_tensor([self.batch_size, self.seq_length]			,					self.vocab_size	)

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

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

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

            _UpperCamelCase							       =			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			,					)
            _UpperCamelCase							       =			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 snake_case__		(				self  :						str			,					lowerCAmelCase__  :						List[Any]			,					lowerCAmelCase__  :						Any			,					lowerCAmelCase__  :						List[Any]			,					lowerCAmelCase__  :						int			,					lowerCAmelCase__  :						List[Any]			,					lowerCAmelCase__  :						Optional[int]			,					lowerCAmelCase__  :						Union[str, Any]	)       ->	Any:

            '''simple docstring'''




            _UpperCamelCase							       =			TFDPRContextEncoder(config=lowerCAmelCase__	)
            _UpperCamelCase							       =			model(lowerCAmelCase__			,					attention_mask=lowerCAmelCase__			,					token_type_ids=lowerCAmelCase__	)
            _UpperCamelCase							       =			model(lowerCAmelCase__			,					token_type_ids=lowerCAmelCase__	)
            _UpperCamelCase							       =			model(lowerCAmelCase__	)
            self.parent.assertEqual(result.pooler_output.shape			,					(self.batch_size, self.projection_dim or self.hidden_size)	)





       def snake_case__		(				self  :						List[Any]			,					lowerCAmelCase__  :						List[str]			,					lowerCAmelCase__  :						Optional[int]			,					lowerCAmelCase__  :						str			,					lowerCAmelCase__  :						Optional[int]			,					lowerCAmelCase__  :						List[str]			,					lowerCAmelCase__  :						Optional[Any]			,					lowerCAmelCase__  :						List[Any]	)       ->	Optional[Any]:

            '''simple docstring'''




            _UpperCamelCase							       =			TFDPRQuestionEncoder(config=lowerCAmelCase__	)
            _UpperCamelCase							       =			model(lowerCAmelCase__			,					attention_mask=lowerCAmelCase__			,					token_type_ids=lowerCAmelCase__	)
            _UpperCamelCase							       =			model(lowerCAmelCase__			,					token_type_ids=lowerCAmelCase__	)
            _UpperCamelCase							       =			model(lowerCAmelCase__	)
            self.parent.assertEqual(result.pooler_output.shape			,					(self.batch_size, self.projection_dim or self.hidden_size)	)





       def snake_case__		(				self  :						Dict			,					lowerCAmelCase__  :						str			,					lowerCAmelCase__  :						Any			,					lowerCAmelCase__  :						int			,					lowerCAmelCase__  :						Any			,					lowerCAmelCase__  :						Tuple			,					lowerCAmelCase__  :						Union[str, Any]			,					lowerCAmelCase__  :						Union[str, Any]	)       ->	Union[str, Any]:

            '''simple docstring'''




            _UpperCamelCase							       =			TFDPRReader(config=lowerCAmelCase__	)
            _UpperCamelCase							       =			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 snake_case__		(				self  :						List[str]	)       ->	Union[str, Any]:

            '''simple docstring'''




            _UpperCamelCase							       =			self.prepare_config_and_inputs()
            (
                (
                _UpperCamelCase
            )       ,							(
                _UpperCamelCase
            )       ,							(
                _UpperCamelCase
            )       ,							(
                _UpperCamelCase
            )       ,							(
                _UpperCamelCase
            )       ,							(
                _UpperCamelCase
            )       ,							(
                _UpperCamelCase
            )       ,							
            )							       =			config_and_inputs
            _UpperCamelCase							       =			{'''input_ids''': input_ids}
            return config, inputs_dict

@require_tf
class 							__lowerCAmelCase	(       __magic_name__		,		__magic_name__		,		unittest.TestCase					):






       """simple docstring"""
       _snake_case      :	str									=       (
           (
               TFDPRContextEncoder,
               TFDPRQuestionEncoder,
               TFDPRReader,
           )
           if is_tf_available()
           else ()
       )
       _snake_case      :	List[Any]									=       {'feature-extraction': TFDPRQuestionEncoder} if is_tf_available() else {}

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





       def snake_case__		(				self  :						Dict	)       ->	Dict:

            '''simple docstring'''




            _UpperCamelCase							       =			TFDPRModelTester(self	)
            _UpperCamelCase							       =			ConfigTester(self			,					config_class=lowerCAmelCase__			,					hidden_size=37	)





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

            '''simple docstring'''




            self.config_tester.run_common_tests()





       def snake_case__		(				self  :						Optional[int]	)       ->	Tuple:

            '''simple docstring'''




            _UpperCamelCase							       =			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_dpr_context_encoder(*lowerCAmelCase__	)





       def snake_case__		(				self  :						int	)       ->	List[str]:

            '''simple docstring'''




            _UpperCamelCase							       =			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_dpr_question_encoder(*lowerCAmelCase__	)





       def snake_case__		(				self  :						Union[str, Any]	)       ->	Optional[Any]:

            '''simple docstring'''




            _UpperCamelCase							       =			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_dpr_reader(*lowerCAmelCase__	)







       @slow
       def snake_case__		(				self  :						List[str]	)       ->	Any:

            '''simple docstring'''




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

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

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

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

@require_tf
class 							__lowerCAmelCase	(       unittest.TestCase					):






       """simple docstring"""





       @slow
       def snake_case__		(				self  :						Tuple	)       ->	str:

            '''simple docstring'''




            _UpperCamelCase							       =			TFDPRQuestionEncoder.from_pretrained('''facebook/dpr-question_encoder-single-nq-base'''	)

            _UpperCamelCase							       =			tf.constant(
                [[101, 7592, 1010, 2003, 2026, 3899, 10140, 1029, 102]]	)  # [CLS] hello, is my dog cute? [SEP]
            _UpperCamelCase							       =			model(lowerCAmelCase__	)[0]  # embedding shape = (1, 768)
            # compare the actual values for a slice.
            _UpperCamelCase							       =			tf.constant(
                [
                    [
                        0.03236253,
                        0.12753335,
                        0.16818509,
                        0.00279786,
                        0.3896933,
                        0.24264945,
                        0.2178971,
                        -0.02335227,
                        -0.08481959,
                        -0.14324117,
                    ]
                ]	)
            self.assertTrue(numpy.allclose(output[:, :10].numpy()			,					expected_slice.numpy()			,					atol=1e-4	)	)








'''simple docstring'''





def 		__snake_case(							)						->					Optional[Any]:
      for n in range(1	,  1_000_000						):
            yield n * (n + 1) // 2





def 		__snake_case(							_lowerCAmelCase						)						->					str:
      snake_case__    :       Optional[int]       		= 1
      snake_case__    :       List[Any]       		= 2
      while i * i <= n:
            snake_case__    :       Dict       		= 0
            while n % i == 0:
                  n //= i
                  multiplicity += 1
            divisors_count *= multiplicity + 1
            i += 1
      if n > 1:
            divisors_count *= 2
      return divisors_count





def 		__snake_case(							)						->					List[str]:
      return next(i for i in triangle_number_generator() if count_divisors(_lowerCAmelCase						) > 500						)


if __name__ == "__main__":
       print(solution())
