


'''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      lowercase			:

		"""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					,     ):

							'''simple docstring'''


							UpperCamelCase__     :Any							      =				parent
							UpperCamelCase__     :str							      =				batch_size
							UpperCamelCase__     :Optional[Any]							      =				seq_length
							UpperCamelCase__     :Optional[Any]							      =				is_training
							UpperCamelCase__     :Dict							      =				use_input_mask
							UpperCamelCase__     :Union[str, Any]							      =				use_token_type_ids
							UpperCamelCase__     :List[Any]							      =				use_labels
							UpperCamelCase__     :Union[str, Any]							      =				vocab_size
							UpperCamelCase__     :str							      =				hidden_size
							UpperCamelCase__     :str							      =				num_hidden_layers
							UpperCamelCase__     :List[str]							      =				num_attention_heads
							UpperCamelCase__     :Optional[int]							      =				intermediate_size
							UpperCamelCase__     :Union[str, Any]							      =				hidden_act
							UpperCamelCase__     :Union[str, Any]							      =				hidden_dropout_prob
							UpperCamelCase__     :Optional[Any]							      =				attention_probs_dropout_prob
							UpperCamelCase__     :List[str]							      =				max_position_embeddings
							UpperCamelCase__     :Optional[int]							      =				type_vocab_size
							UpperCamelCase__     :Optional[int]							      =				type_sequence_label_size
							UpperCamelCase__     :Tuple							      =				initializer_range
							UpperCamelCase__     :Tuple							      =				num_labels
							UpperCamelCase__     :Any							      =				num_choices
							UpperCamelCase__     :Tuple							      =				scope
							UpperCamelCase__     :Union[str, Any]							      =				projection_dim




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Tuple							      =				ids_tensor([self.batch_size, self.seq_length]					,     self.vocab_size							)

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

							UpperCamelCase__     :List[str]							      =				None
							if self.use_token_type_ids:
												UpperCamelCase__     :Optional[int]							      =				ids_tensor([self.batch_size, self.seq_length]					,     self.type_vocab_size							)

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

							UpperCamelCase__     :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=UpperCamelCase_					,     initializer_range=self.initializer_range					,     )
							UpperCamelCase__     :List[str]							      =				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					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :Union[str, Any]							      =				TFDPRContextEncoder(config=UpperCamelCase_							)
							UpperCamelCase__     :List[Any]							      =				model(UpperCamelCase_					,     attention_mask=UpperCamelCase_					,     token_type_ids=UpperCamelCase_							)
							UpperCamelCase__     :Optional[Any]							      =				model(UpperCamelCase_					,     token_type_ids=UpperCamelCase_							)
							UpperCamelCase__     :Optional[Any]							      =				model(UpperCamelCase_							)
							self.parent.assertEqual(result.pooler_output.shape					,     (self.batch_size, self.projection_dim or self.hidden_size)							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :Dict							      =				TFDPRQuestionEncoder(config=UpperCamelCase_							)
							UpperCamelCase__     :int							      =				model(UpperCamelCase_					,     attention_mask=UpperCamelCase_					,     token_type_ids=UpperCamelCase_							)
							UpperCamelCase__     :Any							      =				model(UpperCamelCase_					,     token_type_ids=UpperCamelCase_							)
							UpperCamelCase__     :Optional[Any]							      =				model(UpperCamelCase_							)
							self.parent.assertEqual(result.pooler_output.shape					,     (self.batch_size, self.projection_dim or self.hidden_size)							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :List[str]							      =				TFDPRReader(config=UpperCamelCase_							)
							UpperCamelCase__     :int							      =				model(UpperCamelCase_					,     attention_mask=UpperCamelCase_							)

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

							'''simple docstring'''


							UpperCamelCase__     :List[str]							      =				self.prepare_config_and_inputs()
							(
							    (
							    UpperCamelCase__
							)      ,       (
							    UpperCamelCase__
							)      ,       (
							    UpperCamelCase__
							)      ,       (
							    UpperCamelCase__
							)      ,       (
							    UpperCamelCase__
							)      ,       (
							    UpperCamelCase__
							)      ,       (
							    UpperCamelCase__
							)      ,       
							)     :Dict							      =				config_and_inputs
							UpperCamelCase__     :Dict							      =				{'''input_ids''': input_ids}
							return config, inputs_dict



@require_tf
class      lowercase			(							A__			,	A__			,	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 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Tuple							      =				TFDPRModelTester(self							)
							UpperCamelCase__     :Any							      =				ConfigTester(self					,     config_class=UpperCamelCase_					,     hidden_size=37							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							self.config_tester.run_common_tests()




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :List[Any]							      =				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_dpr_context_encoder(*UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Optional[Any]							      =				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_dpr_question_encoder(*UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Union[str, Any]							      =				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_dpr_reader(*UpperCamelCase_							)




		@slow
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												UpperCamelCase__     :int							      =				TFDPRContextEncoder.from_pretrained(UpperCamelCase_							)
												self.assertIsNotNone(UpperCamelCase_							)

							for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												UpperCamelCase__     :Union[str, Any]							      =				TFDPRContextEncoder.from_pretrained(UpperCamelCase_							)
												self.assertIsNotNone(UpperCamelCase_							)

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

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



@require_tf
class      lowercase			(							unittest.TestCase      ):

		"""simple docstring"""

		@slow
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Union[str, Any]							      =				TFDPRQuestionEncoder.from_pretrained('''facebook/dpr-question_encoder-single-nq-base'''							)

							UpperCamelCase__     :List[Any]							      =				tf.constant(
							    [[101, 7592, 1010, 2003, 2026, 3899, 10140, 1029, 102]]							)  # [CLS] hello, is my dog cute? [SEP]
							UpperCamelCase__     :Tuple							      =				model(UpperCamelCase_							)[0]  # embedding shape = (1, 768)
							# compare the actual values for a slice.
							UpperCamelCase__     :Optional[int]							      =				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'''
from __future__ import annotations

from decimal import Decimal
from math import *  # noqa: F403

from sympy import diff


def     a   (    __a				,      __a				,      __a = 10**-10     )						->			float:



					'''simple docstring'''






					UpperCamelCase__     :Tuple							      =				a
					while True:
										UpperCamelCase__     :Dict							      =				Decimal(__a     ) - (
										    Decimal(eval(__a     )     ) / Decimal(eval(str(diff(__a     )     )     )     )  # noqa: S307
										)
										# This number dictates the accuracy of the answer
										if abs(eval(__a     )     ) < precision:  # noqa: S307
															return float(__a     )


# Let's Execute
if __name__ == "__main__":
		# Find root of trigonometric function
		# Find value of pi
		print(F"""The root of sin(x) = 0 is {newton_raphson('sin(x)', 2)}""")
		# Find root of polynomial
		print(F"""The root of x**2 - 5*x + 2 = 0 is {newton_raphson('x**2 - 5*x + 2', 0.4)}""")
		# Find Square Root of 5
		print(F"""The root of log(x) - 1 = 0 is {newton_raphson('log(x) - 1', 2)}""")
		# Exponential Roots
		print(F"""The root of exp(x) - 1 = 0 is {newton_raphson('exp(x) - 1', 0)}""")