


from __future__ import annotations

import os







class 			snake_case__:







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__ :					Any   =							(
						    """High card""",
						    """One pair""",
						    """Two pairs""",
						    """Three of a kind""",
						    """Straight""",
						    """Flush""",
						    """Full house""",
						    """Four of a kind""",
						    """Straight flush""",
						    """Royal flush""",
						)

						SCREAMING_SNAKE_CASE__ :					int   =							(
						    """""",  # placeholder as tuples are zero-indexed
						    """One""",
						    """Two""",
						    """Three""",
						    """Four""",
						    """Five""",
						    """Six""",
						    """Seven""",
						    """Eight""",
						    """Nine""",
						    """Ten""",
						    """Jack""",
						    """Queen""",
						    """King""",
						    """Ace""",
						)




						def __init__(			self				,  __lowercase							)   ->      None:
										if not isinstance(__lowercase				,  __lowercase							):
														lowerCAmelCase_	: Optional[int]      			=			f"""Hand should be of type 'str': {hand!r}"""
														raise TypeError(__lowercase							)
										# split removes duplicate whitespaces so no need of strip
										if len(hand.split(''' '''							)							) != 5:
														lowerCAmelCase_	: str      			=			f"""Hand should contain only 5 cards: {hand!r}"""
														raise ValueError(__lowercase							)
										lowerCAmelCase_	: Optional[Any]      			=			hand
										lowerCAmelCase_	: List[Any]      			=			0
										lowerCAmelCase_	: Any      			=			0
										lowerCAmelCase_			,					lowerCAmelCase_	: Optional[int]      			=			self._internal_state()
										lowerCAmelCase_	: int      			=			self._get_hand_type()
										lowerCAmelCase_	: Union[str, Any]      			=			self._card_values[0]




						@property
						def   lowercase_	(			self							)   ->      str:
										return self._hand




						def   lowercase_	(			self				,  __lowercase							)   ->      str:
										# Breaking the tie works on the following order of precedence:
										# 1. First pair (default 0)
										# 2. Second pair (default 0)
										# 3. Compare all cards in reverse order because they are sorted.

										# First pair and second pair will only be a non-zero value if the card
										# type is either from the following:
										# 21: Four of a kind
										# 20: Full house
										# 17: Three of a kind
										# 16: Two pairs
										# 15: One pair
										if self._hand_type > other._hand_type:
														return "Win"
										elif self._hand_type < other._hand_type:
														return "Loss"
										elif self._first_pair == other._first_pair:
														if self._second_pair == other._second_pair:
																		return self._compare_cards(__lowercase							)
														else:
																		return "Win" if self._second_pair > other._second_pair else "Loss"
										return "Win" if self._first_pair > other._first_pair else "Loss"




						def   lowercase_	(			self							)   ->      str:
										lowerCAmelCase_	: Dict      			=			PokerHand._HAND_NAME[self._hand_type - 1_4]
										lowerCAmelCase_	: List[Any]      			=			PokerHand._CARD_NAME[self._high_card]
										lowerCAmelCase_	: Dict      			=			PokerHand._CARD_NAME[self._first_pair]
										lowerCAmelCase_	: List[Any]      			=			PokerHand._CARD_NAME[self._second_pair]
										if self._hand_type in [2_2, 1_9, 1_8]:
														return name + f""", {high}-high"""
										elif self._hand_type in [2_1, 1_7, 1_5]:
														return name + f""", {paira}s"""
										elif self._hand_type in [2_0, 1_6]:
														lowerCAmelCase_	: List[Any]      			=			'''over''' if self._hand_type == 2_0 else '''and'''
														return name + f""", {paira}s {join} {paira}s"""
										elif self._hand_type == 2_3:
														return name
										else:
														return name + f""", {high}"""




						def   lowercase_	(			self				,  __lowercase							)   ->      str:
										# Enumerate gives us the index as well as the element of a list
										for index, card_value in enumerate(self._card_values							):
														if card_value != other._card_values[index]:
																		return "Win" if card_value > other._card_values[index] else "Loss"
										return "Tie"




						def   lowercase_	(			self							)   ->      int:
										# Number representing the type of hand internally:
										# 23: Royal flush
										# 22: Straight flush
										# 21: Four of a kind
										# 20: Full house
										# 19: Flush
										# 18: Straight
										# 17: Three of a kind
										# 16: Two pairs
										# 15: One pair
										# 14: High card
										if self._is_flush():
														if self._is_five_high_straight() or self._is_straight():
																		return 2_3 if sum(self._card_values							) == 6_0 else 2_2
														return 1_9
										elif self._is_five_high_straight() or self._is_straight():
														return 1_8
										return 1_4 + self._is_same_kind()




						def   lowercase_	(			self							)   ->      bool:
										return len(self._card_suit							) == 1




						def   lowercase_	(			self							)   ->      bool:
										# If a card is a five high straight (low ace) change the location of
										# ace from the start of the list to the end. Check whether the first
										# element is ace or not. (Don't want to change again)
										# Five high straight (low ace): AH 2H 3S 4C 5D
										# Why use sorted here? One call to this function will mutate the list to
										# [5, 4, 3, 2, 14] and so for subsequent calls (which will be rare) we
										# need to compare the sorted version.
										# Refer test_multiple_calls_five_high_straight in test_poker_hand.py
										if sorted(self._card_values							) == [2, 3, 4, 5, 1_4]:
														if self._card_values[0] == 1_4:
																		# Remember, our list is sorted in reverse order
																		lowerCAmelCase_	: Optional[Any]      			=			self._card_values.pop(0							)
																		self._card_values.append(__lowercase							)
														return True
										return False




						def   lowercase_	(			self							)   ->      bool:
										for i in range(4							):
														if self._card_values[i] - self._card_values[i + 1] != 1:
																		return False
										return True




						def   lowercase_	(			self							)   ->      int:
										# Kind Values for internal use:
										# 7: Four of a kind
										# 6: Full house
										# 3: Three of a kind
										# 2: Two pairs
										# 1: One pair
										# 0: False
										lowerCAmelCase_	: Any      			=			0
										for i in range(4							):
														# Compare two cards at a time, if they are same increase 'kind',
														# add the value of the card to val1, if it is repeating again we
														# will add 2 to 'kind' as there are now 3 cards with same value.
														# If we get card of different value than val1, we will do the same
														# thing with val2
														if self._card_values[i] == self._card_values[i + 1]:
																		if not vala:
																						lowerCAmelCase_	: Dict      			=			self._card_values[i]
																						kind += 1
																		elif vala == self._card_values[i]:
																						kind += 2
																		elif not vala:
																						lowerCAmelCase_	: Tuple      			=			self._card_values[i]
																						kind += 1
																		elif vala == self._card_values[i]:
																						kind += 2
        # For consistency in hand type (look at note in _get_hand_type function)
										lowerCAmelCase_	: Any      			=			kind + 2 if kind in [4, 5] else kind
										# first meaning first pair to compare in 'compare_with'
										lowerCAmelCase_	: List[Any]      			=			max(__lowercase				,  __lowercase							)
										lowerCAmelCase_	: List[Any]      			=			min(__lowercase				,  __lowercase							)
										# If it's full house (three count pair + two count pair), make sure
										# first pair is three count and if not then switch them both.
										if kind == 6 and self._card_values.count(__lowercase							) != 3:
														lowerCAmelCase_			,					lowerCAmelCase_	: str      			=			second, first
										lowerCAmelCase_	: Dict      			=			first
										lowerCAmelCase_	: Any      			=			second
										return kind




						def   lowercase_	(			self							)   ->      tuple[list[int], set[str]]:
										# Internal representation of hand as a list of card values and
										# a set of card suit
										lowerCAmelCase_	: dict      			=			{"T": "10", "J": "11", "Q": "12", "K": "13", "A": "14"}
										lowerCAmelCase_	: Optional[Any]      			=			self._hand.translate(str.maketrans(__lowercase							)							).split()
										lowerCAmelCase_	: int      			=			[int(card[:-1]							) for card in new_hand]
										lowerCAmelCase_	: Any      			=			{card[-1] for card in new_hand}
										return sorted(__lowercase				,  reverse=__lowercase							), card_suit




						def __repr__(			self							)   ->      str:
										return f"""{self.__class__}(\"{self._hand}\")"""




						def __str__(			self							)   ->      int:
										return self._hand




						def __eq__(			self				,  __lowercase							)   ->      Dict:
										if isinstance(__lowercase				,  __lowercase							):
														return self.compare_with(__lowercase							) == "Tie"
										return NotImplemented




						def __lt__(			self				,  __lowercase							)   ->      Optional[Any]:
										if isinstance(__lowercase				,  __lowercase							):
														return self.compare_with(__lowercase							) == "Loss"
										return NotImplemented




						def __le__(			self				,  __lowercase							)   ->      Any:
										if isinstance(__lowercase				,  __lowercase							):
														return self < other or self == other
										return NotImplemented




						def __gt__(			self				,  __lowercase							)   ->      List[Any]:
										if isinstance(__lowercase				,  __lowercase							):
														return not self < other and self != other
										return NotImplemented




						def __ge__(			self				,  __lowercase							)   ->      str:
										if isinstance(__lowercase				,  __lowercase							):
														return not self < other
										return NotImplemented




						def __hash__(			self							)   ->      Optional[Any]:
										return object.__hash__(self							)






