




"""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 				snake_case_			:







   """simple docstring"""




   def __init__(		self       ,					lowerCamelCase_       ,					lowerCamelCase_=1_3       ,					lowerCamelCase_=7       ,					lowerCamelCase_=True       ,					lowerCamelCase_=True       ,					lowerCamelCase_=True       ,					lowerCamelCase_=True       ,					lowerCamelCase_=9_9       ,					lowerCamelCase_=3_2       ,					lowerCamelCase_=2       ,					lowerCamelCase_=4       ,					lowerCamelCase_=3_7       ,					lowerCamelCase_="gelu"       ,					lowerCamelCase_=0.1       ,					lowerCamelCase_=0.1       ,					lowerCamelCase_=5_1_2       ,					lowerCamelCase_=1_6       ,					lowerCamelCase_=2       ,					lowerCamelCase_=0.02       ,					lowerCamelCase_=3       ,					lowerCamelCase_=4       ,					lowerCamelCase_=None       ,					lowerCamelCase_=0       ,					)				->   Tuple:
       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   UpperCAmelCase__			(		self)				->   List[str]:
       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=__lowercase       ,					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   UpperCAmelCase__			(		self       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_)				->   Dict:
       UpperCamelCase              =	TFDPRContextEncoder(config=__lowercase)
       UpperCamelCase              =	model(__lowercase       ,					attention_mask=__lowercase       ,					token_type_ids=__lowercase)
       UpperCamelCase              =	model(__lowercase       ,					token_type_ids=__lowercase)
       UpperCamelCase              =	model(__lowercase)
       self.parent.assertEqual(result.pooler_output.shape       ,					(self.batch_size, self.projection_dim or self.hidden_size))







   def   UpperCAmelCase__			(		self       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_)				->   List[Any]:
       UpperCamelCase              =	TFDPRQuestionEncoder(config=__lowercase)
       UpperCamelCase              =	model(__lowercase       ,					attention_mask=__lowercase       ,					token_type_ids=__lowercase)
       UpperCamelCase              =	model(__lowercase       ,					token_type_ids=__lowercase)
       UpperCamelCase              =	model(__lowercase)
       self.parent.assertEqual(result.pooler_output.shape       ,					(self.batch_size, self.projection_dim or self.hidden_size))







   def   UpperCAmelCase__			(		self       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_)				->   Optional[int]:
       UpperCamelCase              =	TFDPRReader(config=__lowercase)
       UpperCamelCase              =	model(__lowercase       ,					attention_mask=__lowercase)

       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)				->   Any:
       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 				snake_case_			(					lowerCamelCase_	, lowerCamelCase_	, unittest.TestCase			):







   """simple docstring"""




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

   A_				      =       False
   A_				      =       False
   A_				      =       False
   A_				      =       False
   A_				      =       False







   def   UpperCAmelCase__			(		self)				->   Tuple:
       UpperCamelCase              =	TFDPRModelTester(self)
       UpperCamelCase              =	ConfigTester(self       ,					config_class=__lowercase       ,					hidden_size=3_7)







   def   UpperCAmelCase__			(		self)				->   Dict:
       self.config_tester.run_common_tests()







   def   UpperCAmelCase__			(		self)				->   List[str]:
       UpperCamelCase              =	self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_dpr_context_encoder(*__lowercase)







   def   UpperCAmelCase__			(		self)				->   Union[str, Any]:
       UpperCamelCase              =	self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_dpr_question_encoder(*__lowercase)







   def   UpperCAmelCase__			(		self)				->   int:
       UpperCamelCase              =	self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_dpr_reader(*__lowercase)







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







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

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

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

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

@require_tf
class 				snake_case_			(					unittest.TestCase			):







   """simple docstring"""




   @slow
   def   UpperCAmelCase__			(		self)				->   Dict:
       UpperCamelCase              =	TFDPRQuestionEncoder.from_pretrained('''facebook/dpr-question_encoder-single-nq-base''')

       UpperCamelCase              =	tf.constant(
           [[1_0_1, 7_5_9_2, 1_0_1_0, 2_0_0_3, 2_0_2_6, 3_8_9_9, 1_0_1_4_0, 1_0_2_9, 1_0_2]])  # [CLS] hello, is my dog cute? [SEP]
       UpperCamelCase              =	model(__lowercase)[0]  # embedding shape = (1, 768)
       # compare the actual values for a slice.
       UpperCamelCase              =	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[:, :1_0].numpy()       ,					expected_slice.numpy()       ,					atol=1e-4))


'''simple docstring'''

from __future__ import annotations

def 					__UpperCamelCase				(						lowercase__    :	float,       lowercase__    :	float,       lowercase__    :	float			):






     '''simple docstring'''





     if (voltage, current, resistance).count(0			) != 1:
          raise ValueError('One and only one argument must be 0'			)
     if resistance < 0:
          raise ValueError('Resistance cannot be negative'			)
     if voltage == 0:
          return {"voltage": float(current * resistance			)}
     elif current == 0:
          return {"current": voltage / resistance}
     elif resistance == 0:
          return {"resistance": voltage / current}
     else:
          raise ValueError('Exactly one argument must be 0'			)


if __name__ == "__main__":
       import doctest

       doctest.testmod()


