


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


   '''simple docstring'''







   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_							:str			     =							parent
        lowercase_							:Dict			     =							batch_size
        lowercase_							:Dict			     =							seq_length
        lowercase_							:str			     =							is_training
        lowercase_							:Dict			     =							use_input_mask
        lowercase_							:List[str]			     =							use_token_type_ids
        lowercase_							:int			     =							use_labels
        lowercase_							:Optional[Any]			     =							vocab_size
        lowercase_							:Tuple			     =							hidden_size
        lowercase_							:Optional[Any]			     =							num_hidden_layers
        lowercase_							:int			     =							num_attention_heads
        lowercase_							:Dict			     =							intermediate_size
        lowercase_							:int			     =							hidden_act
        lowercase_							:Any			     =							hidden_dropout_prob
        lowercase_							:List[str]			     =							attention_probs_dropout_prob
        lowercase_							:str			     =							max_position_embeddings
        lowercase_							:List[Any]			     =							type_vocab_size
        lowercase_							:Optional[int]			     =							type_sequence_label_size
        lowercase_							:List[Any]			     =							initializer_range
        lowercase_							:Optional[Any]			     =							num_labels
        lowercase_							:str			     =							num_choices
        lowercase_							:str			     =							scope
        lowercase_							:Optional[int]			     =							projection_dim
   def 		UpperCamelCase	(  self		):
        lowercase_							:int			     =							ids_tensor([self.batch_size, self.seq_length] ,				self.vocab_size		)

        lowercase_							:List[str]			     =							None
        if self.use_input_mask:
             # follow test_modeling_tf_ctrl.py
             lowercase_							:Optional[int]			     =							random_attention_mask([self.batch_size, self.seq_length]		)

        lowercase_							:Union[str, Any]			     =							None
        if self.use_token_type_ids:
             lowercase_							:Tuple			     =							ids_tensor([self.batch_size, self.seq_length] ,				self.type_vocab_size		)

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

        lowercase_							:Tuple			     =							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_							:Optional[Any]			     =							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_							:Optional[Any]			     =							TFDPRContextEncoder(config=__lowerCAmelCase		)
        lowercase_							:Dict			     =							model(__lowerCAmelCase ,				attention_mask=__lowerCAmelCase ,				token_type_ids=__lowerCAmelCase		)
        lowercase_							:str			     =							model(__lowerCAmelCase ,				token_type_ids=__lowerCAmelCase		)
        lowercase_							:Optional[int]			     =							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_							:Any			     =							TFDPRQuestionEncoder(config=__lowerCAmelCase		)
        lowercase_							:Tuple			     =							model(__lowerCAmelCase ,				attention_mask=__lowerCAmelCase ,				token_type_ids=__lowerCAmelCase		)
        lowercase_							:Optional[int]			     =							model(__lowerCAmelCase ,				token_type_ids=__lowerCAmelCase		)
        lowercase_							:Union[str, Any]			     =							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_							:Optional[int]			     =							TFDPRReader(config=__lowerCAmelCase		)
        lowercase_							:Dict			     =							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_							:List[str]			     =							self.prepare_config_and_inputs()
        (
            (
            lowercase_					
        )     ,   (
            lowercase_					
        )     ,   (
            lowercase_					
        )     ,   (
            lowercase_					
        )     ,   (
            lowercase_					
        )     ,   (
            lowercase_					
        )     ,   (
            lowercase_					
        )     ,   					
        )							:Optional[int]			     =							config_and_inputs
        lowercase_							:List[str]			     =							{'''input_ids''': input_ids}
        return config, inputs_dict