def      lowerCAmelCase	(						)->	int:
				# Solution for problem number 54 from Project Euler
				# Input from poker_hands.txt file
				lowerCAmelCase_	: List[str]      			=			0
				lowerCAmelCase_	: Union[str, Any]      			=			os.path.abspath(os.path.dirname(lowerCAmelCase_	)	)
				lowerCAmelCase_	: int      			=			os.path.join(lowerCAmelCase_	,				'''poker_hands.txt'''	)
				with open(lowerCAmelCase_	) as file_hand:
								for line in file_hand:
												lowerCAmelCase_	: Union[str, Any]      			=			line[:14].strip()
												lowerCAmelCase_	: Optional[Any]      			=			line[15:].strip()
												lowerCAmelCase_			,					lowerCAmelCase_	: str      			=			PokerHand(lowerCAmelCase_	), PokerHand(lowerCAmelCase_	)
												lowerCAmelCase_	: Optional[Any]      			=			player.compare_with(lowerCAmelCase_	)
												if output == "Win":
																answer += 1
				return answer


if __name__ == "__main__":
						solution()



from __future__ import annotations

import inspect
import unittest
from typing import List, Tuple

from transformers import ConvNextConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
						import tensorflow as tf

						from transformers import TFConvNextForImageClassification, TFConvNextModel


