
from __future__ import annotations

from collections.abc import Iterable

class __snake_case	:
    def __init__(						self	,snake_case	,snake_case   ):



           '''simple docstring'''







           lowercase			,    lowercase							:  Optional[Any] 			=   float(snake_case   ), float(snake_case   )
    def __eq__(						self	,snake_case   ):



           '''simple docstring'''







           return self.x == other.x and self.y == other.y
    def __ne__(						self	,snake_case   ):



           '''simple docstring'''







           return not self == other
    def __gt__(						self	,snake_case   ):



           '''simple docstring'''







           if self.x > other.x:
                  return True
           elif self.x == other.x:
                  return self.y > other.y
           return False
    def __lt__(						self	,snake_case   ):



           '''simple docstring'''







           return not self > other
    def __ge__(						self	,snake_case   ):



           '''simple docstring'''







           if self.x > other.x:
                  return True
           elif self.x == other.x:
                  return self.y >= other.y
           return False
    def __le__(						self	,snake_case   ):



           '''simple docstring'''







           if self.x < other.x:
                  return True
           elif self.x == other.x:
                  return self.y <= other.y
           return False
    def __repr__(						self   ):



           '''simple docstring'''







           return f"({self.x}, {self.y})"
    def __hash__(						self   ):



           '''simple docstring'''







           return hash(self.x   )







def 		_snake_case(						SCREAMING_SNAKE_CASE__      ,			)				->					list[Point]:
       lowercase							:  list[Point] 			=   []
       if list_of_tuples:
              for p in list_of_tuples:
                     if isinstance(SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       ):
                            points.append(SCREAMING_SNAKE_CASE__       )
                     else:
                            try:
                                   points.append(Point(p[0]      ,			p[1]       )       )
                            except (IndexError, TypeError):
                                   print(
                                       f"Ignoring deformed point {p}. All points"
                                       """ must have at least 2 coordinates."""       )
       return points







def 		_snake_case(						SCREAMING_SNAKE_CASE__       )				->					list[Point]:

       if not hasattr(SCREAMING_SNAKE_CASE__      ,			"""__iter__"""       ):
              lowercase							:  Optional[Any] 			=   f"Expecting an iterable object but got an non-iterable type {points}"
              raise ValueError(SCREAMING_SNAKE_CASE__       )

       if not points:
              lowercase							:  int 			=   f"Expecting a list of points but got {points}"
              raise ValueError(SCREAMING_SNAKE_CASE__       )

       return _construct_points(SCREAMING_SNAKE_CASE__       )







def 		_snake_case(						SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )				->					float:
       lowercase							:  Dict 			=   (a.x * b.y + b.x * c.y + c.x * a.y) - (a.y * b.x + b.y * c.x + c.y * a.x)
       return det







def 		_snake_case(						SCREAMING_SNAKE_CASE__       )				->					list[Point]:
       lowercase							:  Any 			=   sorted(_validate_input(SCREAMING_SNAKE_CASE__       )       )
       lowercase							:  Dict 			=   len(SCREAMING_SNAKE_CASE__       )
       lowercase							:  List[Any] 			=   set()

       for i in range(n - 1       ):
              for j in range(i + 1      ,			SCREAMING_SNAKE_CASE__       ):
                     lowercase							:  str 			=   False
                     lowercase							:  Optional[Any] 			=   True
                     for k in range(SCREAMING_SNAKE_CASE__       ):
                            if k != i and k != j:
                                   lowercase							:  List[str] 			=   _det(points[i]      ,			points[j]      ,			points[k]       )

                                   if det_k > 0:
                                          lowercase							:  List[Any] 			=   True
                                   elif det_k < 0:
                                          lowercase							:  str 			=   True
                                   else:
                                          # point[i], point[j], point[k] all lie on a straight line
                                          # if point[k] is to the left of point[i] or it's to the
                                          # right of point[j], then point[i], point[j] cannot be
                                          # part of the convex hull of A
                                          if points[k] < points[i] or points[k] > points[j]:
                                                 lowercase							:  str 			=   False
                                                 break

                            if points_left_of_ij and points_right_of_ij:
                                   lowercase							:  Optional[int] 			=   False
                                   break

                     if ij_part_of_convex_hull:
                            convex_set.update([points[i], points[j]]       )

       return sorted(SCREAMING_SNAKE_CASE__       )