@require_tf
class   UpperCamelCase       (		lowerCAmelCase_    ,   lowerCAmelCase_    ,   unittest.TestCase  ):


   '''simple docstring'''







   lowercase       :						Tuple          =(
       (
           TFDPRContextEncoder,
           TFDPRQuestionEncoder,
           TFDPRReader,
       )
       if is_tf_available()
       else ()
   )
   lowercase       :						str          ={'feature-extraction': TFDPRQuestionEncoder} if is_tf_available() else {}

   lowercase       :						Optional[int]          =False
   lowercase       :						Optional[int]          =False
   lowercase       :						Any          =False
   lowercase       :						Optional[int]          =False
   lowercase       :						Dict          =False
   def 		UpperCamelCase	(  self		):
        lowercase_							:str			     =							TFDPRModelTester(self		)
        lowercase_							:Dict			     =							ConfigTester(self ,				config_class=__lowerCAmelCase ,				hidden_size=37		)
   def 		UpperCamelCase	(  self		):
        self.config_tester.run_common_tests()
   def 		UpperCamelCase	(  self		):
        lowercase_							:List[Any]			     =							self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_dpr_context_encoder(*__lowerCAmelCase		)
   def 		UpperCamelCase	(  self		):
        lowercase_							:int			     =							self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_dpr_question_encoder(*__lowerCAmelCase		)
   def 		UpperCamelCase	(  self		):
        lowercase_							:int			     =							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_							:Union[str, Any]			     =							TFDPRContextEncoder.from_pretrained(__lowerCAmelCase		)
             self.assertIsNotNone(__lowerCAmelCase		)

        for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             lowercase_							:str			     =							TFDPRContextEncoder.from_pretrained(__lowerCAmelCase		)
             self.assertIsNotNone(__lowerCAmelCase		)

        for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             lowercase_							:Dict			     =							TFDPRQuestionEncoder.from_pretrained(__lowerCAmelCase		)
             self.assertIsNotNone(__lowerCAmelCase		)

        for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             lowercase_							:Union[str, Any]			     =							TFDPRReader.from_pretrained(__lowerCAmelCase		)
             self.assertIsNotNone(__lowerCAmelCase		)






@require_tf
class   UpperCamelCase       (		unittest.TestCase  ):


   '''simple docstring'''







   @slow
   def 		UpperCamelCase	(  self		):
        lowercase_							:List[Any]			     =							TFDPRQuestionEncoder.from_pretrained('''facebook/dpr-question_encoder-single-nq-base'''		)

        lowercase_							:Any			     =							tf.constant(
            [[101, 7592, 1010, 2003, 2026, 3899, 1_0140, 1029, 102]]		)  # [CLS] hello, is my dog cute? [SEP]
        lowercase_							:List[Any]			     =							model(__lowerCAmelCase		)[0]  # embedding shape = (1, 768)
        # compare the actual values for a slice.
        lowercase_							:Any			     =							tf.constant(
            [
                [
                    0.0323_6253,
                    0.1275_3335,
                    0.1681_8509,
                    0.0027_9786,
                    0.389_6933,
                    0.2426_4945,
                    0.217_8971,
                    -0.0233_5227,
                    -0.0848_1959,
                    -0.1432_4117,
                ]
            ]		)
        self.assertTrue(numpy.allclose(output[:, :10].numpy() ,				expected_slice.numpy() ,				atol=1E-4		)		)


"""simple docstring"""


from __future__ import annotations

import typing
from collections import Counter






def      __UpperCAmelCase       (      lowercase		):







  """simple docstring"""
  _UpperCAmelCase    			=   Counter()
  for base in range(1 ,max_perimeter + 1		):
    for perpendicular in range(lowercase ,max_perimeter + 1		):
      _UpperCAmelCase    			=   (base * base + perpendicular * perpendicular) ** 0.5
      if hypotenuse == int(lowercase		):
        _UpperCAmelCase    			=   int(base + perpendicular + hypotenuse		)
        if perimeter > max_perimeter:
          continue
        triplets[perimeter] += 1
  return triplets






def      __UpperCAmelCase       (      lowercase = 10_00		):







  """simple docstring"""
  _UpperCAmelCase    			=   pythagorean_triple(lowercase		)
  return triplets.most_common(1		)[0][0]


if __name__ == "__main__":
    print(F'''Perimeter {solution()} has maximum solutions''')
