



"""simple docstring"""






from __future__ import annotations

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




class    __snake_case(					__A       ):
    _A       = 1
    _A       = 2
    _A       = 3




    def __repr__(   self			):





      '''simple docstring'''



      return F'''{self.__class__.__name__}.{self.name}'''



def 							A__ (     UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__    ):


  '''simple docstring'''


  _SCREAMING_SNAKE_CASE    ,     _SCREAMING_SNAKE_CASE        =			point
  return degrees(atana(y - miny       ,							x - minx    )    )


def 							A__ (     UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__    ):


  '''simple docstring'''


  _SCREAMING_SNAKE_CASE    ,     _SCREAMING_SNAKE_CASE        =			starting
  _SCREAMING_SNAKE_CASE    ,     _SCREAMING_SNAKE_CASE        =			via
  _SCREAMING_SNAKE_CASE    ,     _SCREAMING_SNAKE_CASE        =			target
  _SCREAMING_SNAKE_CASE        =			degrees(atana(ya - ya       ,							xa - xa    )    )
  via_angle %= 360
  _SCREAMING_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 							A__ (     UpperCamelCase__    ):


  '''simple docstring'''


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

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

  _SCREAMING_SNAKE_CASE        =			sorted(snake_case__       ,							key=lambda UpperCamelCase__    : angle_comparer(snake_case__       ,							snake_case__       ,							snake_case__    )    )
  # 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)    )

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

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

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








'''simple docstring'''







import sys
from collections.abc import Mapping

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter






class        a__     (      TensorFormatter[Mapping, np.ndarray, Mapping]    ):
     '''simple docstring'''







     def __init__(self     :						Tuple					,					lowercase__     :						Dict=None					,					**lowercase__     :						List[Any]       )	->							str:
           super().__init__(features=lowercase__       )
           __A		 =   np_array_kwargs






     def      _UpperCamelCase (self     :						int					,					lowercase__     :						Tuple       )	->							List[Any]:
           if isinstance(lowercase__					,					lowercase__       ):
                 if column and all(
                     isinstance(lowercase__					,					np.ndarray       ) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column       ):
                       return np.stack(lowercase__       )
                 else:
                       # don't use np.array(column, dtype=object)
                       # since it fails in certain cases
                       # see https://stackoverflow.com/q/51005699
                       __A		 =   np.empty(len(lowercase__       )					,					dtype=lowercase__       )
                       __A		 =   column
                       return out
           return column






     def      _UpperCamelCase (self     :						Optional[Any]					,					lowercase__     :						Optional[int]       )	->							Tuple:
           if isinstance(lowercase__					,					(str, bytes, type(lowercase__       ))       ):
                 return value
           elif isinstance(lowercase__					,					(np.character, np.ndarray)       ) and np.issubdtype(value.dtype					,					np.character       ):
                 return value
           elif isinstance(lowercase__					,					np.number       ):
                 return value

           __A		 =   {}

           if isinstance(lowercase__					,					np.ndarray       ) and np.issubdtype(value.dtype					,					np.integer       ):
                 __A		 =   {"dtype": np.intaa}
           elif isinstance(lowercase__					,					np.ndarray       ) and np.issubdtype(value.dtype					,					np.floating       ):
                 __A		 =   {"dtype": np.floataa}
           elif config.PIL_AVAILABLE and "PIL" in sys.modules:
                 import PIL.Image

                 if isinstance(lowercase__					,					PIL.Image.Image       ):
                       return np.asarray(lowercase__					,					**self.np_array_kwargs       )

           return np.asarray(lowercase__					,					**{**default_dtype, **self.np_array_kwargs}       )






     def      _UpperCamelCase (self     :						List[Any]					,					lowercase__     :						str       )	->							Optional[Any]:
           # support for torch, tf, jax etc.
           if config.TORCH_AVAILABLE and "torch" in sys.modules:
                 import torch

                 if isinstance(lowercase__					,					torch.Tensor       ):
                       return self._tensorize(data_struct.detach().cpu().numpy()[()]       )
           if hasattr(lowercase__					,					"__array__"       ) and not isinstance(lowercase__					,					(np.ndarray, np.character, np.number)       ):
                 __A		 =   data_struct.__array__()
           # support for nested types like struct of list of struct
           if isinstance(lowercase__					,					np.ndarray       ):
                 if data_struct.dtype == object:
                       return self._consolidate([self.recursive_tensorize(lowercase__       ) for substruct in data_struct]       )
           if isinstance(lowercase__					,					(list, tuple)       ):
                 return self._consolidate([self.recursive_tensorize(lowercase__       ) for substruct in data_struct]       )
           return self._tensorize(lowercase__       )






     def      _UpperCamelCase (self     :						Optional[Any]					,					lowercase__     :						dict       )	->							Dict:
           return map_nested(self._recursive_tensorize					,					lowercase__					,					map_list=lowercase__       )






     def      _UpperCamelCase (self     :						Optional[int]					,					lowercase__     :						pa.Table       )	->							Mapping:
           __A		 =   self.numpy_arrow_extractor().extract_row(lowercase__       )
           __A		 =   self.python_features_decoder.decode_row(lowercase__       )
           return self.recursive_tensorize(lowercase__       )






     def      _UpperCamelCase (self     :						List[Any]					,					lowercase__     :						pa.Table       )	->							np.ndarray:
           __A		 =   self.numpy_arrow_extractor().extract_column(lowercase__       )
           __A		 =   self.python_features_decoder.decode_column(lowercase__					,					pa_table.column_names[0]       )
           __A		 =   self.recursive_tensorize(lowercase__       )
           __A		 =   self._consolidate(lowercase__       )
           return column






     def      _UpperCamelCase (self     :						Optional[Any]					,					lowercase__     :						pa.Table       )	->							Mapping:
           __A		 =   self.numpy_arrow_extractor().extract_batch(lowercase__       )
           __A		 =   self.python_features_decoder.decode_batch(lowercase__       )
           __A		 =   self.recursive_tensorize(lowercase__       )
           for column_name in batch:
                 __A		 =   self._consolidate(batch[column_name]       )
           return batch