if is_vision_available():
						from PIL import Image

						from transformers import ConvNextImageProcessor







class 			snake_case__:







						'''simple docstring'''




						def __init__(			self				,  __lowercase				,  __lowercase=1_3				,  __lowercase=3_2				,  __lowercase=3				,  __lowercase=4				,  __lowercase=[1_0, 2_0, 3_0, 4_0]				,  __lowercase=[2, 2, 3, 2]				,  __lowercase=True				,  __lowercase=True				,  __lowercase=3_7				,  __lowercase="gelu"				,  __lowercase=1_0				,  __lowercase=0.02				,  __lowercase=3				,  __lowercase=None				,  )   ->      List[str]:
										lowerCAmelCase_	: List[Any]      			=			parent
										lowerCAmelCase_	: int      			=			batch_size
										lowerCAmelCase_	: Optional[int]      			=			image_size
										lowerCAmelCase_	: Dict      			=			num_channels
										lowerCAmelCase_	: Dict      			=			num_stages
										lowerCAmelCase_	: Union[str, Any]      			=			hidden_sizes
										lowerCAmelCase_	: List[Any]      			=			depths
										lowerCAmelCase_	: str      			=			is_training
										lowerCAmelCase_	: Optional[int]      			=			use_labels
										lowerCAmelCase_	: List[str]      			=			intermediate_size
										lowerCAmelCase_	: int      			=			hidden_act
										lowerCAmelCase_	: Any      			=			type_sequence_label_size
										lowerCAmelCase_	: List[Any]      			=			initializer_range
										lowerCAmelCase_	: Union[str, Any]      			=			scope




						def   lowercase_	(			self							)   ->      List[Any]:
										lowerCAmelCase_	: str      			=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

										lowerCAmelCase_	: Any      			=			None
										if self.use_labels:
														lowerCAmelCase_	: Tuple      			=			ids_tensor([self.batch_size]				,  self.type_sequence_label_size							)

										lowerCAmelCase_	: str      			=			self.get_config()

										return config, pixel_values, labels




						def   lowercase_	(			self							)   ->      str:
										return ConvNextConfig(
										    num_channels=self.num_channels				,  hidden_sizes=self.hidden_sizes				,  depths=self.depths				,  num_stages=self.num_stages				,  hidden_act=self.hidden_act				,  is_decoder=__lowercase				,  initializer_range=self.initializer_range				,  )




						def   lowercase_	(			self				,  __lowercase				,  __lowercase				,  __lowercase							)   ->      str:
										lowerCAmelCase_	: List[str]      			=			TFConvNextModel(config=__lowercase							)
										lowerCAmelCase_	: str      			=			model(__lowercase				,  training=__lowercase							)
										# expected last hidden states: B, C, H // 32, W // 32
										self.parent.assertEqual(
										    result.last_hidden_state.shape				,  (self.batch_size, self.hidden_sizes[-1], self.image_size // 3_2, self.image_size // 3_2)				,  )




						def   lowercase_	(			self				,  __lowercase				,  __lowercase				,  __lowercase							)   ->      Optional[int]:
										lowerCAmelCase_	: int      			=			self.type_sequence_label_size
										lowerCAmelCase_	: Dict      			=			TFConvNextForImageClassification(__lowercase							)
										lowerCAmelCase_	: Tuple      			=			model(__lowercase				,  labels=__lowercase				,  training=__lowercase							)
										self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.type_sequence_label_size)							)




						def   lowercase_	(			self							)   ->      Optional[Any]:
										lowerCAmelCase_	: Optional[Any]      			=			self.prepare_config_and_inputs()
										lowerCAmelCase_			,					lowerCAmelCase_			,					lowerCAmelCase_	: Optional[int]      			=			config_and_inputs
										lowerCAmelCase_	: Optional[int]      			=			{'''pixel_values''': pixel_values}
										return config, inputs_dict







