
'''simple docstring'''





from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, 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 tensorflow as tf

		from transformers import (
		    TFConvBertForMaskedLM,
		    TFConvBertForMultipleChoice,
		    TFConvBertForQuestionAnswering,
		    TFConvBertForSequenceClassification,
		    TFConvBertForTokenClassification,
		    TFConvBertModel,
		)







class        lowerCAmelCase__      :

						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=5_12       ,							a=16       ,							a=2       ,							a=0.02       ,							a=3       ,							a=4       ,							a=None       ,							)					->      Dict:


								'''simple docstring'''

								_UpperCamelCase						    =	parent
								_UpperCamelCase						    =	13
								_UpperCamelCase						    =	7
								_UpperCamelCase						    =	True
								_UpperCamelCase						    =	True
								_UpperCamelCase						    =	True
								_UpperCamelCase						    =	True
								_UpperCamelCase						    =	99
								_UpperCamelCase						    =	3_84
								_UpperCamelCase						    =	2
								_UpperCamelCase						    =	4
								_UpperCamelCase						    =	37
								_UpperCamelCase						    =	"gelu"
								_UpperCamelCase						    =	0.1
								_UpperCamelCase						    =	0.1
								_UpperCamelCase						    =	5_12
								_UpperCamelCase						    =	16
								_UpperCamelCase						    =	2
								_UpperCamelCase						    =	0.02
								_UpperCamelCase						    =	3
								_UpperCamelCase						    =	4
								_UpperCamelCase						    =	1_28
								_UpperCamelCase						    =	2
								_UpperCamelCase						    =	9
								_UpperCamelCase						    =	1
								_UpperCamelCase						    =	None

						def  A_				(			self				)					->      Tuple:


								'''simple docstring'''

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

								_UpperCamelCase						    =	None
								if self.use_input_mask:
										_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						    =	ConvBertConfig(
								    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       ,							initializer_range=self.initializer_range       ,							return_dict=A_       ,							)

								return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      Optional[Any]:


								'''simple docstring'''

								_UpperCamelCase						    =	TFConvBertModel(config=A_				)
								_UpperCamelCase						    =	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

								_UpperCamelCase						    =	[input_ids, input_mask]
								_UpperCamelCase						    =	model(A_				)

								_UpperCamelCase						    =	model(A_				)

								self.parent.assertEqual(result.last_hidden_state.shape       ,							(self.batch_size, self.seq_length, self.hidden_size)				)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      str:


								'''simple docstring'''

								_UpperCamelCase						    =	TFConvBertForMaskedLM(config=A_				)
								_UpperCamelCase						    =	{
								    "input_ids": input_ids,
								    "attention_mask": input_mask,
								    "token_type_ids": token_type_ids,
								}
								_UpperCamelCase						    =	model(A_				)
								self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.seq_length, self.vocab_size)				)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      List[str]:


								'''simple docstring'''

								_UpperCamelCase						    =	self.num_labels
								_UpperCamelCase						    =	TFConvBertForSequenceClassification(config=A_				)
								_UpperCamelCase						    =	{
								    "input_ids": input_ids,
								    "attention_mask": input_mask,
								    "token_type_ids": token_type_ids,
								}

								_UpperCamelCase						    =	model(A_				)
								self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.num_labels)				)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      str:


								'''simple docstring'''

								_UpperCamelCase						    =	self.num_choices
								_UpperCamelCase						    =	TFConvBertForMultipleChoice(config=A_				)
								_UpperCamelCase						    =	tf.tile(tf.expand_dims(A_       ,							1				)       ,							(1, self.num_choices, 1)				)
								_UpperCamelCase						    =	tf.tile(tf.expand_dims(A_       ,							1				)       ,							(1, self.num_choices, 1)				)
								_UpperCamelCase						    =	tf.tile(tf.expand_dims(A_       ,							1				)       ,							(1, self.num_choices, 1)				)
								_UpperCamelCase						    =	{
								    "input_ids": multiple_choice_inputs_ids,
								    "attention_mask": multiple_choice_input_mask,
								    "token_type_ids": multiple_choice_token_type_ids,
								}
								_UpperCamelCase						    =	model(A_				)
								self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.num_choices)				)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      List[str]:


								'''simple docstring'''

								_UpperCamelCase						    =	self.num_labels
								_UpperCamelCase						    =	TFConvBertForTokenClassification(config=A_				)
								_UpperCamelCase						    =	{
								    "input_ids": input_ids,
								    "attention_mask": input_mask,
								    "token_type_ids": token_type_ids,
								}
								_UpperCamelCase						    =	model(A_				)
								self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.seq_length, self.num_labels)				)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      Tuple:


								'''simple docstring'''

								_UpperCamelCase						    =	TFConvBertForQuestionAnswering(config=A_				)
								_UpperCamelCase						    =	{
								    "input_ids": input_ids,
								    "attention_mask": input_mask,
								    "token_type_ids": token_type_ids,
								}

								_UpperCamelCase						    =	model(A_				)
								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)				)







						def  A_				(			self				)					->      int:


								'''simple docstring'''

								_UpperCamelCase						    =	self.prepare_config_and_inputs()
								(
								    _UpperCamelCase					
								)						    =	config_and_inputs
								_UpperCamelCase						    =	{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
								return config, inputs_dict







@require_tf
class        lowerCAmelCase__      (   __snake_case		,	__snake_case		,	unittest.TestCase	):
						UpperCamelCase_							: Dict	=		(
						    (
						        TFConvBertModel,
						        TFConvBertForMaskedLM,
						        TFConvBertForQuestionAnswering,
						        TFConvBertForSequenceClassification,
						        TFConvBertForTokenClassification,
						        TFConvBertForMultipleChoice,
						    )
						    if is_tf_available()
						    else ()
						)
						UpperCamelCase_							: Optional[Any]	=		(
						    {
						        'feature-extraction': TFConvBertModel,
						        'fill-mask': TFConvBertForMaskedLM,
						        'question-answering': TFConvBertForQuestionAnswering,
						        'text-classification': TFConvBertForSequenceClassification,
						        'token-classification': TFConvBertForTokenClassification,
						        'zero-shot': TFConvBertForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						UpperCamelCase_							: Any	=		False
						UpperCamelCase_							: int	=		False
						UpperCamelCase_							: str	=		False

						def  A_				(			self				)					->      Tuple:


								'''simple docstring'''

								_UpperCamelCase						    =	TFConvBertModelTester(self				)
								_UpperCamelCase						    =	ConfigTester(self       ,							config_class=A_       ,							hidden_size=37				)

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


								'''simple docstring'''

								self.config_tester.run_common_tests()

						def  A_				(			self				)					->      Dict:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*A_				)

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


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*A_				)

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


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_multiple_choice(*A_				)

						def  A_				(			self				)					->      Union[str, Any]:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*A_				)

						def  A_				(			self				)					->      Any:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*A_				)

						def  A_				(			self				)					->      Any:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*A_				)

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


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs_for_common()
								_UpperCamelCase						    =	True
								_UpperCamelCase						    =	True

								if hasattr(A_       ,							"""use_cache"""				):
										_UpperCamelCase						    =	True

								_UpperCamelCase						    =	getattr(self.model_tester       ,							"""encoder_seq_length"""       ,							self.model_tester.seq_length				)
								_UpperCamelCase						    =	getattr(self.model_tester       ,							"""key_length"""       ,							A_				)

								for model_class in self.all_model_classes:
										_UpperCamelCase						    =	self._prepare_for_class(A_       ,							A_				)
										_UpperCamelCase						    =	model_class(A_				)
										_UpperCamelCase						    =	len(model(A_				)				)

										with tempfile.TemporaryDirectory() as tmpdirname:
												model.save_pretrained(A_       ,							saved_model=A_				)
												_UpperCamelCase						    =	os.path.join(A_       ,							"""saved_model"""       ,							"""1"""				)
												_UpperCamelCase						    =	tf.keras.models.load_model(A_				)
												_UpperCamelCase						    =	model(A_				)

												if self.is_encoder_decoder:
														_UpperCamelCase						    =	outputs["encoder_hidden_states"]
														_UpperCamelCase						    =	outputs["encoder_attentions"]
												else:
														_UpperCamelCase						    =	outputs["hidden_states"]
														_UpperCamelCase						    =	outputs["attentions"]

												self.assertEqual(len(A_				)       ,							A_				)

												_UpperCamelCase						    =	getattr(
												    self.model_tester       ,							"""expected_num_hidden_layers"""       ,							self.model_tester.num_hidden_layers + 1				)

												self.assertEqual(len(A_				)       ,							A_				)
												self.assertListEqual(
												    list(output_hidden_states[0].shape[-2:]				)       ,							[self.model_tester.seq_length, self.model_tester.hidden_size]       ,							)

												self.assertEqual(len(A_				)       ,							self.model_tester.num_hidden_layers				)
												self.assertListEqual(
												    list(output_attentions[0].shape[-3:]				)       ,							[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]       ,							)

						@slow
						def  A_				(			self				)					->      Dict:


								'''simple docstring'''

								_UpperCamelCase						    =	TFConvBertModel.from_pretrained("""YituTech/conv-bert-base"""				)
								self.assertIsNotNone(A_				)







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


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs_for_common()
								_UpperCamelCase						    =	True
								_UpperCamelCase						    =	getattr(self.model_tester       ,							"""decoder_seq_length"""       ,							self.model_tester.seq_length				)
								_UpperCamelCase						    =	getattr(self.model_tester       ,							"""encoder_seq_length"""       ,							self.model_tester.seq_length				)
								_UpperCamelCase						    =	getattr(self.model_tester       ,							"""key_length"""       ,							A_				)
								_UpperCamelCase						    =	getattr(self.model_tester       ,							"""key_length"""       ,							A_				)

								def check_decoder_attentions_output(a				):
										_UpperCamelCase						    =	len(A_				)
										self.assertEqual(out_len % 2       ,							0				)
										_UpperCamelCase						    =	outputs.decoder_attentions
										self.assertEqual(len(A_				)       ,							self.model_tester.num_hidden_layers				)
										self.assertListEqual(
										    list(decoder_attentions[0].shape[-3:]				)       ,							[self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]       ,							)

								def check_encoder_attentions_output(a				):
										_UpperCamelCase						    =	[
										    t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
										]
										self.assertEqual(len(A_				)       ,							self.model_tester.num_hidden_layers				)
										self.assertListEqual(
										    list(attentions[0].shape[-3:]				)       ,							[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]       ,							)

								for model_class in self.all_model_classes:
										_UpperCamelCase						    =	True
										_UpperCamelCase						    =	False
										_UpperCamelCase						    =	model_class(A_				)
										_UpperCamelCase						    =	model(self._prepare_for_class(A_       ,							A_				)				)
										_UpperCamelCase						    =	len(A_				)
										self.assertEqual(config.output_hidden_states       ,							A_				)
										check_encoder_attentions_output(A_				)

										if self.is_encoder_decoder:
												_UpperCamelCase						    =	model_class(A_				)
												_UpperCamelCase						    =	model(self._prepare_for_class(A_       ,							A_				)				)
												self.assertEqual(config.output_hidden_states       ,							A_				)
												check_decoder_attentions_output(A_				)

										# Check that output attentions can also be changed via the config
										del inputs_dict["output_attentions"]
										_UpperCamelCase						    =	True
										_UpperCamelCase						    =	model_class(A_				)
										_UpperCamelCase						    =	model(self._prepare_for_class(A_       ,							A_				)				)
										self.assertEqual(config.output_hidden_states       ,							A_				)
										check_encoder_attentions_output(A_				)

										# Check attention is always last and order is fine
										_UpperCamelCase						    =	True
										_UpperCamelCase						    =	True
										_UpperCamelCase						    =	model_class(A_				)
										_UpperCamelCase						    =	model(self._prepare_for_class(A_       ,							A_				)				)

										self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)       ,							len(A_				)				)
										self.assertEqual(model.config.output_hidden_states       ,							A_				)
										check_encoder_attentions_output(A_				)







