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     :

							'''simple docstring'''

							def __init__(				self   ,	_snake_case   ,	_snake_case=13   ,	_snake_case=7   ,	_snake_case=True   ,	_snake_case=True   ,	_snake_case=True   ,	_snake_case=True   ,	_snake_case=99   ,	_snake_case=32   ,	_snake_case=2   ,	_snake_case=4   ,	_snake_case=37   ,	_snake_case="gelu"   ,	_snake_case=0.1   ,	_snake_case=0.1   ,	_snake_case=512   ,	_snake_case=16   ,	_snake_case=2   ,	_snake_case=0.02   ,	_snake_case=3   ,	_snake_case=4   ,	_snake_case=None   ,	_snake_case=0   ,	):
												_lowerCAmelCase			:		Union[str, Any]          = parent
												_lowerCAmelCase			:		Any          = batch_size
												_lowerCAmelCase			:		str          = seq_length
												_lowerCAmelCase			:		Optional[int]          = is_training
												_lowerCAmelCase			:		str          = use_input_mask
												_lowerCAmelCase			:		int          = use_token_type_ids
												_lowerCAmelCase			:		List[str]          = use_labels
												_lowerCAmelCase			:		Optional[Any]          = vocab_size
												_lowerCAmelCase			:		Optional[int]          = hidden_size
												_lowerCAmelCase			:		str          = num_hidden_layers
												_lowerCAmelCase			:		str          = num_attention_heads
												_lowerCAmelCase			:		Union[str, Any]          = intermediate_size
												_lowerCAmelCase			:		Tuple          = hidden_act
												_lowerCAmelCase			:		Optional[Any]          = hidden_dropout_prob
												_lowerCAmelCase			:		int          = attention_probs_dropout_prob
												_lowerCAmelCase			:		Tuple          = max_position_embeddings
												_lowerCAmelCase			:		int          = type_vocab_size
												_lowerCAmelCase			:		Optional[Any]          = type_sequence_label_size
												_lowerCAmelCase			:		Tuple          = initializer_range
												_lowerCAmelCase			:		Any          = num_labels
												_lowerCAmelCase			:		Any          = num_choices
												_lowerCAmelCase			:		List[str]          = scope
												_lowerCAmelCase			:		int          = projection_dim






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Union[str, Any]          = ids_tensor([self.batch_size, self.seq_length]   ,	self.vocab_size )

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

												_lowerCAmelCase			:		int          = None
												if self.use_token_type_ids:
																	_lowerCAmelCase			:		List[Any]          = ids_tensor([self.batch_size, self.seq_length]   ,	self.type_vocab_size )

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

												_lowerCAmelCase			:		Union[str, Any]          = 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   ,	)
												_lowerCAmelCase			:		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 	SCREAMING_SNAKE_CASE__			(				self   ,	_snake_case   ,	_snake_case   ,	_snake_case   ,	_snake_case   ,	_snake_case   ,	_snake_case   ,	_snake_case ):
												_lowerCAmelCase			:		Union[str, Any]          = TFDPRContextEncoder(config=lowercase_ )
												_lowerCAmelCase			:		Optional[Any]          = model(lowercase_   ,	attention_mask=lowercase_   ,	token_type_ids=lowercase_ )
												_lowerCAmelCase			:		Any          = model(lowercase_   ,	token_type_ids=lowercase_ )
												_lowerCAmelCase			:		Dict          = model(lowercase_ )
												self.parent.assertEqual(result.pooler_output.shape   ,	(self.batch_size, self.projection_dim or self.hidden_size) )






							def 	SCREAMING_SNAKE_CASE__			(				self   ,	_snake_case   ,	_snake_case   ,	_snake_case   ,	_snake_case   ,	_snake_case   ,	_snake_case   ,	_snake_case ):
												_lowerCAmelCase			:		int          = TFDPRQuestionEncoder(config=lowercase_ )
												_lowerCAmelCase			:		Optional[Any]          = model(lowercase_   ,	attention_mask=lowercase_   ,	token_type_ids=lowercase_ )
												_lowerCAmelCase			:		Tuple          = model(lowercase_   ,	token_type_ids=lowercase_ )
												_lowerCAmelCase			:		Tuple          = model(lowercase_ )
												self.parent.assertEqual(result.pooler_output.shape   ,	(self.batch_size, self.projection_dim or self.hidden_size) )






							def 	SCREAMING_SNAKE_CASE__			(				self   ,	_snake_case   ,	_snake_case   ,	_snake_case   ,	_snake_case   ,	_snake_case   ,	_snake_case   ,	_snake_case ):
												_lowerCAmelCase			:		Any          = TFDPRReader(config=lowercase_ )
												_lowerCAmelCase			:		Optional[Any]          = 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 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Optional[int]          = self.prepare_config_and_inputs()
												(
												    (
												    _lowerCAmelCase
												)      ,	(
												    _lowerCAmelCase
												)      ,	(
												    _lowerCAmelCase
												)      ,	(
												    _lowerCAmelCase
												)      ,	(
												    _lowerCAmelCase
												)      ,	(
												    _lowerCAmelCase
												)      ,	(
												    _lowerCAmelCase
												)      ,	
												)			:		Tuple          = config_and_inputs
												_lowerCAmelCase			:		Any          = {"input_ids": input_ids}
												return config, inputs_dict