def 		_snake_case(						SCREAMING_SNAKE_CASE__       )				->					list[Point]:
       lowercase							:  Any 			=   sorted(_validate_input(SCREAMING_SNAKE_CASE__       )       )
       lowercase							:  Optional[int] 			=   len(SCREAMING_SNAKE_CASE__       )

       # divide all the points into an upper hull and a lower hull
       # the left most point and the right most point are definitely
       # members of the convex hull by definition.
       # use these two anchors to divide all the points into two hulls,
       # an upper hull and a lower hull.

       # all points to the left (above) the line joining the extreme points belong to the
       # upper hull
       # all points to the right (below) the line joining the extreme points below to the
       # lower hull
       # ignore all points on the line joining the extreme points since they cannot be
       # part of the convex hull

       lowercase							:  Tuple 			=   points[0]
       lowercase							:  Optional[Any] 			=   points[n - 1]

       lowercase							:  int 			=   {left_most_point, right_most_point}
       lowercase							:  List[Any] 			=   []
       lowercase							:  Union[str, Any] 			=   []

       for i in range(1      ,			n - 1       ):
              lowercase							:  Tuple 			=   _det(SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			points[i]       )

              if det > 0:
                     upper_hull.append(points[i]       )
              elif det < 0:
                     lower_hull.append(points[i]       )

       _construct_hull(SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )
       _construct_hull(SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )

       return sorted(SCREAMING_SNAKE_CASE__       )







def 		_snake_case(						SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )				->					None:
       if points:
              lowercase							:  Optional[int] 			=   None
              lowercase							:  Dict 			=   float("""-inf"""       )
              lowercase							:  List[str] 			=   []

              for p in points:
                     lowercase							:  List[str] 			=   _det(SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )

                     if det > 0:
                            candidate_points.append(SCREAMING_SNAKE_CASE__       )

                            if det > extreme_point_distance:
                                   lowercase							:  Optional[Any] 			=   det
                                   lowercase							:  Union[str, Any] 			=   p

              if extreme_point:
                     _construct_hull(SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )
                     convex_set.add(SCREAMING_SNAKE_CASE__       )
                     _construct_hull(SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )







def 		_snake_case(						SCREAMING_SNAKE_CASE__       )				->					list[Point]:
       lowercase							:  List[str] 			=   sorted(_validate_input(SCREAMING_SNAKE_CASE__       )       )
       lowercase							:  Union[str, Any] 			=   len(SCREAMING_SNAKE_CASE__       )

       lowercase							:  Any 			=   points[:2]
       for i in range(2      ,			SCREAMING_SNAKE_CASE__       ):
              lowercase							:  Optional[int] 			=   _det(convex_hull[1]      ,			convex_hull[0]      ,			points[i]       )
              if det > 0:
                     convex_hull.insert(0      ,			points[i]       )
                     break
              elif det < 0:
                     convex_hull.append(points[i]       )
                     break
              else:
                     lowercase							:  Any 			=   points[i]
       i += 1

       for j in range(SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       ):
              if (
                  _det(convex_hull[0]      ,			convex_hull[-1]      ,			points[j]       ) > 0
                  and _det(convex_hull[-1]      ,			convex_hull[0]      ,			points[1]       ) < 0
              ):
                     # The point lies within the convex hull
                     continue

              convex_hull.insert(0      ,			points[j]       )
              convex_hull.append(points[j]       )
              while _det(convex_hull[0]      ,			convex_hull[1]      ,			convex_hull[2]       ) >= 0:
                     del convex_hull[1]
              while _det(convex_hull[-1]      ,			convex_hull[-2]      ,			convex_hull[-3]       ) <= 0:
                     del convex_hull[-2]

    # `convex_hull` is contains the convex hull in circular order
       return sorted(convex_hull[1:] if len(SCREAMING_SNAKE_CASE__       ) > 3 else convex_hull       )







def 		_snake_case(						)				->					Any:
       lowercase							:  Optional[Any] 			=   [
           (0, 3),
           (2, 2),
           (1, 1),
           (2, 1),
           (3, 0),
           (0, 0),
           (3, 3),
           (2, -1),
           (2, -4),
           (1, -3),
       ]
       # the convex set of points is
       # [(0, 0), (0, 3), (1, -3), (2, -4), (3, 0), (3, 3)]
       lowercase							:  Any 			=   convex_hull_bf(SCREAMING_SNAKE_CASE__       )

       lowercase							:  Optional[Any] 			=   convex_hull_recursive(SCREAMING_SNAKE_CASE__       )
       assert results_bf == results_recursive

       lowercase							:  Union[str, Any] 			=   convex_hull_melkman(SCREAMING_SNAKE_CASE__       )
       assert results_bf == results_melkman

       print(SCREAMING_SNAKE_CASE__       )


