'''simple docstring'''

from __future__ import annotations

from collections.abc import Iterable




class 		SCREAMING_SNAKE_CASE_					:



			"""simple docstring"""






			def __init__(							self				,			snake_case_				,			snake_case_					):
									snake_case				,					snake_case :       List[str]				=    float(snake_case_					), float(snake_case_					)



			def __eq__(							self				,			snake_case_					):
									return self.x == other.x and self.y == other.y



			def __ne__(							self				,			snake_case_					):
									return not self == other



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



			def __lt__(							self				,			snake_case_					):
									return not self > other



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



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



			def __repr__(							self					):
									return F"""({self.x}, {self.y})"""






			def __hash__(							self					):
									return hash(self.x					)







def        UpperCAmelCase__   (				_lowerCAmelCase    :			list[Point] | list[list[float]] | Iterable[list[float]],      )    ->		list[Point]:



						"""simple docstring"""

						snake_case :       list[Point]				=    []
						if list_of_tuples:
												for p in list_of_tuples:
																		if isinstance(_lowerCAmelCase,      _lowerCAmelCase):
																								points.append(_lowerCAmelCase)
																		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        UpperCAmelCase__   (				_lowerCAmelCase    :			list[Point] | list[list[float]])    ->		list[Point]:



						"""simple docstring"""

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

						if not points:
												snake_case :       Tuple				=    f"""Expecting a list of points but got {points}"""
												raise ValueError(_lowerCAmelCase)

						return _construct_points(_lowerCAmelCase)


def        UpperCAmelCase__   (				_lowerCAmelCase    :			Point,      _lowerCAmelCase    :			Point,      _lowerCAmelCase    :			Point)    ->		float:



						"""simple docstring"""

						snake_case :       Optional[Any]				=    (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        UpperCAmelCase__   (				_lowerCAmelCase    :			list[Point])    ->		list[Point]:



						"""simple docstring"""

						snake_case :       Dict				=    sorted(_validate_input(_lowerCAmelCase))
						snake_case :       Union[str, Any]				=    len(_lowerCAmelCase)
						snake_case :       List[Any]				=    set()

						for i in range(n - 1):
												for j in range(i + 1,      _lowerCAmelCase):
																		snake_case :       str				=    False
																		snake_case :       List[str]				=    True
																		for k in range(_lowerCAmelCase):
																								if k != i and k != j:
																														snake_case :       Dict				=    _det(points[i],      points[j],      points[k])

																														if det_k > 0:
																																				snake_case :       Tuple				=    True
																														elif det_k < 0:
																																				snake_case :       int				=    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]:
																																										snake_case :       Tuple				=    False
																																										break

																								if points_left_of_ij and points_right_of_ij:
																														snake_case :       str				=    False
																														break

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

						return sorted(_lowerCAmelCase)


def        UpperCAmelCase__   (				_lowerCAmelCase    :			list[Point])    ->		list[Point]:



						"""simple docstring"""

						snake_case :       Tuple				=    sorted(_validate_input(_lowerCAmelCase))
						snake_case :       Optional[int]				=    len(_lowerCAmelCase)

						# 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

						snake_case :       Optional[int]				=    points[0]
						snake_case :       Optional[Any]				=    points[n - 1]

						snake_case :       Tuple				=    {left_most_point, right_most_point}
						snake_case :       str				=    []
						snake_case :       Optional[int]				=    []

						for i in range(1,      n - 1):
												snake_case :       Dict				=    _det(_lowerCAmelCase,      _lowerCAmelCase,      points[i])

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

						_construct_hull(_lowerCAmelCase,      _lowerCAmelCase,      _lowerCAmelCase,      _lowerCAmelCase)
						_construct_hull(_lowerCAmelCase,      _lowerCAmelCase,      _lowerCAmelCase,      _lowerCAmelCase)

						return sorted(_lowerCAmelCase)


def        UpperCAmelCase__   (				_lowerCAmelCase    :			list[Point],      _lowerCAmelCase    :			Point,      _lowerCAmelCase    :			Point,      _lowerCAmelCase    :			set[Point])    ->		None:



						"""simple docstring"""

						if points:
												snake_case :       int				=    None
												snake_case :       int				=    float("-inf")
												snake_case :       str				=    []

												for p in points:
																		snake_case :       Union[str, Any]				=    _det(_lowerCAmelCase,      _lowerCAmelCase,      _lowerCAmelCase)

																		if det > 0:
																								candidate_points.append(_lowerCAmelCase)

																								if det > extreme_point_distance:
																														snake_case :       str				=    det
																														snake_case :       List[Any]				=    p

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


def        UpperCAmelCase__   (				_lowerCAmelCase    :			list[Point])    ->		list[Point]:



						"""simple docstring"""

						snake_case :       Optional[int]				=    sorted(_validate_input(_lowerCAmelCase))
						snake_case :       str				=    len(_lowerCAmelCase)

						snake_case :       List[str]				=    points[:2]
						for i in range(2,      _lowerCAmelCase):
												snake_case :       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:
																		snake_case :       Optional[Any]				=    points[i]
						i += 1

						for j in range(_lowerCAmelCase,      _lowerCAmelCase):
												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(_lowerCAmelCase) > 3 else convex_hull)


