





from __future__ import annotations

import unittest

from transformers import MPNetConfig, 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.mpnet.modeling_tf_mpnet import (
				    TFMPNetForMaskedLM,
				    TFMPNetForMultipleChoice,
				    TFMPNetForQuestionAnswering,
				    TFMPNetForSequenceClassification,
				    TFMPNetForTokenClassification,
				    TFMPNetModel,
				)



class  _a  :






							"""simple docstring"""

							def __init__(   self					:  int				,						a					:  Any				,						a					:  int=13				,						a					:  Tuple=7				,						a					:  int=True				,						a					:  Any=True				,						a					:  str=False				,						a					:  Dict=True				,						a					:  Dict=99				,						a					:  Optional[int]=64				,						a					:  Union[str, Any]=2				,						a					:  List[str]=4				,						a					:  List[str]=64				,						a					:  Tuple="gelu"				,						a					:  int=0.1				,						a					:  Tuple=0.1				,						a					:  Tuple=5_12				,						a					:  Dict=16				,						a					:  int=2				,						a					:  int=0.02				,						a					:  Union[str, Any]=3				,						a					:  Union[str, Any]=4				,						a					:  Dict=None				,						)						->Tuple:
													SCREAMING_SNAKE_CASE__  :					str =       parent
													SCREAMING_SNAKE_CASE__  :					Optional[int] =       batch_size
													SCREAMING_SNAKE_CASE__  :					str =       seq_length
													SCREAMING_SNAKE_CASE__  :					List[str] =       is_training
													SCREAMING_SNAKE_CASE__  :					Union[str, Any] =       use_input_mask
													SCREAMING_SNAKE_CASE__  :					List[str] =       use_token_type_ids
													SCREAMING_SNAKE_CASE__  :					Optional[int] =       use_labels
													SCREAMING_SNAKE_CASE__  :					Optional[Any] =       vocab_size
													SCREAMING_SNAKE_CASE__  :					Tuple =       hidden_size
													SCREAMING_SNAKE_CASE__  :					Union[str, Any] =       num_hidden_layers
													SCREAMING_SNAKE_CASE__  :					Optional[int] =       num_attention_heads
													SCREAMING_SNAKE_CASE__  :					Tuple =       intermediate_size
													SCREAMING_SNAKE_CASE__  :					Any =       hidden_act
													SCREAMING_SNAKE_CASE__  :					Tuple =       hidden_dropout_prob
													SCREAMING_SNAKE_CASE__  :					List[str] =       attention_probs_dropout_prob
													SCREAMING_SNAKE_CASE__  :					int =       max_position_embeddings
													SCREAMING_SNAKE_CASE__  :					Optional[int] =       type_vocab_size
													SCREAMING_SNAKE_CASE__  :					List[Any] =       type_sequence_label_size
													SCREAMING_SNAKE_CASE__  :					Union[str, Any] =       initializer_range
													SCREAMING_SNAKE_CASE__  :					Optional[int] =       num_labels
													SCREAMING_SNAKE_CASE__  :					Tuple =       num_choices
													SCREAMING_SNAKE_CASE__  :					List[str] =       scope

							def   A_	(   self					:  str     )						->List[str]:
													SCREAMING_SNAKE_CASE__  :					List[str] =       ids_tensor([self.batch_size, self.seq_length]				,						self.vocab_size     )

													SCREAMING_SNAKE_CASE__  :					Optional[Any] =       None
													if self.use_input_mask:
																			SCREAMING_SNAKE_CASE__  :					Optional[int] =       random_attention_mask([self.batch_size, self.seq_length]     )

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

													SCREAMING_SNAKE_CASE__  :					List[str] =       MPNetConfig(
													    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				,						initializer_range=self.initializer_range				,						)
													return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels

							def   A_	(   self					:  str				,						a					:  str				,						a					:  List[Any]				,						a					:  Optional[int]				,						a					:  List[str]				,						a					:  Dict				,						a					:  str     )						->Tuple:
													SCREAMING_SNAKE_CASE__  :					Union[str, Any] =       TFMPNetModel(config=__lowercase     )
													SCREAMING_SNAKE_CASE__  :					Union[str, Any] =       {"input_ids": input_ids, "attention_mask": input_mask}
													SCREAMING_SNAKE_CASE__  :					Optional[Any] =       model(__lowercase     )
													SCREAMING_SNAKE_CASE__  :					int =       [input_ids, input_mask]
													SCREAMING_SNAKE_CASE__  :					Dict =       model(__lowercase     )
													self.parent.assertEqual(result.last_hidden_state.shape				,						(self.batch_size, self.seq_length, self.hidden_size)     )

							def   A_	(   self					:  List[Any]				,						a					:  Optional[Any]				,						a					:  str				,						a					:  Tuple				,						a					:  List[str]				,						a					:  int				,						a					:  Union[str, Any]     )						->Dict:
													SCREAMING_SNAKE_CASE__  :					Any =       TFMPNetForMaskedLM(config=__lowercase     )
													SCREAMING_SNAKE_CASE__  :					List[Any] =       {"input_ids": input_ids, "attention_mask": input_mask}
													SCREAMING_SNAKE_CASE__  :					List[str] =       model(__lowercase     )
													self.parent.assertEqual(result.logits.shape				,						(self.batch_size, self.seq_length, self.vocab_size)     )

							def   A_	(   self					:  Optional[int]				,						a					:  List[Any]				,						a					:  List[str]				,						a					:  Tuple				,						a					:  Tuple				,						a					:  Dict				,						a					:  str     )						->Optional[int]:
													SCREAMING_SNAKE_CASE__  :					Optional[Any] =       TFMPNetForQuestionAnswering(config=__lowercase     )
													SCREAMING_SNAKE_CASE__  :					Any =       {
													    "input_ids": input_ids,
													    "attention_mask": input_mask,
													}
													SCREAMING_SNAKE_CASE__  :					Any =       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					:  int				,						a					:  Dict				,						a					:  str				,						a					:  List[Any]				,						a					:  Optional[int]				,						a					:  Any				,						a					:  Tuple     )						->Dict:
													SCREAMING_SNAKE_CASE__  :					List[str] =       self.num_labels
													SCREAMING_SNAKE_CASE__  :					Tuple =       TFMPNetForSequenceClassification(__lowercase     )
													SCREAMING_SNAKE_CASE__  :					List[str] =       {"input_ids": input_ids, "attention_mask": input_mask}
													SCREAMING_SNAKE_CASE__  :					Dict =       model(__lowercase     )
													self.parent.assertEqual(result.logits.shape				,						(self.batch_size, self.num_labels)     )

							def   A_	(   self					:  str				,						a					:  int				,						a					:  Union[str, Any]				,						a					:  int				,						a					:  Dict				,						a					:  Optional[int]				,						a					:  List[Any]     )						->List[str]:
													SCREAMING_SNAKE_CASE__  :					Tuple =       self.num_choices
													SCREAMING_SNAKE_CASE__  :					Union[str, Any] =       TFMPNetForMultipleChoice(__lowercase     )
													SCREAMING_SNAKE_CASE__  :					Optional[Any] =       tf.tile(tf.expand_dims(__lowercase				,						1     )				,						(1, self.num_choices, 1)     )
													SCREAMING_SNAKE_CASE__  :					Optional[Any] =       tf.tile(tf.expand_dims(__lowercase				,						1     )				,						(1, self.num_choices, 1)     )
													SCREAMING_SNAKE_CASE__  :					Union[str, Any] =       {
													    "input_ids": multiple_choice_inputs_ids,
													    "attention_mask": multiple_choice_input_mask,
													}
													SCREAMING_SNAKE_CASE__  :					Union[str, Any] =       model(__lowercase     )
													self.parent.assertEqual(result.logits.shape				,						(self.batch_size, self.num_choices)     )

							def   A_	(   self					:  Any				,						a					:  Optional[int]				,						a					:  int				,						a					:  Tuple				,						a					:  str				,						a					:  Dict				,						a					:  Optional[int]     )						->List[str]:
													SCREAMING_SNAKE_CASE__  :					Dict =       self.num_labels
													SCREAMING_SNAKE_CASE__  :					Tuple =       TFMPNetForTokenClassification(__lowercase     )
													SCREAMING_SNAKE_CASE__  :					str =       {"input_ids": input_ids, "attention_mask": input_mask}
													SCREAMING_SNAKE_CASE__  :					List[str] =       model(__lowercase     )
													self.parent.assertEqual(result.logits.shape				,						(self.batch_size, self.seq_length, self.num_labels)     )






							def   A_	(   self					:  Any     )						->Any:
													SCREAMING_SNAKE_CASE__  :					int =       self.prepare_config_and_inputs()
													((SCREAMING_SNAKE_CASE__),				(SCREAMING_SNAKE_CASE__),				(SCREAMING_SNAKE_CASE__),				(SCREAMING_SNAKE_CASE__),				(SCREAMING_SNAKE_CASE__),				(SCREAMING_SNAKE_CASE__))  :					str =       config_and_inputs
													SCREAMING_SNAKE_CASE__  :					Optional[Any] =       {"input_ids": input_ids, "attention_mask": input_mask}
													return config, inputs_dict







