




"""simple docstring"""






from __future__ import annotations

import unittest

from transformers import DistilBertConfig, 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.models.distilbert.modeling_tf_distilbert import (
			    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
			    TFDistilBertForMaskedLM,
			    TFDistilBertForMultipleChoice,
			    TFDistilBertForQuestionAnswering,
			    TFDistilBertForSequenceClassification,
			    TFDistilBertForTokenClassification,
			    TFDistilBertModel,
			)






class lowerCAmelCase__      :






			'''simple docstring'''



			def __init__(    self    , lowercase    , ):
							_lowerCamelCase	:     Tuple       =       parent
							_lowerCamelCase	:     Optional[Any]       =       13
							_lowerCamelCase	:     Optional[int]       =       7
							_lowerCamelCase	:     List[str]       =       True
							_lowerCamelCase	:     Tuple       =       True
							_lowerCamelCase	:     Dict       =       False
							_lowerCamelCase	:     List[str]       =       True
							_lowerCamelCase	:     Dict       =       99
							_lowerCamelCase	:     Optional[Any]       =       32
							_lowerCamelCase	:     Tuple       =       2
							_lowerCamelCase	:     Union[str, Any]       =       4
							_lowerCamelCase	:     Union[str, Any]       =       37
							_lowerCamelCase	:     Dict       =       'gelu'
							_lowerCamelCase	:     List[str]       =       0.1
							_lowerCamelCase	:     Tuple       =       0.1
							_lowerCamelCase	:     List[str]       =       512
							_lowerCamelCase	:     int       =       16
							_lowerCamelCase	:     Tuple       =       2
							_lowerCamelCase	:     List[Any]       =       0.02
							_lowerCamelCase	:     Tuple       =       3
							_lowerCamelCase	:     List[str]       =       4
							_lowerCamelCase	:     Dict       =       None
			def    A_       (    self    ):
							_lowerCamelCase	:     List[str]       =       ids_tensor([self.batch_size, self.seq_length]    , self.vocab_size    )

							_lowerCamelCase	:     Tuple       =       None
							if self.use_input_mask:
											_lowerCamelCase	:     Union[str, Any]       =       random_attention_mask([self.batch_size, self.seq_length]    )

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

							_lowerCamelCase	:     str       =       DistilBertConfig(
							    vocab_size=self.vocab_size    , dim=self.hidden_size    , n_layers=self.num_hidden_layers    , n_heads=self.num_attention_heads    , hidden_dim=self.intermediate_size    , hidden_act=self.hidden_act    , dropout=self.hidden_dropout_prob    , attention_dropout=self.attention_probs_dropout_prob    , max_position_embeddings=self.max_position_embeddings    , initializer_range=self.initializer_range    , )

							return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
			def    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     Optional[int]       =       TFDistilBertModel(config=lowercase    )
							_lowerCamelCase	:     int       =       {'input_ids': input_ids, 'attention_mask': input_mask}

							_lowerCamelCase	:     List[str]       =       model(lowercase    )

							_lowerCamelCase	:     List[Any]       =       [input_ids, input_mask]

							_lowerCamelCase	:     Dict       =       model(lowercase    )

							self.parent.assertEqual(result.last_hidden_state.shape    , (self.batch_size, self.seq_length, self.hidden_size)    )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     Optional[Any]       =       TFDistilBertForMaskedLM(config=lowercase    )
							_lowerCamelCase	:     List[Any]       =       {'input_ids': input_ids, 'attention_mask': input_mask}
							_lowerCamelCase	:     int       =       model(lowercase    )
							self.parent.assertEqual(result.logits.shape    , (self.batch_size, self.seq_length, self.vocab_size)    )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     str       =       TFDistilBertForQuestionAnswering(config=lowercase    )
							_lowerCamelCase	:     Tuple       =       {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							}
							_lowerCamelCase	:     int       =       model(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)    )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     Optional[int]       =       self.num_labels
							_lowerCamelCase	:     int       =       TFDistilBertForSequenceClassification(lowercase    )
							_lowerCamelCase	:     Any       =       {'input_ids': input_ids, 'attention_mask': input_mask}
							_lowerCamelCase	:     List[str]       =       model(lowercase    )
							self.parent.assertEqual(result.logits.shape    , (self.batch_size, self.num_labels)    )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     int       =       self.num_choices
							_lowerCamelCase	:     List[str]       =       TFDistilBertForMultipleChoice(lowercase    )
							_lowerCamelCase	:     int       =       tf.tile(tf.expand_dims(lowercase    , 1    )    , (1, self.num_choices, 1)    )
							_lowerCamelCase	:     Optional[int]       =       tf.tile(tf.expand_dims(lowercase    , 1    )    , (1, self.num_choices, 1)    )
							_lowerCamelCase	:     int       =       {
							    'input_ids': multiple_choice_inputs_ids,
							    'attention_mask': multiple_choice_input_mask,
							}
							_lowerCamelCase	:     List[Any]       =       model(lowercase    )
							self.parent.assertEqual(result.logits.shape    , (self.batch_size, self.num_choices)    )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    ):
							_lowerCamelCase	:     List[str]       =       self.num_labels
							_lowerCamelCase	:     Union[str, Any]       =       TFDistilBertForTokenClassification(lowercase    )
							_lowerCamelCase	:     Tuple       =       {'input_ids': input_ids, 'attention_mask': input_mask}
							_lowerCamelCase	:     str       =       model(lowercase    )
							self.parent.assertEqual(result.logits.shape    , (self.batch_size, self.seq_length, self.num_labels)    )






			def    A_       (    self    ):
							_lowerCamelCase	:     Dict       =       self.prepare_config_and_inputs()
							((_lowerCamelCase),					(_lowerCamelCase),					(_lowerCamelCase),					(_lowerCamelCase),					(_lowerCamelCase),					(_lowerCamelCase))	:     str       =       config_and_inputs
							_lowerCamelCase	:     Optional[Any]       =       {'input_ids': input_ids, 'attention_mask': input_mask}
							return config, inputs_dict






