



def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Tuple     ,				_SCREAMING_SNAKE_CASE   :	str				)->Optional[int]:
      return (pointa[0] - pointa[0]) ** 2 + (pointa[1] - pointa[1]) ** 2
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Dict     ,				_SCREAMING_SNAKE_CASE   :	List[str]=0				)->List[Any]:
      return sorted(_SCREAMING_SNAKE_CASE     ,				key=lambda _SCREAMING_SNAKE_CASE				: x[column]				)
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Optional[int]     ,				_SCREAMING_SNAKE_CASE   :	Dict     ,				_SCREAMING_SNAKE_CASE   :	str=float('''inf'''				)				)->Dict:

      for i in range(points_counts - 1				):
            for j in range(i + 1     ,				_SCREAMING_SNAKE_CASE				):
                  _lowerCAmelCase 			=  euclidean_distance_sqr(points[i]     ,				points[j]				)
                  if current_dis < min_dis:
                        _lowerCAmelCase 			=  current_dis
      return min_dis
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Optional[int]     ,				_SCREAMING_SNAKE_CASE   :	Dict     ,				_SCREAMING_SNAKE_CASE   :	List[str]=float('''inf'''				)				)->Union[str, Any]:

      for i in range(min(6     ,				points_counts - 1				)     ,				_SCREAMING_SNAKE_CASE				):
            for j in range(max(0     ,				i - 6				)     ,				_SCREAMING_SNAKE_CASE				):
                  _lowerCAmelCase 			=  euclidean_distance_sqr(points[i]     ,				points[j]				)
                  if current_dis < min_dis:
                        _lowerCAmelCase 			=  current_dis
      return min_dis
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Any     ,				_SCREAMING_SNAKE_CASE   :	Optional[Any]     ,				_SCREAMING_SNAKE_CASE   :	Any				)->Optional[int]:

      # base case
      if points_counts <= 3:
            return dis_between_closest_pair(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)

      # recursion
      _lowerCAmelCase 			=  points_counts // 2
      _lowerCAmelCase 			=  closest_pair_of_points_sqr(
          _SCREAMING_SNAKE_CASE     ,				points_sorted_on_y[:mid]     ,				_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  closest_pair_of_points_sqr(
          _SCREAMING_SNAKE_CASE     ,				points_sorted_on_y[mid:]     ,				points_counts - mid				)
      _lowerCAmelCase 			=  min(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  []
      for point in points_sorted_on_x:
            if abs(point[0] - points_sorted_on_x[mid][0]				) < closest_pair_dis:
                  cross_strip.append(_SCREAMING_SNAKE_CASE				)

      _lowerCAmelCase 			=  dis_between_closest_in_strip(
          _SCREAMING_SNAKE_CASE     ,				len(_SCREAMING_SNAKE_CASE				)     ,				_SCREAMING_SNAKE_CASE				)
      return min(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	str     ,				_SCREAMING_SNAKE_CASE   :	List[Any]				)->str:
      _lowerCAmelCase 			=  column_based_sort(_SCREAMING_SNAKE_CASE     ,				column=0				)
      _lowerCAmelCase 			=  column_based_sort(_SCREAMING_SNAKE_CASE     ,				column=1				)
      return (
          closest_pair_of_points_sqr(
              _SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)
      ) ** 0.5


if __name__ == "__main__":
    UpperCAmelCase_									=							[(2, 3), (1_2, 3_0), (4_0, 5_0), (5, 1), (1_2, 1_0), (3, 4)]
    print("Distance:", closest_pair_of_points(points, len(points)))











import functools
import gc
import inspect

import torch

from .imports import is_npu_available, is_xpu_available
def 							UpperCAmelCase__		(				*_SCREAMING_SNAKE_CASE   :	Tuple				)->List[Any]:
      if not isinstance(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				):
            _lowerCAmelCase 			=  list(_SCREAMING_SNAKE_CASE				)
      for i in range(len(_SCREAMING_SNAKE_CASE				)				):
            _lowerCAmelCase 			=  None
      gc.collect()
      if is_xpu_available():
            torch.xpu.empty_cache()
      elif is_npu_available():
            torch.npu.empty_cache()
      else:
            torch.cuda.empty_cache()
      return objects
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Exception				)->bool:
      _lowerCAmelCase 			=  [
          '''CUDA out of memory.''',  # CUDA OOM
          '''cuDNN error: CUDNN_STATUS_NOT_SUPPORTED.''',  # CUDNN SNAFU
          '''DefaultCPUAllocator: can\'t allocate memory''',  # CPU OOM
      ]
      if isinstance(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				) and len(exception.args				) == 1:
            return any(err in exception.args[0] for err in _statements				)
      return False


def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	callable = None     ,				_SCREAMING_SNAKE_CASE   :	int = 1_2_8				)->Optional[int]:
      if function is None:
            return functools.partial(_SCREAMING_SNAKE_CASE     ,				starting_batch_size=_SCREAMING_SNAKE_CASE				)

      _lowerCAmelCase 			=  starting_batch_size

      def decorator(*_SCREAMING_SNAKE_CASE   :	Optional[int]     ,				**_SCREAMING_SNAKE_CASE   :	Optional[Any]				):
            nonlocal batch_size
            gc.collect()
            if is_xpu_available():
                  torch.xpu.empty_cache()
            elif is_npu_available():
                  torch.npu.empty_cache()
            else:
                  torch.cuda.empty_cache()
            _lowerCAmelCase 			=  list(inspect.signature(_SCREAMING_SNAKE_CASE				).parameters.keys()				)
            # Guard against user error
            if len(_SCREAMING_SNAKE_CASE				) < (len(_SCREAMING_SNAKE_CASE				) + 1):
                  _lowerCAmelCase 			=  ''', '''.join([f'''{arg}={value}''' for arg, value in zip(params[1:]     ,				args[1:]				)]				)
                  raise TypeError(
                      f'''Batch size was passed into `{function.__name__}` as the first argument when called.'''
                      f'''Remove this as the decorator already does so: `{function.__name__}({arg_str})`'''				)
            while True:
                  if batch_size == 0:
                        raise RuntimeError('''No executable batch size found, reached zero.'''				)
                  try:
                        return function(_SCREAMING_SNAKE_CASE     ,				*_SCREAMING_SNAKE_CASE     ,				**_SCREAMING_SNAKE_CASE				)
                  except Exception as e:
                        if should_reduce_batch_size(_SCREAMING_SNAKE_CASE				):
                              gc.collect()
                              if is_xpu_available():
                                    torch.xpu.empty_cache()
                              elif is_npu_available():
                                    torch.npu.empty_cache()
                              else:
                                    torch.cuda.empty_cache()
                              batch_size //= 2
                        else:
                              raise

      return decorator