@require_tf
class  _a  (					__UpperCamelCase       ,				__UpperCamelCase       ,				unittest.TestCase				):






							"""simple docstring"""

							snake_case_							=    (
							    (
							        TFMPNetForMaskedLM,
							        TFMPNetForMultipleChoice,
							        TFMPNetForQuestionAnswering,
							        TFMPNetForSequenceClassification,
							        TFMPNetForTokenClassification,
							        TFMPNetModel,
							    )
							    if is_tf_available()
							    else ()
							)
							snake_case_							=    (
							    {
							        'feature-extraction': TFMPNetModel,
							        'fill-mask': TFMPNetForMaskedLM,
							        'question-answering': TFMPNetForQuestionAnswering,
							        'text-classification': TFMPNetForSequenceClassification,
							        'token-classification': TFMPNetForTokenClassification,
							        'zero-shot': TFMPNetForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							snake_case_							=    False
							snake_case_							=    False

							def   A_	(   self					:  List[str]     )						->str:
													SCREAMING_SNAKE_CASE__  :					Tuple =       TFMPNetModelTester(self     )
													SCREAMING_SNAKE_CASE__  :					Dict =       ConfigTester(self				,						config_class=__lowercase				,						hidden_size=37     )

							def   A_	(   self					:  Optional[Any]     )						->Union[str, Any]:
													self.config_tester.run_common_tests()

							def   A_	(   self					:  Any     )						->List[Any]:
													SCREAMING_SNAKE_CASE__  :					Dict =       self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_mpnet_model(*__lowercase     )

							def   A_	(   self					:  int     )						->List[Any]:
													SCREAMING_SNAKE_CASE__  :					str =       self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_mpnet_for_masked_lm(*__lowercase     )

							def   A_	(   self					:  Tuple     )						->Optional[Any]:
													SCREAMING_SNAKE_CASE__  :					List[Any] =       self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_mpnet_for_question_answering(*__lowercase     )

							def   A_	(   self					:  Union[str, Any]     )						->Optional[Any]:
													SCREAMING_SNAKE_CASE__  :					Optional[Any] =       self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_mpnet_for_sequence_classification(*__lowercase     )

							def   A_	(   self					:  str     )						->Optional[Any]:
													SCREAMING_SNAKE_CASE__  :					List[str] =       self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_mpnet_for_multiple_choice(*__lowercase     )

							def   A_	(   self					:  Any     )						->str:
													SCREAMING_SNAKE_CASE__  :					Optional[int] =       self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_mpnet_for_token_classification(*__lowercase     )






							@slow
							def   A_	(   self					:  Tuple     )						->Dict:
													for model_name in ["microsoft/mpnet-base"]:
																			SCREAMING_SNAKE_CASE__  :					List[str] =       TFMPNetModel.from_pretrained(__lowercase     )
																			self.assertIsNotNone(__lowercase     )







@require_tf
class  _a  (					unittest.TestCase				):






							"""simple docstring"""

							@slow
							def   A_	(   self					:  Optional[Any]     )						->Tuple:
													SCREAMING_SNAKE_CASE__  :					Optional[Any] =       TFMPNetModel.from_pretrained("microsoft/mpnet-base"     )
													SCREAMING_SNAKE_CASE__  :					Any =       tf.constant([[0, 1, 2, 3, 4, 5]]     )
													SCREAMING_SNAKE_CASE__  :					List[str] =       model(__lowercase     )[0]

													SCREAMING_SNAKE_CASE__  :					int =       [1, 6, 7_68]
													self.assertEqual(output.shape				,						__lowercase     )

													SCREAMING_SNAKE_CASE__  :					Optional[int] =       tf.constant(
													    [
													        [
													            [-0.106_7172, 0.0821_6473, 0.002_4543],
													            [-0.0346_5879, 0.835_4118, -0.0325_2288],
													            [-0.0656_9476, -0.1242_4111, -0.049_4436],
													        ]
													    ]     )
													tf.debugging.assert_near(output[:, :3, :3]				,						__lowercase				,						atol=1E-4     )







"""simple docstring"""



from __future__ import annotations

from math import pi, pow




def       snake_case__		(   _SCREAMING_SNAKE_CASE			)    ->float:
 if side_length < 0:
  raise ValueError("""vol_cube() only accepts non-negative values"""			)
 return pow(_SCREAMING_SNAKE_CASE       ,	3			)




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->float:
 if height < 0 or radius < 0:
  raise ValueError("""vol_spherical_cap() only accepts non-negative values"""			)
 # Volume is 1/3 pi * height squared * (3 * radius - height)
 return 1 / 3 * pi * pow(_SCREAMING_SNAKE_CASE       ,	2			) * (3 * radius - height)




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->float:
 if radius_a < 0 or radius_a < 0 or centers_distance < 0:
  raise ValueError("""vol_spheres_intersect() only accepts non-negative values"""			)
 if centers_distance == 0:
  return vol_sphere(min(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)			)

 UpperCAmelCase__ 						=				(
     (radius_a - radius_a + centers_distance)
     * (radius_a + radius_a - centers_distance)
     / (2 * centers_distance)
 )
 UpperCAmelCase__ 						=				(
     (radius_a - radius_a + centers_distance)
     * (radius_a + radius_a - centers_distance)
     / (2 * centers_distance)
 )

 return vol_spherical_cap(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			) + vol_spherical_cap(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->float:

 if radius_a <= 0 or radius_a <= 0 or centers_distance < 0:
  raise ValueError(
      """vol_spheres_union() only accepts non-negative values, non-zero radius"""			)

 if centers_distance == 0:
  return vol_sphere(max(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)			)

 return (
     vol_sphere(_SCREAMING_SNAKE_CASE			)
     + vol_sphere(_SCREAMING_SNAKE_CASE			)
     - vol_spheres_intersect(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)
 )




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->float:
 if width < 0 or height < 0 or length < 0:
  raise ValueError("""vol_cuboid() only accepts non-negative values"""			)
 return float(width * height * length			)




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->float:
 if height < 0 or area_of_base < 0:
  raise ValueError("""vol_cone() only accepts non-negative values"""			)
 return area_of_base * height / 3.0




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->float:
 if height < 0 or radius < 0:
  raise ValueError("""vol_right_circ_cone() only accepts non-negative values"""			)
 return pi * pow(_SCREAMING_SNAKE_CASE       ,	2			) * height / 3.0




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->float:
 if height < 0 or area_of_base < 0:
  raise ValueError("""vol_prism() only accepts non-negative values"""			)
 return float(area_of_base * height			)




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->float:
 if height < 0 or area_of_base < 0:
  raise ValueError("""vol_pyramid() only accepts non-negative values"""			)
 return area_of_base * height / 3.0




def       snake_case__		(   _SCREAMING_SNAKE_CASE			)    ->float:
 if radius < 0:
  raise ValueError("""vol_sphere() only accepts non-negative values"""			)
 # Volume is 4/3 * pi * radius cubed
 return 4 / 3 * pi * pow(_SCREAMING_SNAKE_CASE       ,	3			)




def       snake_case__		(   _SCREAMING_SNAKE_CASE			)    ->float:
 if radius < 0:
  raise ValueError("""vol_hemisphere() only accepts non-negative values"""			)
 # Volume is radius cubed * pi * 2/3
 return pow(_SCREAMING_SNAKE_CASE       ,	3			) * pi * 2 / 3




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->float:
 if height < 0 or radius < 0:
  raise ValueError("""vol_circular_cylinder() only accepts non-negative values"""			)
 # Volume is radius squared * height * pi
 return pow(_SCREAMING_SNAKE_CASE       ,	2			) * height * pi




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->float:
 # Volume - (outer_radius squared - inner_radius squared) * pi * height
 if inner_radius < 0 or outer_radius < 0 or height < 0:
  raise ValueError(
      """vol_hollow_circular_cylinder() only accepts non-negative values"""			)
 if outer_radius <= inner_radius:
  raise ValueError("""outer_radius must be greater than inner_radius"""			)
 return pi * (pow(_SCREAMING_SNAKE_CASE       ,	2			) - pow(_SCREAMING_SNAKE_CASE       ,	2			)) * height




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->float:
 # Volume is 1/3 * pi * height *
 #           (radius_1 squared + radius_2 squared + radius_1 * radius_2)
 if radius_a < 0 or radius_a < 0 or height < 0:
  raise ValueError("""vol_conical_frustum() only accepts non-negative values"""			)
 return (
     1
     / 3
     * pi
     * height
     * (pow(_SCREAMING_SNAKE_CASE       ,	2			) + pow(_SCREAMING_SNAKE_CASE       ,	2			) + radius_a * radius_a)
 )




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->float:
 if torus_radius < 0 or tube_radius < 0:
  raise ValueError("""vol_torus() only accepts non-negative values"""			)
 return 2 * pow(_SCREAMING_SNAKE_CASE       ,	2			) * torus_radius * pow(_SCREAMING_SNAKE_CASE       ,	2			)




def       snake_case__		(   )    ->str:
 print("""Volumes:"""			)
 print(F'''Cube: {vol_cube(2			) = }'''			)  # = 8
 print(F'''Cuboid: {vol_cuboid(2       ,	2       ,	2			) = }'''			)  # = 8
 print(F'''Cone: {vol_cone(2       ,	2			) = }'''			)  # ~= 1.33
 print(F'''Right Circular Cone: {vol_right_circ_cone(2       ,	2			) = }'''			)  # ~= 8.38
 print(F'''Prism: {vol_prism(2       ,	2			) = }'''			)  # = 4
 print(F'''Pyramid: {vol_pyramid(2       ,	2			) = }'''			)  # ~= 1.33
 print(F'''Sphere: {vol_sphere(2			) = }'''			)  # ~= 33.5
 print(F'''Hemisphere: {vol_hemisphere(2			) = }'''			)  # ~= 16.75
 print(F'''Circular Cylinder: {vol_circular_cylinder(2       ,	2			) = }'''			)  # ~= 25.1
 print(F'''Torus: {vol_torus(2       ,	2			) = }'''			)  # ~= 157.9
 print(F'''Conical Frustum: {vol_conical_frustum(2       ,	2       ,	4			) = }'''			)  # ~= 58.6
 print(F'''Spherical cap: {vol_spherical_cap(1       ,	2			) = }'''			)  # ~= 5.24
 print(F'''Spheres intersetion: {vol_spheres_intersect(2       ,	2       ,	1			) = }'''			)  # ~= 21.21
 print(F'''Spheres union: {vol_spheres_union(2       ,	2       ,	1			) = }'''			)  # ~= 45.81
 print(
     F'''Hollow Circular Cylinder: {vol_hollow_circular_cylinder(1       ,	2       ,	3			) = }'''			)  # ~= 28.3


if __name__ == "__main__":
 main()



