





'''simple docstring'''






from __future__ import annotations

from collections import deque
from enum import Enum
from math import atana, degrees
from sys import maxsize




class 				UpperCAmelCase  (    snake_case_     ):
      _lowercase:    List[Any]		  =     1
      _lowercase:    Any		  =     2
      _lowercase:    Optional[int]		  =     3




      def __repr__(    self    :				str						)       ->   List[str]:
            return f"{self.__class__.__name__}.{self.name}"




def      UpperCamelCase__   (	lowerCAmelCase							,			lowerCAmelCase							,			lowerCAmelCase						):





      """simple docstring"""


      _lowerCAmelCase  ,							_lowerCAmelCase							  =							point
      return degrees(atana(y - miny							,			x - minx						)						)
def      UpperCamelCase__   (	lowerCAmelCase							,			lowerCAmelCase							,			lowerCAmelCase						):





      """simple docstring"""


      _lowerCAmelCase  ,							_lowerCAmelCase							  =							starting
      _lowerCAmelCase  ,							_lowerCAmelCase							  =							via
      _lowerCAmelCase  ,							_lowerCAmelCase							  =							target
      _lowerCAmelCase							  =							degrees(atana(ya - ya							,			xa - xa						)						)
      via_angle %= 3_60
      _lowerCAmelCase							  =							degrees(atana(ya - ya							,			xa - xa						)						)
      target_angle %= 3_60
      # 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      UpperCamelCase__   (	lowerCAmelCase						):





      """simple docstring"""


      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
      _lowerCAmelCase							  =							0
      _lowerCAmelCase  ,							_lowerCAmelCase							  =							maxsize, maxsize
      for i, point in enumerate(lowerCAmelCase						):
            _lowerCAmelCase							  =							point[0]
            _lowerCAmelCase							  =							point[1]
            if y < miny:
                  _lowerCAmelCase							  =							y
                  _lowerCAmelCase							  =							x
                  _lowerCAmelCase							  =							i
            if y == miny and x < minx:
                  _lowerCAmelCase							  =							x
                  _lowerCAmelCase							  =							i

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

      _lowerCAmelCase							  =							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)						)

      _lowerCAmelCase							  =							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.
      _lowerCAmelCase							  =							Direction.left

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

                  if next_direction == Direction.left:
                        _lowerCAmelCase							  =							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						)













'''simple docstring'''






import unittest

import numpy as np

from transformers import ElectraConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
      from transformers.models.electra.modeling_flax_electra import (
          FlaxElectraForCausalLM,
          FlaxElectraForMaskedLM,
          FlaxElectraForMultipleChoice,
          FlaxElectraForPreTraining,
          FlaxElectraForQuestionAnswering,
          FlaxElectraForSequenceClassification,
          FlaxElectraForTokenClassification,
          FlaxElectraModel,
      )




class 				UpperCAmelCase  (    unittest.TestCase     ):




      def __init__(    self    :				str    ,    __snake_case    :				str    ,    __snake_case    :				str=13    ,    __snake_case    :				Optional[Any]=7    ,    __snake_case    :				str=True    ,    __snake_case    :				Any=True    ,    __snake_case    :				List[str]=True    ,    __snake_case    :				Any=True    ,    __snake_case    :				List[str]=99    ,    __snake_case    :				Dict=24    ,    __snake_case    :				Any=32    ,    __snake_case    :				List[str]=5    ,    __snake_case    :				Any=4    ,    __snake_case    :				Optional[Any]=37    ,    __snake_case    :				Union[str, Any]="gelu"    ,    __snake_case    :				Dict=0.1    ,    __snake_case    :				int=0.1    ,    __snake_case    :				Dict=5_12    ,    __snake_case    :				List[Any]=16    ,    __snake_case    :				Dict=2    ,    __snake_case    :				str=0.02    ,    __snake_case    :				Any=4    ,    )       ->   Union[str, Any]:
            _lowerCAmelCase							  =							parent
            _lowerCAmelCase							  =							batch_size
            _lowerCAmelCase							  =							seq_length
            _lowerCAmelCase							  =							is_training
            _lowerCAmelCase							  =							use_attention_mask
            _lowerCAmelCase							  =							use_token_type_ids
            _lowerCAmelCase							  =							use_labels
            _lowerCAmelCase							  =							vocab_size
            _lowerCAmelCase							  =							hidden_size
            _lowerCAmelCase							  =							embedding_size
            _lowerCAmelCase							  =							num_hidden_layers
            _lowerCAmelCase							  =							num_attention_heads
            _lowerCAmelCase							  =							intermediate_size
            _lowerCAmelCase							  =							hidden_act
            _lowerCAmelCase							  =							hidden_dropout_prob
            _lowerCAmelCase							  =							attention_probs_dropout_prob
            _lowerCAmelCase							  =							max_position_embeddings
            _lowerCAmelCase							  =							type_vocab_size
            _lowerCAmelCase							  =							type_sequence_label_size
            _lowerCAmelCase							  =							initializer_range
            _lowerCAmelCase							  =							num_choices




      def        lowercase__					(    self    :				Optional[Any]						)       ->   Optional[Any]:
            _lowerCAmelCase							  =							ids_tensor([self.batch_size, self.seq_length]    ,    self.vocab_size						)

            _lowerCAmelCase							  =							None
            if self.use_attention_mask:
                  _lowerCAmelCase							  =							random_attention_mask([self.batch_size, self.seq_length]						)

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

            _lowerCAmelCase							  =							ElectraConfig(
                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, attention_mask




      def        lowercase__					(    self    :				Any						)       ->   Optional[int]:
            _lowerCAmelCase							  =							self.prepare_config_and_inputs()
            _lowerCAmelCase  ,							_lowerCAmelCase  ,							_lowerCAmelCase  ,							_lowerCAmelCase							  =							config_and_inputs
            _lowerCAmelCase							  =							{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
            return config, inputs_dict




@require_flax
class 				UpperCAmelCase  (    snake_case_							,	unittest.TestCase     ):
      _lowercase:    str		  =     True

      _lowercase:    Optional[Any]		  =     (
          (
              FlaxElectraModel,
              FlaxElectraForCausalLM,
              FlaxElectraForMaskedLM,
              FlaxElectraForPreTraining,
              FlaxElectraForTokenClassification,
              FlaxElectraForQuestionAnswering,
              FlaxElectraForMultipleChoice,
              FlaxElectraForSequenceClassification,
          )
          if is_flax_available()
          else ()
      )




      def        lowercase__					(    self    :				Tuple						)       ->   Optional[int]:
            _lowerCAmelCase							  =							FlaxElectraModelTester(self						)




      @slow
      def        lowercase__					(    self    :				List[Any]						)       ->   str:
            for model_class_name in self.all_model_classes:
                  if model_class_name == FlaxElectraForMaskedLM:
                        _lowerCAmelCase							  =							model_class_name.from_pretrained("""google/electra-small-generator"""						)
                  else:
                        _lowerCAmelCase							  =							model_class_name.from_pretrained("""google/electra-small-discriminator"""						)
                  _lowerCAmelCase							  =							model(np.ones((1, 1)						)						)
                  self.assertIsNotNone(__snake_case						)






