




"""simple docstring"""

from __future__ import annotations

import unittest

from transformers import AlbertConfig, is_tf_available
from transformers.models.auto import get_values
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 TF_MODEL_FOR_PRETRAINING_MAPPING
		from transformers.models.albert.modeling_tf_albert import (
		    TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFAlbertForMaskedLM,
		    TFAlbertForMultipleChoice,
		    TFAlbertForPreTraining,
		    TFAlbertForQuestionAnswering,
		    TFAlbertForSequenceClassification,
		    TFAlbertForTokenClassification,
		    TFAlbertModel,
		)
class     A__      :




	def __init__(   self  :	int      ,    lowercase  :	List[str]      ,    lowercase  :	Tuple=13      ,    lowercase  :	Any=7      ,    lowercase  :	List[Any]=True      ,    lowercase  :	Optional[Any]=True      ,    lowercase  :	List[str]=True      ,    lowercase  :	Union[str, Any]=True      ,    lowercase  :	Optional[Any]=99      ,    lowercase  :	Any=16      ,    lowercase  :	Optional[int]=32      ,    lowercase  :	List[Any]=2      ,    lowercase  :	Tuple=4      ,    lowercase  :	Any=37      ,    lowercase  :	Union[str, Any]="gelu"      ,    lowercase  :	Optional[Any]=0.1      ,    lowercase  :	Optional[Any]=0.1      ,    lowercase  :	str=512      ,    lowercase  :	List[Any]=16      ,    lowercase  :	Optional[Any]=2      ,    lowercase  :	List[Any]=0.02      ,    lowercase  :	List[str]=3      ,    lowercase  :	Any=4      ,    lowercase  :	Optional[int]=None      ,    )					-> Any:
						__snake_case          =	parent
						__snake_case          =	13
						__snake_case          =	7
						__snake_case          =	True
						__snake_case          =	True
						__snake_case          =	True
						__snake_case          =	True
						__snake_case          =	99
						__snake_case          =	16
						__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




	def 							a_		(   self  :	Union[str, Any]	)					-> List[Any]:
						__snake_case          =	ids_tensor([self.batch_size, self.seq_length]      ,    self.vocab_size	)

						__snake_case          =	None
						if self.use_input_mask:
											__snake_case          =	random_attention_mask([self.batch_size, self.seq_length]	)

						__snake_case          =	None
						if self.use_token_type_ids:
											__snake_case          =	ids_tensor([self.batch_size, self.seq_length]      ,    self.type_vocab_size	)

						__snake_case          =	None
						__snake_case          =	None
						__snake_case          =	None
						if self.use_labels:
											__snake_case          =	ids_tensor([self.batch_size]      ,    self.type_sequence_label_size	)
											__snake_case          =	ids_tensor([self.batch_size, self.seq_length]      ,    self.num_labels	)
											__snake_case          =	ids_tensor([self.batch_size]      ,    self.num_choices	)

						__snake_case          =	AlbertConfig(
						    vocab_size=self.vocab_size      ,    hidden_size=self.hidden_size      ,    embedding_size=self.embedding_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 config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels




	def 							a_		(   self  :	Tuple      ,    lowercase  :	Union[str, Any]      ,    lowercase  :	str      ,    lowercase  :	Optional[int]      ,    lowercase  :	Optional[Any]      ,    lowercase  :	Optional[int]      ,    lowercase  :	List[str]      ,    lowercase  :	Tuple	)					-> Dict:
						__snake_case          =	TFAlbertModel(config=lowercase	)
						# inputs = {'input_ids': input_ids,
						#           'attention_mask': input_mask,
						#           'token_type_ids': token_type_ids}
						# sequence_output, pooled_output = model(**inputs)
						__snake_case          =	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						__snake_case          =	model(lowercase	)

						__snake_case          =	[input_ids, input_mask]
						__snake_case          =	model(lowercase	)

						__snake_case          =	model(lowercase	)

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




	def 							a_		(   self  :	Optional[int]      ,    lowercase  :	Union[str, Any]      ,    lowercase  :	Tuple      ,    lowercase  :	int      ,    lowercase  :	Any      ,    lowercase  :	Dict      ,    lowercase  :	List[str]      ,    lowercase  :	Optional[Any]	)					-> Optional[Any]:
						__snake_case          =	self.num_labels
						__snake_case          =	TFAlbertForPreTraining(config=lowercase	)
						__snake_case          =	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						__snake_case          =	model(lowercase	)
						self.parent.assertEqual(result.prediction_logits.shape      ,    (self.batch_size, self.seq_length, self.vocab_size)	)
						self.parent.assertEqual(result.sop_logits.shape      ,    (self.batch_size, self.num_labels)	)




	def 							a_		(   self  :	Any      ,    lowercase  :	Optional[int]      ,    lowercase  :	Any      ,    lowercase  :	Any      ,    lowercase  :	Any      ,    lowercase  :	List[Any]      ,    lowercase  :	List[Any]      ,    lowercase  :	str	)					-> Tuple:
						__snake_case          =	TFAlbertForMaskedLM(config=lowercase	)
						__snake_case          =	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						__snake_case          =	model(lowercase	)
						self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.vocab_size)	)




	def 							a_		(   self  :	Any      ,    lowercase  :	Any      ,    lowercase  :	Optional[int]      ,    lowercase  :	Any      ,    lowercase  :	Any      ,    lowercase  :	Tuple      ,    lowercase  :	Dict      ,    lowercase  :	List[str]	)					-> Any:
						__snake_case          =	self.num_labels
						__snake_case          =	TFAlbertForSequenceClassification(config=lowercase	)
						__snake_case          =	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						__snake_case          =	model(lowercase	)
						self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.num_labels)	)




	def 							a_		(   self  :	Any      ,    lowercase  :	Any      ,    lowercase  :	int      ,    lowercase  :	Dict      ,    lowercase  :	Any      ,    lowercase  :	str      ,    lowercase  :	Tuple      ,    lowercase  :	Tuple	)					-> Optional[Any]:
						__snake_case          =	TFAlbertForQuestionAnswering(config=lowercase	)
						__snake_case          =	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						__snake_case          =	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  :	Tuple      ,    lowercase  :	List[Any]      ,    lowercase  :	int      ,    lowercase  :	Optional[Any]      ,    lowercase  :	int      ,    lowercase  :	Dict      ,    lowercase  :	Union[str, Any]      ,    lowercase  :	Union[str, Any]	)					-> Optional[int]:
						__snake_case          =	self.num_choices
						__snake_case          =	TFAlbertForMultipleChoice(config=lowercase	)
						__snake_case          =	tf.tile(tf.expand_dims(lowercase      ,    1	)      ,    (1, self.num_choices, 1)	)
						__snake_case          =	tf.tile(tf.expand_dims(lowercase      ,    1	)      ,    (1, self.num_choices, 1)	)
						__snake_case          =	tf.tile(tf.expand_dims(lowercase      ,    1	)      ,    (1, self.num_choices, 1)	)
						__snake_case          =	{
						    """input_ids""": multiple_choice_inputs_ids,
						    """attention_mask""": multiple_choice_input_mask,
						    """token_type_ids""": multiple_choice_token_type_ids,
						}
						__snake_case          =	model(lowercase	)
						self.parent.assertListEqual(list(result["""logits"""].shape	)      ,    [self.batch_size, self.num_choices]	)




	def 							a_		(   self  :	Optional[Any]      ,    lowercase  :	Tuple      ,    lowercase  :	Optional[int]      ,    lowercase  :	Dict      ,    lowercase  :	List[str]      ,    lowercase  :	Tuple      ,    lowercase  :	Dict      ,    lowercase  :	List[str]	)					-> Dict:
						__snake_case          =	self.num_labels
						__snake_case          =	TFAlbertForTokenClassification(config=lowercase	)
						__snake_case          =	{
						    """input_ids""": input_ids,
						    """attention_mask""": input_mask,
						    """token_type_ids""": token_type_ids,
						}
						__snake_case          =	model(lowercase	)
						self.parent.assertListEqual(list(result["""logits"""].shape	)      ,    [self.batch_size, self.seq_length, self.num_labels]	)




	def 							a_		(   self  :	Optional[int]	)					-> List[str]:
						__snake_case          =	self.prepare_config_and_inputs()
						(
						    (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      
						)          =	config_and_inputs
						__snake_case          =	{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
						return config, inputs_dict

@require_tf
class     A__      (      lowercase_     ,	lowercase_     ,	unittest.TestCase     ):
	A_							:				List[Any]						     =      (
	    (
	        TFAlbertModel,
	        TFAlbertForPreTraining,
	        TFAlbertForMaskedLM,
	        TFAlbertForSequenceClassification,
	        TFAlbertForQuestionAnswering,
	        TFAlbertForTokenClassification,
	        TFAlbertForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	A_							:				int						     =      (
	    {
	        """feature-extraction""": TFAlbertModel,
	        """fill-mask""": TFAlbertForMaskedLM,
	        """question-answering""": TFAlbertForQuestionAnswering,
	        """text-classification""": TFAlbertForSequenceClassification,
	        """token-classification""": TFAlbertForTokenClassification,
	        """zero-shot""": TFAlbertForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	A_							:				str						     =      False
	A_							:				Optional[int]						     =      False




	def 							a_		(   self  :	Tuple      ,    lowercase  :	Tuple      ,    lowercase  :	List[str]      ,    lowercase  :	str=False	)					-> List[Any]:
						__snake_case          =	super()._prepare_for_class(lowercase      ,    lowercase      ,    return_labels=lowercase	)

						if return_labels:
											if model_class in get_values(lowercase	):
																__snake_case          =	tf.zeros(self.model_tester.batch_size      ,    dtype=tf.intaa	)

						return inputs_dict




	def 							a_		(   self  :	Optional[int]	)					-> List[Any]:
						__snake_case          =	TFAlbertModelTester(self	)
						__snake_case          =	ConfigTester(self      ,    config_class=lowercase      ,    hidden_size=37	)




	def 							a_		(   self  :	Any	)					-> List[str]:
						self.config_tester.run_common_tests()




	def 							a_		(   self  :	str	)					-> Dict:
						__snake_case          =	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_albert_model(*lowercase	)




	def 							a_		(   self  :	Dict	)					-> Optional[int]:
						__snake_case          =	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_albert_for_pretraining(*lowercase	)




	def 							a_		(   self  :	Union[str, Any]	)					-> Dict:
						__snake_case          =	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_albert_for_masked_lm(*lowercase	)




	def 							a_		(   self  :	Union[str, Any]	)					-> List[Any]:
						__snake_case          =	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_albert_for_multiple_choice(*lowercase	)




	def 							a_		(   self  :	Optional[int]	)					-> List[str]:
						__snake_case          =	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_albert_for_sequence_classification(*lowercase	)




	def 							a_		(   self  :	List[Any]	)					-> Optional[Any]:
						__snake_case          =	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_albert_for_question_answering(*lowercase	)




	@slow
	def 							a_		(   self  :	Tuple	)					-> List[str]:
						for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__snake_case          =	TFAlbertModel.from_pretrained(lowercase	)
											self.assertIsNotNone(lowercase	)

@require_tf
class     A__      (      unittest.TestCase     ):




	@slow
	def 							a_		(   self  :	Union[str, Any]	)					-> Tuple:
						__snake_case          =	TFAlbertForPreTraining.from_pretrained("""albert-base-v2"""	)
						__snake_case          =	tf.constant([[0, 1, 2, 3, 4, 5]]	)
						__snake_case          =	model(lowercase	)[0]

						__snake_case          =	[1, 6, 30_000]
						self.assertEqual(output.shape      ,    lowercase	)

						__snake_case          =	tf.constant(
						    [
						        [
						            [4.59_56_68, 0.74_46_27_54, -1.81_81_47],
						            [4.5_95_43_47, 0.7_45_41_84, -1.8_18_82_58],
						            [4.5_95_49_05, 0.7_44_82_35, -1.8_18_23_16],
						        ]
						    ]	)
						tf.debugging.assert_near(output[:, :3, :3]      ,    lowercase      ,    atol=1e-4	)








"""simple docstring"""

from __future__ import annotations

from collections import deque
from enum import Enum
from math import atana, degrees
from sys import maxsize
class     A__      (      lowercase_     ):
	A_							:				Tuple						     =      1
	A_							:				Union[str, Any]						     =      2
	A_							:				Union[str, Any]						     =      3




	def __repr__(   self  :	Dict	)					-> Union[str, Any]:
						return f'''{self.__class__.__name__}.{self.name}'''




def       snake_case__	(       lowerCAmelCase   :		tuple[int, int]				,					lowerCAmelCase   :		int				,					lowerCAmelCase   :		int		):
					__snake_case      ,      __snake_case          =	point
					return degrees(atana(y - miny				,					x - minx		)		)




def       snake_case__	(       lowerCAmelCase   :		tuple[int, int]				,					lowerCAmelCase   :		tuple[int, int]				,					lowerCAmelCase   :		tuple[int, int]		):
					__snake_case      ,      __snake_case          =	starting
					__snake_case      ,      __snake_case          =	via
					__snake_case      ,      __snake_case          =	target
					__snake_case          =	degrees(atana(ya - ya				,					xa - xa		)		)
					via_angle %= 360
					__snake_case          =	degrees(atana(ya - ya				,					xa - xa		)		)
					target_angle %= 360
					# t-
					#  \ \
					#   \ v
					#    \|
					#     s
					# via_angle is always lower than target_angle, if direction is left.
					# If they are same, it means they are on a same line of convex hull.
					if target_angle > via_angle:
										return Direction.left
					elif target_angle == via_angle:
										return Direction.straight
					else:
										return Direction.right




def       snake_case__	(       lowerCAmelCase   :		list[tuple[int, int]]		):

					if len(lowerCAmelCase		) <= 2:
										# There is no convex hull
										raise ValueError("""graham_scan: argument must contain more than 3 points."""		)
					if len(lowerCAmelCase		) == 3:
										return points
					# find the lowest and the most left point
					__snake_case          =	0
					__snake_case      ,      __snake_case          =	maxsize, maxsize
					for i, point in enumerate(lowerCAmelCase		):
										__snake_case          =	point[0]
										__snake_case          =	point[1]
										if y < miny:
															__snake_case          =	y
															__snake_case          =	x
															__snake_case          =	i
										if y == miny and x < minx:
															__snake_case          =	x
															__snake_case          =	i

    # remove the lowest and the most left point from points for preparing for sort
					points.pop(lowerCAmelCase		)

					__snake_case          =	sorted(lowerCAmelCase				,					key=lambda lowerCAmelCase		: angle_comparer(lowerCAmelCase				,					lowerCAmelCase				,					lowerCAmelCase		)		)
					# This insert actually costs complexity,
					# and you should instead add (minx, miny) into stack later.
					# I'm using insert just for easy understanding.
					sorted_points.insert(0				,					(minx, miny)		)

					__snake_case          =	deque()
					stack.append(sorted_points[0]		)
					stack.append(sorted_points[1]		)
					stack.append(sorted_points[2]		)
					# In any ways, the first 3 points line are towards left.
					# Because we sort them the angle from minx, miny.
					__snake_case          =	Direction.left

					for i in range(3				,					len(lowerCAmelCase		)		):
										while True:
															__snake_case          =	stack[-2]
															__snake_case          =	stack[-1]
															__snake_case          =	sorted_points[i]
															__snake_case          =	check_direction(lowerCAmelCase				,					lowerCAmelCase				,					lowerCAmelCase		)

															if next_direction == Direction.left:
																				__snake_case          =	Direction.left
																				break
															if next_direction == Direction.straight:
																				if current_direction == Direction.left:
																									# We keep current_direction as left.
																									# Because if the straight line keeps as straight,
																									# we want to know if this straight line is towards left.
																									break
																				elif current_direction == Direction.right:
																									# If the straight line is towards right,
																									# every previous points on those straigh line is not convex hull.
																									stack.pop()
															if next_direction == Direction.right:
																				stack.pop()
										stack.append(sorted_points[i]		)
					return list(lowerCAmelCase		)