@require_tf
class        lowerCAmelCase__      (   unittest.TestCase	):

						@slow
						def  A_				(			self				)					->      List[Any]:


								'''simple docstring'''

								_UpperCamelCase						    =	TFConvBertModel.from_pretrained("""YituTech/conv-bert-base"""				)
								_UpperCamelCase						    =	tf.constant([[0, 1, 2, 3, 4, 5]]				)
								_UpperCamelCase						    =	model(A_				)[0]

								_UpperCamelCase						    =	[1, 6, 7_68]
								self.assertEqual(output.shape       ,							A_				)

								_UpperCamelCase						    =	tf.constant(
								    [
								        [
								            [-0.0347_5493, -0.468_6034, -0.3063_8832],
								            [0.2263_7248, -0.2698_8646, -0.742_3424],
								            [0.1032_4868, -0.4501_3508, -0.5828_0784],
								        ]
								    ]				)
								tf.debugging.assert_near(output[:, :3, :3]       ,							A_       ,							atol=1e-4				)





def 							__A(lowerCAmelCase						,  lowerCAmelCase )		->				tuple[float, float]:

		"""simple docstring"""






		if not len(lowerCAmelCase ) == len(lowerCAmelCase ) == 3:
				raise ValueError("""Please enter a valid equation.""" )
		if equationa[0] == equationa[1] == equationa[0] == equationa[1] == 0:
				raise ValueError("""Both a & b of two equations can't be zero.""" )

		# Extract the coefficients
		_UpperCamelCase    ,	_UpperCamelCase    ,	_UpperCamelCase						    =	equationa
		_UpperCamelCase    ,	_UpperCamelCase    ,	_UpperCamelCase						    =	equationa

		# Calculate the determinants of the matrices
		_UpperCamelCase						    =	aa * ba - aa * ba
		_UpperCamelCase						    =	ca * ba - ca * ba
		_UpperCamelCase						    =	aa * ca - aa * ca

		# Check if the system of linear equations has a solution (using Cramer's rule)
		if determinant == 0:
				if determinant_x == determinant_y == 0:
						raise ValueError("""Infinite solutions. (Consistent system)""" )
				else:
						raise ValueError("""No solution. (Inconsistent system)""" )
		else:
				if determinant_x == determinant_y == 0:
						# Trivial solution (Inconsistent system)
						return (0.0, 0.0)
				else:
						_UpperCamelCase						    =	determinant_x / determinant
						_UpperCamelCase						    =	determinant_y / determinant
						# Non-Trivial Solution (Consistent system)
						return (x, y)