def        UpperCAmelCase__   (				)    ->		Optional[Any]:



						"""simple docstring"""

						snake_case :       Dict				=    [
						    (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)]
						snake_case :       str				=    convex_hull_bf(_lowerCAmelCase)

						snake_case :       int				=    convex_hull_recursive(_lowerCAmelCase)
						assert results_bf == results_recursive

						snake_case :       str				=    convex_hull_melkman(_lowerCAmelCase)
						assert results_bf == results_melkman

						print(_lowerCAmelCase)


if __name__ == "__main__":
						main()






'''simple docstring'''

import unittest

import requests

from transformers import MODEL_FOR_VISION_2_SEQ_MAPPING, TF_MODEL_FOR_VISION_2_SEQ_MAPPING, is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    is_torch_available,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_torch_available():
						from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
else:
						A_	   = False


if is_vision_available():
						from PIL import Image
else:




						class 		SCREAMING_SNAKE_CASE_					:



									"""simple docstring"""






									@staticmethod
									def   lowerCamelCase (							*snake_case_				,			**snake_case_					):
															pass




@is_pipeline_test
@require_vision
class 		SCREAMING_SNAKE_CASE_					(unittest.TestCase      ):



			"""simple docstring"""






			__magic_name__ :				Optional[int]   							=       MODEL_FOR_VISION_2_SEQ_MAPPING
			__magic_name__ :				Optional[int]   							=       TF_MODEL_FOR_VISION_2_SEQ_MAPPING



			def   lowerCamelCase (							self				,			snake_case_				,			snake_case_				,			snake_case_					):
									snake_case :       str				=    pipeline("image-to-text"				,			model=snake_case_				,			tokenizer=snake_case_				,			image_processor=snake_case_					)
									snake_case :       List[Any]				=    [
									    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"					),
									    "./tests/fixtures/tests_samples/COCO/000000039769.png",
									]
									return pipe, examples



			def   lowerCamelCase (							self				,			snake_case_				,			snake_case_					):
									snake_case :       Union[str, Any]				=    pipe(snake_case_					)
									self.assertEqual(
									    snake_case_				,			[
									        [{"generated_text": ANY(snake_case_					)}],
									        [{"generated_text": ANY(snake_case_					)}],
									    ]				,			)



			@require_tf
			def   lowerCamelCase (							self					):
									snake_case :       Tuple				=    pipeline("image-to-text"				,			model="hf-internal-testing/tiny-random-vit-gpt2"				,			framework="tf"					)
									snake_case :       Union[str, Any]				=    "./tests/fixtures/tests_samples/COCO/000000039769.png"

									snake_case :       Dict				=    pipe(snake_case_					)
									self.assertEqual(
									    snake_case_				,			[
									        {
									            "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
									        },
									    ]				,			)

									snake_case :       Tuple				=    pipe([image, image]					)
									self.assertEqual(
									    snake_case_				,			[
									        [
									            {
									                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
									            }
									        ],
									        [
									            {
									                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
									            }
									        ],
									    ]				,			)

									snake_case :       List[Any]				=    pipe(snake_case_				,			max_new_tokens=1					)
									self.assertEqual(
									    snake_case_				,			[{"generated_text": "growth"}]				,			)



			@require_torch
			def   lowerCamelCase (							self					):
									snake_case :       List[Any]				=    pipeline("image-to-text"				,			model="hf-internal-testing/tiny-random-vit-gpt2"					)
									snake_case :       Tuple				=    "./tests/fixtures/tests_samples/COCO/000000039769.png"

									snake_case :       Any				=    pipe(snake_case_					)
									self.assertEqual(
									    snake_case_				,			[
									        {
									            "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
									        },
									    ]				,			)

									snake_case :       str				=    pipe([image, image]					)
									self.assertEqual(
									    snake_case_				,			[
									        [
									            {
									                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
									            }
									        ],
									        [
									            {
									                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
									            }
									        ],
									    ]				,			)



			@require_torch
			def   lowerCamelCase (							self					):
									snake_case :       Tuple				=    pipeline("image-to-text"				,			model="hf-internal-testing/tiny-random-BlipForConditionalGeneration"					)
									snake_case :       Dict				=    "./tests/fixtures/tests_samples/COCO/000000039769.png"
									snake_case :       List[Any]				=    "a photo of"

									snake_case :       List[str]				=    pipe(snake_case_				,			prompt=snake_case_					)
									self.assertTrue(outputs[0]["generated_text"].startswith(snake_case_					)					)



			@slow
			@require_torch
			def   lowerCamelCase (							self					):
									snake_case :       Optional[Any]				=    pipeline("image-to-text"				,			model="ydshieh/vit-gpt2-coco-en"					)
									snake_case :       Union[str, Any]				=    "./tests/fixtures/tests_samples/COCO/000000039769.png"

									snake_case :       Tuple				=    pipe(snake_case_					)
									self.assertEqual(snake_case_				,			[{"generated_text": "a cat laying on a blanket next to a cat laying on a bed "}]					)

									snake_case :       Tuple				=    pipe([image, image]					)
									self.assertEqual(
									    snake_case_				,			[
									        [{"generated_text": "a cat laying on a blanket next to a cat laying on a bed "}],
									        [{"generated_text": "a cat laying on a blanket next to a cat laying on a bed "}],
									    ]				,			)



			@slow
			@require_torch
			def   lowerCamelCase (							self					):
									snake_case :       Optional[Any]				=    pipeline("image-to-text"				,			model="Salesforce/blip-image-captioning-base"					)
									snake_case :       Any				=    "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
									snake_case :       Union[str, Any]				=    Image.open(requests.get(snake_case_				,			stream=snake_case_					).raw					)

									snake_case :       Optional[Any]				=    pipe(snake_case_					)
									self.assertEqual(snake_case_				,			[{"generated_text": "a pink pokemon pokemon with a blue shirt and a blue shirt"}]					)



			@slow
			@require_torch
			def   lowerCamelCase (							self					):
									snake_case :       Tuple				=    pipeline("image-to-text"				,			model="microsoft/git-base-coco"					)
									snake_case :       Tuple				=    "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
									snake_case :       Tuple				=    Image.open(requests.get(snake_case_				,			stream=snake_case_					).raw					)

									snake_case :       Any				=    pipe(snake_case_					)
									self.assertEqual(snake_case_				,			[{"generated_text": "a cartoon of a purple character."}]					)



			@slow
			@require_torch
			def   lowerCamelCase (							self					):
									snake_case :       Optional[Any]				=    pipeline("image-to-text"				,			model="Salesforce/blip-image-captioning-base"					)
									snake_case :       int				=    "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
									snake_case :       Tuple				=    Image.open(requests.get(snake_case_				,			stream=snake_case_					).raw					)

									snake_case :       str				=    "a photography of"

									snake_case :       int				=    pipe(snake_case_				,			prompt=snake_case_					)
									self.assertEqual(snake_case_				,			[{"generated_text": "a photography of a volcano"}]					)

									with self.assertRaises(snake_case_					):
															snake_case :       List[Any]				=    pipe([image, image]				,			prompt=[prompt, prompt]					)



			@slow
			@require_torch
			def   lowerCamelCase (							self					):
									snake_case :       List[str]				=    pipeline("image-to-text"				,			model="microsoft/git-base-coco"					)
									snake_case :       Optional[Any]				=    "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
									snake_case :       List[str]				=    Image.open(requests.get(snake_case_				,			stream=snake_case_					).raw					)

									snake_case :       Any				=    "a photo of a"

									snake_case :       Dict				=    pipe(snake_case_				,			prompt=snake_case_					)
									self.assertEqual(snake_case_				,			[{"generated_text": "a photo of a tent with a tent and a tent in the background."}]					)

									with self.assertRaises(snake_case_					):
															snake_case :       List[str]				=    pipe([image, image]				,			prompt=[prompt, prompt]					)



			@unittest.skipIf(
			    not is_torch_greater_or_equal_than_1_11				,			reason="`Pix2StructImageProcessor` requires `torch>=1.11.0`."					)
			@slow
			@require_torch
			def   lowerCamelCase (							self					):
									snake_case :       List[str]				=    pipeline("image-to-text"				,			model="google/pix2struct-ai2d-base"					)
									snake_case :       Optional[int]				=    "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
									snake_case :       str				=    Image.open(requests.get(snake_case_				,			stream=snake_case_					).raw					)

									snake_case :       Any				=    "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"

									snake_case :       str				=    pipe(snake_case_				,			prompt=snake_case_					)
									self.assertEqual(snake_case_				,			[{"generated_text": "ash cloud"}]					)

									with self.assertRaises(snake_case_					):
															snake_case :       List[str]				=    pipe([image, image]				,			prompt=[prompt, prompt]					)






			@slow
			@require_tf
			def   lowerCamelCase (							self					):
									snake_case :       List[str]				=    pipeline("image-to-text"				,			model="ydshieh/vit-gpt2-coco-en"				,			framework="tf"					)
									snake_case :       Union[str, Any]				=    "./tests/fixtures/tests_samples/COCO/000000039769.png"

									snake_case :       Any				=    pipe(snake_case_					)
									self.assertEqual(snake_case_				,			[{"generated_text": "a cat laying on a blanket next to a cat laying on a bed "}]					)

									snake_case :       Optional[int]				=    pipe([image, image]					)
									self.assertEqual(
									    snake_case_				,			[
									        [{"generated_text": "a cat laying on a blanket next to a cat laying on a bed "}],
									        [{"generated_text": "a cat laying on a blanket next to a cat laying on a bed "}],
									    ]				,			)