@require_tf
class __A     (      _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 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		int          = TFDPRModelTester(self )
												_lowerCAmelCase			:		int          = ConfigTester(self   ,	config_class=lowercase_   ,	hidden_size=37 )






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												self.config_tester.run_common_tests()






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Optional[Any]          = self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_dpr_context_encoder(*lowercase_ )






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Optional[int]          = self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_dpr_question_encoder(*lowercase_ )






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		List[Any]          = self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_dpr_reader(*lowercase_ )






							@slow
							def 	SCREAMING_SNAKE_CASE__			(				self ):
												for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	_lowerCAmelCase			:		Union[str, Any]          = TFDPRContextEncoder.from_pretrained(lowercase_ )
																	self.assertIsNotNone(lowercase_ )

												for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	_lowerCAmelCase			:		List[Any]          = TFDPRContextEncoder.from_pretrained(lowercase_ )
																	self.assertIsNotNone(lowercase_ )

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

												for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	_lowerCAmelCase			:		Dict          = TFDPRReader.from_pretrained(lowercase_ )
																	self.assertIsNotNone(lowercase_ )



@require_tf
class __A     (      unittest.TestCase						):

							'''simple docstring'''

							@slow
							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Optional[int]          = TFDPRQuestionEncoder.from_pretrained("facebook/dpr-question_encoder-single-nq-base" )

												_lowerCAmelCase			:		Optional[int]          = tf.constant(
												    [[101, 7592, 1010, 2003, 2026, 3899, 1_0140, 1029, 102]] )  # [CLS] hello, is my dog cute? [SEP]
												_lowerCAmelCase			:		Dict          = model(lowercase_ )[0]  # embedding shape = (1, 768)
												# compare the actual values for a slice.
												_lowerCAmelCase			:		Optional[int]          = 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'''

def 						__magic_name__       (      __UpperCAmelCase, __UpperCAmelCase      )						->   int:

					'''simple docstring'''

					return int((input_a, input_a).count(0      ) == 0      )


def 						__magic_name__       (      )						->   None:

					'''simple docstring'''

					assert and_gate(0, 0      ) == 0
					assert and_gate(0, 1      ) == 0
					assert and_gate(1, 0      ) == 0
					assert and_gate(1, 1      ) == 1


if __name__ == "__main__":
							test_and_gate()
							print(and_gate(1, 0))
							print(and_gate(0, 0))
							print(and_gate(0, 1))
							print(and_gate(1, 1))