if __name__ == "__main__":
  main()


import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device


if is_torch_available():
  import torch

  from transformers import XLMProphetNetForConditionalGeneration, XLMProphetNetTokenizer

@require_torch
class __snake_case	(   unittest.TestCase  ):
    @slow
    def    _SCREAMING_SNAKE_CASE (						self   ):



           '''simple docstring'''







           lowercase							:  int 			=   XLMProphetNetForConditionalGeneration.from_pretrained("""microsoft/xprophetnet-large-wiki100-cased"""   )
           model.to(snake_case   )

           # encoder-decoder outputs
           lowercase							:  List[str] 			=   torch.tensor([[17, 96208, 103471, 2]]   ).to(snake_case   )
           lowercase							:  List[str] 			=   torch.tensor(
               [[2, 250, 9953, 34, 69489, 1620, 32, 118424, 624, 210, 105, 2913, 1032, 351]]   ).to(snake_case   )
           lowercase							:  str 			=   model(
               input_ids=snake_case	,attention_mask=snake_case	,encoder_outputs=snake_case	,decoder_input_ids=snake_case   )
           lowercase							:  Tuple 			=   output[0]
           lowercase							:  int 			=   torch.Size((1, 14, 250012)   )
           self.assertEqual(output_predited_logis.shape	,snake_case   )
           lowercase							:  Union[str, Any] 			=   torch.tensor(
               [[[-6.3_986, -8.2_391, 12.5_189], [-6.3_289, -8.0_864, 12.6_211], [-6.2_418, -8.0_445, 12.7_968]]]   ).to(snake_case   )
           self.assertTrue(torch.allclose(output_predited_logis[:, :3, :3]	,snake_case	,atol=1e-4   )   )

           # encoder outputs
           lowercase							:  Tuple 			=   model.prophetnet.encoder(snake_case   )[0]
           lowercase							:  Any 			=   torch.tensor(
               [[[-1.4_260, -0.7_628, 0.8_453], [-1.4_719, -0.1_391, 0.7_807], [-1.7_678, 0.0_114, 0.4_646]]]   ).to(snake_case   )
           lowercase							:  Optional[Any] 			=   torch.Size((1, 4, 1024)   )
           self.assertEqual(encoder_outputs.shape	,snake_case   )
           self.assertTrue(torch.allclose(encoder_outputs[:, :3, :3]	,snake_case	,atol=1e-4   )   )

           # decoder outputs
           lowercase							:  Tuple 			=   model.prophetnet.decoder(
               snake_case	,encoder_hidden_states=snake_case	,)
           lowercase							:  Optional[int] 			=   decoder_outputs[1].view(1	,model.config.ngram	,14	,-1   )
           lowercase							:  Optional[int] 			=   model.lm_head(snake_case   )
           lowercase							:  List[Any] 			=   predicting_streams_logits[:, 0]
           self.assertTrue(torch.allclose(next_first_stream_logits[:, :3, :3]	,snake_case	,atol=1e-4   )   )
    @slow
    def    _SCREAMING_SNAKE_CASE (						self   ):



           '''simple docstring'''







           lowercase							:  Optional[Any] 			=   XLMProphetNetForConditionalGeneration.from_pretrained(
               """microsoft/xprophetnet-large-wiki100-cased-xglue-ntg"""   )
           model.to(snake_case   )

           lowercase							:  Optional[int] 			=   torch.tensor([[17, 96208, 103471, 2]]   ).to(snake_case   )
           lowercase							:  Dict 			=   torch.tensor(
               [[2, 250, 9953, 34, 69489, 1620, 32, 118424, 624, 210, 105, 2913, 1032, 351]]   ).to(snake_case   )
           lowercase							:  Any 			=   model(
               input_ids=snake_case	,attention_mask=snake_case	,encoder_outputs=snake_case	,decoder_input_ids=snake_case   )
           lowercase							:  Optional[int] 			=   output[0]
           lowercase							:  Dict 			=   torch.Size((1, 14, 250012)   )
           self.assertEqual(output_predited_logis.shape	,snake_case   )
           # compare the actual values for a slice.
           lowercase							:  int 			=   torch.tensor(
               [[[-9.2_253, -9.7_173, -6.3_529], [-7.6_701, -9.0_145, -1.9_382], [-8.0_195, -7.0_004, -0.1_523]]]   ).to(snake_case   )

           self.assertTrue(torch.allclose(output_predited_logis[:, :3, :3]	,snake_case	,atol=1e-4   )   )
    @slow
    def    _SCREAMING_SNAKE_CASE (						self   ):



           '''simple docstring'''







           lowercase							:  Any 			=   XLMProphetNetForConditionalGeneration.from_pretrained(
               """microsoft/xprophetnet-large-wiki100-cased-xglue-ntg"""   )
           model.to(snake_case   )
           lowercase							:  Optional[int] 			=   512

           lowercase							:  List[Any] 			=   XLMProphetNetTokenizer.from_pretrained("""microsoft/xprophetnet-large-wiki100-cased-xglue-ntg"""   )

           lowercase							:  int 			=   (
               """Microsoft Corporation intends to officially end free support for the Windows 7 operating system after"""
               """ January 14, 2020, according to the official portal of the organization. From that day, users of this"""
               """ system will not be able to receive security updates, which could make their computers vulnerable to"""
               """ cyber attacks."""
           )
           lowercase							:  List[str] 			=   (
               """орпорация Microsoft намерена официально прекратить бесплатную поддержку операционной системы Windows 7"""
               """ после 14 января 2020 года, сообщается на официальном портале организации . С указанного дня пользователи"""
               """ этой системы не смогут получать обновления безопасности, из-за чего их компьютеры могут стать уязвимыми"""
               """ к кибератакам."""
           )
           lowercase							:  str 			=   (
               """根据该组织的官方门户网站，微软公司打算在2020年1月14日之后正式终止对Windows 7操作系统的免费支持。从那时起，该系统的用户将无法接收安全更新，这可能会使他们的计算机容易受到网络攻击。"""
           )

           lowercase							:  Tuple 			=   tokenizer(
               [EN_SENTENCE, RU_SENTENCE, ZH_SENTENCE]	,padding=snake_case	,max_length=255	,return_tensors="""pt"""   ).input_ids
           lowercase							:  Union[str, Any] 			=   input_ids.to(snake_case   )

           lowercase							:  Dict 			=   model.generate(
               snake_case	,num_beams=10	,length_penalty=1.0	,no_repeat_ngram_size=3	,early_stopping=snake_case   )
           lowercase							:  Any 			=   [tokenizer.decode(snake_case	,skip_special_tokens=snake_case   ) for g in summary_ids]
           lowercase							:  Union[str, Any] 			=   """Microsoft to end Windows 7 free support after January 14, 2020"""
           lowercase							:  Tuple 			=   """Microsoft намерена прекратить бесплатную поддержку Windows 7 после 14 января 2020 года"""
           lowercase							:  Dict 			=   """微软打算终止对Windows 7操作系统的免费支持"""
           self.assertListEqual(
               [EXPECTED_TITLE_EN, EXPECTED_TITLE_RU, EXPECTED_TITLE_ZH]	,snake_case	,)

           lowercase							:  int 			=   model.generate(
               snake_case	,num_beams=1	,length_penalty=1.0	,no_repeat_ngram_size=3	,early_stopping=snake_case   )
           lowercase							:  List[Any] 			=   [
               tokenizer.convert_ids_to_tokens(snake_case	,skip_special_tokens=snake_case   ) for g in summary_ids_beama
           ]
           lowercase							:  List[str] 			=   """▁Microsoft ▁to ▁end ▁free ▁support ▁for ▁Windows ▁7""".split(""" """   )
           lowercase							:  Optional[Any] 			=   """▁Microsoft ▁намерен а ▁прекрати ть ▁бес плат ную ▁поддержку ▁Windows ▁7 ▁после ▁14 ▁января ▁2020 ▁года""".split(
               """ """   )
           lowercase							:  Optional[Any] 			=   """微软 公司 打算 终止 对 Windows ▁7 操作 系统的 免费 支持""".split(""" """   )
           self.assertListEqual(
               [EXPECTED_TITLE_EN_BEAM1_TOK, EXPECTED_TITLE_RU_BEAM1_TOK, EXPECTED_TITLE_ZH_BEAM1_TOK]	,snake_case	,)
