


def    snake_case_     (  snake_case			,							snake_case     )  ->				Optional[int]:
       return (pointa[0] - pointa[0]) ** 2 + (pointa[1] - pointa[1]) ** 2




def    snake_case_     (  snake_case			,							snake_case=0     )  ->				Optional[Any]:
       return sorted(snake_case			,							key=lambda snake_case     : x[column]     )




def    snake_case_     (  snake_case			,							snake_case			,							snake_case=float('inf'     )     )  ->				str:

       for i in range(points_counts - 1     ):
              for j in range(i + 1			,							snake_case     ):
                     lowercase__:   str  			=   euclidean_distance_sqr(points[i]			,							points[j]     )
                     if current_dis < min_dis:
                            lowercase__:   Union[str, Any]  			=   current_dis
       return min_dis




def    snake_case_     (  snake_case			,							snake_case			,							snake_case=float('inf'     )     )  ->				Any:

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




def    snake_case_     (  snake_case			,							snake_case			,							snake_case     )  ->				Optional[Any]:

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

       # recursion
       lowercase__:   Dict  			=   points_counts // 2
       lowercase__:   str  			=   closest_pair_of_points_sqr(
           snake_case			,							points_sorted_on_y[:mid]			,							snake_case     )
       lowercase__:   Optional[Any]  			=   closest_pair_of_points_sqr(
           snake_case			,							points_sorted_on_y[mid:]			,							points_counts - mid     )
       lowercase__:   Tuple  			=   min(snake_case			,							snake_case     )
       lowercase__:   str  			=   []
       for point in points_sorted_on_x:
              if abs(point[0] - points_sorted_on_x[mid][0]     ) < closest_pair_dis:
                     cross_strip.append(snake_case     )

       lowercase__:   str  			=   dis_between_closest_in_strip(
           snake_case			,							len(snake_case     )			,							snake_case     )
       return min(snake_case			,							snake_case     )




def    snake_case_     (  snake_case			,							snake_case     )  ->				List[Any]:
       lowercase__:   List[Any]  			=   column_based_sort(snake_case			,							column=0     )
       lowercase__:   Union[str, Any]  			=   column_based_sort(snake_case			,							column=1     )
       return (
           closest_pair_of_points_sqr(
               snake_case			,							snake_case			,							snake_case     )
       ) ** 0.5


if __name__ == "__main__":
 __lowerCAmelCase		       =							[(2, 3), (12, 30), (40, 50), (5, 1), (12, 10), (3, 4)]
 print('''Distance:''', closest_pair_of_points(points, len(points)))






from collections import UserDict
from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
 from PIL import Image

 from ..image_utils import load_image

if is_torch_available():
 from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING

if is_tf_available():
 from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
 from ..tf_utils import stable_softmax

__lowerCAmelCase		       =							logging.get_logger(__name__)





@add_end_docstrings(__UpperCamelCase      )
class   __a			(    __UpperCamelCase      ):
 def __init__(   self				, **lowerCAmelCase__ )					->				List[str]:




        '''simple docstring'''
        super().__init__(**lowerCAmelCase__ )

        requires_backends(self				, 'vision' )
        self.check_model_type(
            TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
            if self.framework == 'tf'
            else MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING )
 def __call__(   self				, lowerCAmelCase__				, **lowerCAmelCase__ )					->				Optional[Any]:




        '''simple docstring'''
        return super().__call__(lowerCAmelCase__				, **lowerCAmelCase__ )
 def 		SCREAMING_SNAKE_CASE__   (   self				, **lowerCAmelCase__ )					->				Dict:




        '''simple docstring'''
        lowercase__:   int  			=   {}
        if "candidate_labels" in kwargs:
               lowercase__:   Dict  			=   kwargs['candidate_labels']
        if "hypothesis_template" in kwargs:
               lowercase__:   List[Any]  			=   kwargs['hypothesis_template']

        return preprocess_params, {}, {}
 def 		SCREAMING_SNAKE_CASE__   (   self				, lowerCAmelCase__				, lowerCAmelCase__=None				, lowerCAmelCase__="This is a photo of {}." )					->				int:




        '''simple docstring'''
        lowercase__:   Optional[int]  			=   load_image(lowerCAmelCase__ )
        lowercase__:   Dict  			=   self.image_processor(images=[image]				, return_tensors=self.framework )
        lowercase__:   Tuple  			=   candidate_labels
        lowercase__:   List[str]  			=   [hypothesis_template.format(lowerCAmelCase__ ) for x in candidate_labels]
        lowercase__:   Optional[Any]  			=   self.tokenizer(lowerCAmelCase__				, return_tensors=self.framework				, padding=lowerCAmelCase__ )
        lowercase__:   str  			=   [text_inputs]
        return inputs
 def 		SCREAMING_SNAKE_CASE__   (   self				, lowerCAmelCase__ )					->				int:




        '''simple docstring'''
        lowercase__:   str  			=   model_inputs.pop('candidate_labels' )
        lowercase__:   List[str]  			=   model_inputs.pop('text_inputs' )
        if isinstance(text_inputs[0]				, lowerCAmelCase__ ):
               lowercase__:   Any  			=   text_inputs[0]
        else:
               # Batching case.
               lowercase__:   Optional[int]  			=   text_inputs[0][0]

        lowercase__:   Tuple  			=   self.model(**lowerCAmelCase__				, **lowerCAmelCase__ )

        lowercase__:   Any  			=   {
            'candidate_labels': candidate_labels,
            'logits': outputs.logits_per_image,
        }
        return model_outputs
 def 		SCREAMING_SNAKE_CASE__   (   self				, lowerCAmelCase__ )					->				Union[str, Any]:




        '''simple docstring'''
        lowercase__:   Tuple  			=   model_outputs.pop('candidate_labels' )
        lowercase__:   Dict  			=   model_outputs['logits'][0]
        if self.framework == "pt":
               lowercase__:   Optional[int]  			=   logits.softmax(dim=-1 ).squeeze(-1 )
               lowercase__:   Dict  			=   probs.tolist()
               if not isinstance(lowerCAmelCase__				, lowerCAmelCase__ ):
                      lowercase__:   Dict  			=   [scores]
        elif self.framework == "tf":
               lowercase__:   Optional[int]  			=   stable_softmax(lowerCAmelCase__				, axis=-1 )
               lowercase__:   Union[str, Any]  			=   probs.numpy().tolist()
        else:
               raise ValueError(F'Unsupported framework: {self.framework}' )

        lowercase__:   List[Any]  			=   [
            {'score': score, 'label': candidate_label}
            for score, candidate_label in sorted(zip(lowerCAmelCase__				, lowerCAmelCase__ )				, key=lambda lowerCAmelCase__ : -x[0] )
        ]
        return result


