






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  ,		A  ,		A=13  ,		A=7  ,		A=True  ,		A=True  ,		A=True  ,		A=True  ,		A=99  ,		A=32  ,		A=2  ,		A=4  ,		A=37  ,		A="gelu"  ,		A=0.1  ,		A=0.1  ,		A=512  ,		A=16  ,		A=2  ,		A=0.0_2  ,		A=3  ,		A=4  ,		A=None  ,		A=0  ,		)  ->   List[Any]:



          '''simple docstring'''



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







     def       lowerCAmelCase_    (     self			)  ->   Optional[Any]:



          '''simple docstring'''



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

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

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

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

          a     =				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  ,		)
          a     =				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       lowerCAmelCase_    (     self  ,		A  ,		A  ,		A  ,		A  ,		A  ,		A  ,		A			)  ->   Tuple:



          '''simple docstring'''



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







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



          '''simple docstring'''



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







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



          '''simple docstring'''



          a     =				TFDPRReader(config=__lowerCamelCase			)
          a     =				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       lowerCAmelCase_    (     self			)  ->   Any:



          '''simple docstring'''



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







@require_tf
class       a__	( UpperCamelCase__       , UpperCamelCase__       , unittest.TestCase				):
     a		:      Dict		 =     (
         (
             TFDPRContextEncoder,
             TFDPRQuestionEncoder,
             TFDPRReader,
         )
         if is_tf_available()
         else ()
     )
     a		:      Dict		 =     {"""feature-extraction""": TFDPRQuestionEncoder} if is_tf_available() else {}

     a		:      Union[str, Any]		 =     False
     a		:      Optional[int]		 =     False
     a		:      str		 =     False
     a		:      Union[str, Any]		 =     False
     a		:      List[str]		 =     False







     def       lowerCAmelCase_    (     self			)  ->   Optional[Any]:



          '''simple docstring'''



          a     =				TFDPRModelTester(self			)
          a     =				ConfigTester(self  ,		config_class=__lowerCamelCase  ,		hidden_size=37			)







     def       lowerCAmelCase_    (     self			)  ->   Tuple:



          '''simple docstring'''



          self.config_tester.run_common_tests()







     def       lowerCAmelCase_    (     self			)  ->   Optional[int]:



          '''simple docstring'''



          a     =				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_dpr_context_encoder(*__lowerCamelCase			)







     def       lowerCAmelCase_    (     self			)  ->   Tuple:



          '''simple docstring'''



          a     =				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_dpr_question_encoder(*__lowerCamelCase			)







     def       lowerCAmelCase_    (     self			)  ->   List[str]:



          '''simple docstring'''



          a     =				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_dpr_reader(*__lowerCamelCase			)







     @slow
     def       lowerCAmelCase_    (     self			)  ->   Optional[int]:



          '''simple docstring'''



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

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

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

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







@require_tf
class       a__	( unittest.TestCase				):







     @slow
     def       lowerCAmelCase_    (     self			)  ->   Optional[int]:



          '''simple docstring'''



          a     =				TFDPRQuestionEncoder.from_pretrained("facebook/dpr-question_encoder-single-nq-base"			)

          a     =				tf.constant(
              [[101, 7592, 1010, 2003, 2026, 3899, 10140, 1029, 102]]			)  # [CLS] hello, is my dog cute? [SEP]
          a     =				model(__lowerCamelCase			)[0]  # embedding shape = (1, 768)
          # compare the actual values for a slice.
          a     =				tf.constant(
              [
                  [
                      0.0_3_2_3_6_2_5_3,
                      0.1_2_7_5_3_3_3_5,
                      0.1_6_8_1_8_5_0_9,
                      0.0_0_2_7_9_7_8_6,
                      0.3_8_9_6_9_3_3,
                      0.2_4_2_6_4_9_4_5,
                      0.2_1_7_8_9_7_1,
                      -0.0_2_3_3_5_2_2_7,
                      -0.0_8_4_8_1_9_5_9,
                      -0.1_4_3_2_4_1_1_7,
                  ]
              ]			)
          self.assertTrue(numpy.allclose(output[:, :10].numpy()  ,		expected_slice.numpy()  ,		atol=1e-4			)			)







from math import isqrt

def  SCREAMING_SNAKE_CASE							(       __UpperCamelCase)      ->					bool:
     return all(number % divisor != 0 for divisor in range(2		, isqrt(__UpperCamelCase) + 1))

def  SCREAMING_SNAKE_CASE							(       __UpperCamelCase = 10**6)      ->					int:
     a     =				0
     a     =				1
     a     =				7
     while prime_candidate < max_prime:
          primes_count += is_prime(__UpperCamelCase)

          cube_index += 1
          prime_candidate += 6 * cube_index

     return primes_count


if __name__ == "__main__":
   print(F'{solution() = }')