@require_tf
class 			snake_case__(							UpperCAmelCase__,  UpperCAmelCase__,  unittest.TestCase							):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__ :					Optional[Any]   =							(TFConvNextModel, TFConvNextForImageClassification) if is_tf_available() else ()
						SCREAMING_SNAKE_CASE__ :					Dict   =							(
						    {"""feature-extraction""": TFConvNextModel, """image-classification""": TFConvNextForImageClassification}
						    if is_tf_available()
						    else {}
						)

						SCREAMING_SNAKE_CASE__ :					Optional[int]   =							False
						SCREAMING_SNAKE_CASE__ :					Optional[Any]   =							False
						SCREAMING_SNAKE_CASE__ :					str   =							False
						SCREAMING_SNAKE_CASE__ :					List[Any]   =							False
						SCREAMING_SNAKE_CASE__ :					Optional[Any]   =							False




						def   lowercase_	(			self							)   ->      str:
										lowerCAmelCase_	: Optional[int]      			=			TFConvNextModelTester(self							)
										lowerCAmelCase_	: Dict      			=			ConfigTester(
										    self				,  config_class=__lowercase				,  has_text_modality=__lowercase				,  hidden_size=3_7				,  )




						@unittest.skip(reason='''ConvNext does not use inputs_embeds'''							)
						def   lowercase_	(			self							)   ->      str:
										pass




						@unittest.skipIf(
						    not is_tf_available() or len(tf.config.list_physical_devices('''GPU'''							)							) == 0				,  reason='''TF does not support backprop for grouped convolutions on CPU.'''				,  )
						@slow
						def   lowercase_	(			self							)   ->      Union[str, Any]:
										super().test_keras_fit()




						@unittest.skip(reason='''ConvNext does not support input and output embeddings'''							)
						def   lowercase_	(			self							)   ->      Any:
										pass




						def   lowercase_	(			self							)   ->      Dict:
										lowerCAmelCase_			,					lowerCAmelCase_	: Dict      			=			self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
														lowerCAmelCase_	: List[str]      			=			model_class(__lowercase							)
														lowerCAmelCase_	: Dict      			=			inspect.signature(model.call							)
														# signature.parameters is an OrderedDict => so arg_names order is deterministic
														lowerCAmelCase_	: Union[str, Any]      			=			[*signature.parameters.keys()]

														lowerCAmelCase_	: int      			=			['''pixel_values''']
														self.assertListEqual(arg_names[:1]				,  __lowercase							)




						def   lowercase_	(			self							)   ->      List[str]:
										lowerCAmelCase_	: Any      			=			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*__lowercase							)




						@unittest.skipIf(
						    not is_tf_available() or len(tf.config.list_physical_devices('''GPU'''							)							) == 0				,  reason='''TF does not support backprop for grouped convolutions on CPU.'''				,  )
						def   lowercase_	(			self							)   ->      List[Any]:
										super().test_dataset_conversion()




						def   lowercase_	(			self							)   ->      List[Any]:
										def check_hidden_states_output(__lowercase				,  __lowercase				,  __lowercase							):
														lowerCAmelCase_	: Union[str, Any]      			=			model_class(__lowercase							)

														lowerCAmelCase_	: str      			=			model(**self._prepare_for_class(__lowercase				,  __lowercase							)							)
														lowerCAmelCase_	: Optional[int]      			=			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

														lowerCAmelCase_	: Any      			=			self.model_tester.num_stages
														self.assertEqual(len(__lowercase							)				,  expected_num_stages + 1							)

														# ConvNext's feature maps are of shape (batch_size, num_channels, height, width)
														self.assertListEqual(
														    list(hidden_states[0].shape[-2:]							)				,  [self.model_tester.image_size // 4, self.model_tester.image_size // 4]				,  )

										lowerCAmelCase_			,					lowerCAmelCase_	: List[Any]      			=			self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
														lowerCAmelCase_	: Tuple      			=			True
														check_hidden_states_output(__lowercase				,  __lowercase				,  __lowercase							)

														# check that output_hidden_states also work using config
														del inputs_dict["output_hidden_states"]
														lowerCAmelCase_	: str      			=			True

														check_hidden_states_output(__lowercase				,  __lowercase				,  __lowercase							)




						def   lowercase_	(			self							)   ->      Optional[int]:
										lowerCAmelCase_			,					lowerCAmelCase_	: str      			=			self.model_tester.prepare_config_and_inputs_for_common()

										def check_equivalence(__lowercase				,  __lowercase				,  __lowercase				,  __lowercase={}							):
														lowerCAmelCase_	: str      			=			model(__lowercase				,  return_dict=__lowercase				,  **__lowercase							)
														lowerCAmelCase_	: int      			=			model(__lowercase				,  return_dict=__lowercase				,  **__lowercase							).to_tuple()

														def recursive_check(__lowercase				,  __lowercase							):
																		if isinstance(__lowercase				,  (List, Tuple)							):
																						for tuple_iterable_value, dict_iterable_value in zip(__lowercase				,  __lowercase							):
																										recursive_check(__lowercase				,  __lowercase							)
																		elif tuple_object is None:
																						return
																		else:
																						self.assertTrue(
																						    all(tf.equal(__lowercase				,  __lowercase							)							)				,  msg=(
																						        '''Tuple and dict output are not equal. Difference:'''
																						        f""" {tf.math.reduce_max(tf.abs(tuple_object - dict_object							)							)}"""
																						    )				,  )

																		recursive_check(__lowercase				,  __lowercase							)

										for model_class in self.all_model_classes:
														lowerCAmelCase_	: Optional[int]      			=			model_class(__lowercase							)

														lowerCAmelCase_	: Optional[int]      			=			self._prepare_for_class(__lowercase				,  __lowercase							)
														lowerCAmelCase_	: Tuple      			=			self._prepare_for_class(__lowercase				,  __lowercase							)
														check_equivalence(__lowercase				,  __lowercase				,  __lowercase							)

														lowerCAmelCase_	: Any      			=			self._prepare_for_class(__lowercase				,  __lowercase				,  return_labels=__lowercase							)
														lowerCAmelCase_	: List[str]      			=			self._prepare_for_class(__lowercase				,  __lowercase				,  return_labels=__lowercase							)
														check_equivalence(__lowercase				,  __lowercase				,  __lowercase							)

														lowerCAmelCase_	: List[str]      			=			self._prepare_for_class(__lowercase				,  __lowercase							)
														lowerCAmelCase_	: int      			=			self._prepare_for_class(__lowercase				,  __lowercase							)
														check_equivalence(__lowercase				,  __lowercase				,  __lowercase				,  {'''output_hidden_states''': True}							)

														lowerCAmelCase_	: Any      			=			self._prepare_for_class(__lowercase				,  __lowercase				,  return_labels=__lowercase							)
														lowerCAmelCase_	: Optional[int]      			=			self._prepare_for_class(__lowercase				,  __lowercase				,  return_labels=__lowercase							)
														check_equivalence(__lowercase				,  __lowercase				,  __lowercase				,  {'''output_hidden_states''': True}							)




						def   lowercase_	(			self							)   ->      Optional[Any]:
										lowerCAmelCase_	: Dict      			=			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_classification(*__lowercase							)




						@slow
						def   lowercase_	(			self							)   ->      Union[str, Any]:
										lowerCAmelCase_	: Union[str, Any]      			=			TFConvNextModel.from_pretrained('''facebook/convnext-tiny-224'''							)
										self.assertIsNotNone(__lowercase							)






def      lowerCAmelCase	(						)->	Optional[Any]:
				lowerCAmelCase_	: Dict      			=			Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''	)
				return image







@require_tf
@require_vision
class 			snake_case__(							unittest.TestCase							):







						'''simple docstring'''




						@cached_property
						def   lowercase_	(			self							)   ->      Union[str, Any]:
										return ConvNextImageProcessor.from_pretrained('''facebook/convnext-tiny-224'''							) if is_vision_available() else None




						@slow
						def   lowercase_	(			self							)   ->      Optional[Any]:
										lowerCAmelCase_	: Union[str, Any]      			=			TFConvNextForImageClassification.from_pretrained('''facebook/convnext-tiny-224'''							)

										lowerCAmelCase_	: int      			=			self.default_image_processor
										lowerCAmelCase_	: Dict      			=			prepare_img()
										lowerCAmelCase_	: Optional[Any]      			=			image_processor(images=__lowercase				,  return_tensors='''tf'''							)

										# forward pass
										lowerCAmelCase_	: Any      			=			model(**__lowercase							)

										# verify the logits
										lowerCAmelCase_	: Union[str, Any]      			=			tf.TensorShape((1, 1_0_0_0)							)
										self.assertEqual(outputs.logits.shape				,  __lowercase							)

										lowerCAmelCase_	: List[str]      			=			tf.constant([-0.02_60, -0.47_39, 0.19_11]							)

										tf.debugging.assert_near(outputs.logits[0, :3]				,  __lowercase				,  atol=1e-4							)