@require_tf
class lowerCAmelCase__      (	lowercase,      lowercase,      unittest.TestCase		):






			'''simple docstring'''



			lowerCamelCase__ =     (
			    (
			        TFDistilBertModel,
			        TFDistilBertForMaskedLM,
			        TFDistilBertForQuestionAnswering,
			        TFDistilBertForSequenceClassification,
			        TFDistilBertForTokenClassification,
			        TFDistilBertForMultipleChoice,
			    )
			    if is_tf_available()
			    else None
			)
			lowerCamelCase__ =     (
			    {
			        """feature-extraction""": TFDistilBertModel,
			        """fill-mask""": TFDistilBertForMaskedLM,
			        """question-answering""": TFDistilBertForQuestionAnswering,
			        """text-classification""": TFDistilBertForSequenceClassification,
			        """token-classification""": TFDistilBertForTokenClassification,
			        """zero-shot""": TFDistilBertForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)
			lowerCamelCase__ =     False
			lowerCamelCase__ =     False
			def    A_       (    self    ):
							_lowerCamelCase	:     List[str]       =       TFDistilBertModelTester(self    )
							_lowerCamelCase	:     Any       =       ConfigTester(self    , config_class=lowercase    , dim=37    )
			def    A_       (    self    ):
							self.config_tester.run_common_tests()
			def    A_       (    self    ):
							_lowerCamelCase	:     Dict       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_model(*lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     List[str]       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_masked_lm(*lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     str       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_question_answering(*lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     Optional[int]       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_sequence_classification(*lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     List[str]       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_multiple_choice(*lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     Any       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_token_classification(*lowercase    )






			@slow
			def    A_       (    self    ):
							for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]    ):
											_lowerCamelCase	:     int       =       TFDistilBertModel.from_pretrained(lowercase    )
											self.assertIsNotNone(lowercase    )






@require_tf
class lowerCAmelCase__      (	unittest.TestCase		):






			'''simple docstring'''



			@slow
			def    A_       (    self    ):
							_lowerCamelCase	:     int       =       TFDistilBertModel.from_pretrained('distilbert-base-uncased'    )
							_lowerCamelCase	:     int       =       tf.constant([[0, 1, 2, 3, 4, 5]]    )
							_lowerCamelCase	:     int       =       model(lowercase    )[0]

							_lowerCamelCase	:     Union[str, Any]       =       [1, 6, 768]
							self.assertEqual(output.shape    , lowercase    )

							_lowerCamelCase	:     Dict       =       tf.constant(
							    [
							        [
							            [0.19_26_18_85, -0.13_73_29_55, 0.4_11_97_99],
							            [0.22_15_01_56, -0.07_42_26_61, 0.39_03_72_04],
							            [0.22_75_60_18, -0.0_89_64_14, 0.3_70_14_67],
							        ]
							    ]    )
							tf.debugging.assert_near(output[:, :3, :3]    , lowercase    , atol=1E-4    )





"""simple docstring"""






from __future__ import annotations

from fractions import Fraction
from math import gcd, sqrt







def 	_snake_case     (							lowercase__						):
				_lowerCamelCase	:     int       =       int(number**0.5						)
				return number == sq * sq







def 	_snake_case     (							lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						):
				_lowerCamelCase	:     int       =       x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den
				_lowerCamelCase	:     int       =       x_den * y_den * z_den
				_lowerCamelCase	:     int       =       gcd(lowercase__				,       lowercase__						)
				top //= hcf
				bottom //= hcf
				return top, bottom







def 	_snake_case     (							lowercase__ = 35						):
				_lowerCamelCase	:     set       =       set()
				_lowerCamelCase	:     int
				_lowerCamelCase	:     Fraction       =       Fraction(0						)
				_lowerCamelCase	:     tuple[int, int]

				for x_num in range(1				,       order + 1						):
								for x_den in range(x_num + 1				,       order + 1						):
												for y_num in range(1				,       order + 1						):
																for y_den in range(y_num + 1				,       order + 1						):
																				# n=1
																				_lowerCamelCase	:     int       =       x_num * y_den + x_den * y_num
																				_lowerCamelCase	:     List[Any]       =       x_den * y_den
																				_lowerCamelCase	:     int       =       gcd(lowercase__				,       lowercase__						)
																				z_num //= hcf
																				z_den //= hcf
																				if 0 < z_num < z_den <= order:
																								_lowerCamelCase	:     Optional[Any]       =       add_three(
																								    lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						)
																								unique_s.add(lowercase__						)

																				# n=2
																				_lowerCamelCase	:     Tuple       =       (
																				    x_num * x_num * y_den * y_den + x_den * x_den * y_num * y_num
																				)
																				_lowerCamelCase	:     Dict       =       x_den * x_den * y_den * y_den
																				if is_sq(lowercase__						) and is_sq(lowercase__						):
																								_lowerCamelCase	:     Dict       =       int(sqrt(lowercase__						)						)
																								_lowerCamelCase	:     Optional[Any]       =       int(sqrt(lowercase__						)						)
																								_lowerCamelCase	:     List[Any]       =       gcd(lowercase__				,       lowercase__						)
																								z_num //= hcf
																								z_den //= hcf
																								if 0 < z_num < z_den <= order:
																												_lowerCamelCase	:     Union[str, Any]       =       add_three(
																												    lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						)
																												unique_s.add(lowercase__						)

                    # n=-1
																				_lowerCamelCase	:     List[str]       =       x_num * y_num
																				_lowerCamelCase	:     int       =       x_den * y_num + x_num * y_den
																				_lowerCamelCase	:     Dict       =       gcd(lowercase__				,       lowercase__						)
																				z_num //= hcf
																				z_den //= hcf
																				if 0 < z_num < z_den <= order:
																								_lowerCamelCase	:     List[str]       =       add_three(
																								    lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						)
																								unique_s.add(lowercase__						)

																				# n=2
																				_lowerCamelCase	:     Tuple       =       x_num * x_num * y_num * y_num
																				_lowerCamelCase	:     List[str]       =       (
																				    x_den * x_den * y_num * y_num + x_num * x_num * y_den * y_den
																				)
																				if is_sq(lowercase__						) and is_sq(lowercase__						):
																								_lowerCamelCase	:     Optional[int]       =       int(sqrt(lowercase__						)						)
																								_lowerCamelCase	:     Optional[int]       =       int(sqrt(lowercase__						)						)
																								_lowerCamelCase	:     Dict       =       gcd(lowercase__				,       lowercase__						)
																								z_num //= hcf
																								z_den //= hcf
																								if 0 < z_num < z_den <= order:
																												_lowerCamelCase	:     int       =       add_three(
																												    lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						)
																												unique_s.add(lowercase__						)

				for num, den in unique_s:
								total += Fraction(lowercase__				,       lowercase__						)

				return total.denominator + total.numerator


if __name__ == "__main__":
			print(F"{solution() = }")