


"""simple docstring"""
import inspect
import unittest
from typing import List

import numpy as np

from transformers import EfficientFormerConfig
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 (
				    TFEfficientFormerForImageClassification,
				    TFEfficientFormerForImageClassificationWithTeacher,
				    TFEfficientFormerModel,
				)
				from transformers.models.efficientformer.modeling_tf_efficientformer import (
				    TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
				)


if is_vision_available():
				from PIL import Image

				from transformers import EfficientFormerImageProcessor





class        snake_case__       :





							'''simple docstring'''

							def __init__(			self							: Union[str, Any]						,    UpperCAmelCase_							: Tuple						,    UpperCAmelCase_							: int = 13						,    UpperCAmelCase_							: int = 64						,    UpperCAmelCase_							: int = 2						,    UpperCAmelCase_							: int = 3						,    UpperCAmelCase_							: int = 3						,    UpperCAmelCase_							: bool = True						,    UpperCAmelCase_							: bool = True						,    UpperCAmelCase_							: int = 128						,    UpperCAmelCase_							: List[Any]=[16, 32, 64, 128]						,    UpperCAmelCase_							: int = 7						,    UpperCAmelCase_							: int = 4						,    UpperCAmelCase_							: int = 37						,    UpperCAmelCase_							: str = "gelu"						,    UpperCAmelCase_							: float = 0.1						,    UpperCAmelCase_							: float = 0.1						,    UpperCAmelCase_							: int = 10						,    UpperCAmelCase_							: float = 0.02						,    UpperCAmelCase_							: int = 2						,    UpperCAmelCase_							: int = 1						,    UpperCAmelCase_							: int = 128						,    UpperCAmelCase_							: List[int] = [2, 2, 2, 2]						,    UpperCAmelCase_							: int = 2						,    UpperCAmelCase_							: int = 2						,    )   ->str:



														"""simple docstring"""



														snake_case_          =						parent
														snake_case_          =						batch_size
														snake_case_          =						image_size
														snake_case_          =						patch_size
														snake_case_          =						num_channels
														snake_case_          =						is_training
														snake_case_          =						use_labels
														snake_case_          =						hidden_size
														snake_case_          =						num_hidden_layers
														snake_case_          =						num_attention_heads
														snake_case_          =						intermediate_size
														snake_case_          =						hidden_act
														snake_case_          =						hidden_dropout_prob
														snake_case_          =						attention_probs_dropout_prob
														snake_case_          =						type_sequence_label_size
														snake_case_          =						initializer_range
														snake_case_          =						encoder_stride
														snake_case_          =						num_attention_outputs
														snake_case_          =						embed_dim
														snake_case_          =						embed_dim + 1
														snake_case_          =						resolution
														snake_case_          =						depths
														snake_case_          =						hidden_sizes
														snake_case_          =						dim
														snake_case_          =						mlp_expansion_ratio



							def 						lowerCAmelCase    (			self							: str    )   ->Optional[Any]:



														"""simple docstring"""



														snake_case_          =						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]    )

														snake_case_          =						None
														if self.use_labels:
																					snake_case_          =						ids_tensor([self.batch_size]						,    self.type_sequence_label_size    )

														snake_case_          =						self.get_config()

														return config, pixel_values, labels



							def 						lowerCAmelCase    (			self							: Tuple    )   ->List[Any]:



														"""simple docstring"""



														return EfficientFormerConfig(
														    image_size=self.image_size						,    patch_size=self.patch_size						,    num_channels=self.num_channels						,    hidden_size=self.hidden_size						,    num_hidden_layers=self.num_hidden_layers						,    num_attention_heads=self.num_attention_heads						,    intermediate_size=self.intermediate_size						,    hidden_act=self.hidden_act						,    hidden_dropout_prob=self.hidden_dropout_prob						,    attention_probs_dropout_prob=self.attention_probs_dropout_prob						,    is_decoder=UpperCAmelCase_						,    initializer_range=self.initializer_range						,    encoder_stride=self.encoder_stride						,    resolution=self.resolution						,    depths=self.depths						,    hidden_sizes=self.hidden_sizes						,    dim=self.dim						,    mlp_expansion_ratio=self.mlp_expansion_ratio						,    )



							def 						lowerCAmelCase    (			self							: str						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: int						,    UpperCAmelCase_							: Tuple    )   ->Optional[Any]:



														"""simple docstring"""



														snake_case_          =						TFEfficientFormerModel(config=UpperCAmelCase_    )
														snake_case_          =						model(UpperCAmelCase_						,    training=UpperCAmelCase_    )
														self.parent.assertEqual(result.last_hidden_state.shape						,    (self.batch_size, self.seq_length, self.hidden_size)    )



							def 						lowerCAmelCase    (			self							: Optional[int]						,    UpperCAmelCase_							: List[Any]						,    UpperCAmelCase_							: Tuple						,    UpperCAmelCase_							: Any    )   ->List[Any]:



														"""simple docstring"""



														snake_case_          =						self.type_sequence_label_size
														snake_case_          =						TFEfficientFormerForImageClassification(UpperCAmelCase_    )
														snake_case_          =						model(UpperCAmelCase_						,    labels=UpperCAmelCase_						,    training=UpperCAmelCase_    )
														self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.type_sequence_label_size)    )

														# test greyscale images
														snake_case_          =						1
														snake_case_          =						TFEfficientFormerForImageClassification(UpperCAmelCase_    )

														snake_case_          =						floats_tensor([self.batch_size, 1, self.image_size, self.image_size]    )
														snake_case_          =						model(UpperCAmelCase_						,    labels=UpperCAmelCase_    )
														self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.type_sequence_label_size)    )



							def 						lowerCAmelCase    (			self							: Optional[int]    )   ->str:



														"""simple docstring"""



														snake_case_          =						self.prepare_config_and_inputs()
														snake_case_    ,  snake_case_    ,  snake_case_          =						config_and_inputs
														snake_case_          =						{"""pixel_values""": pixel_values}
														return config, inputs_dict





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





							'''simple docstring'''

							__lowercase:						int							 =      (
							    (
							        TFEfficientFormerModel,
							        TFEfficientFormerForImageClassificationWithTeacher,
							        TFEfficientFormerForImageClassification,
							    )
							    if is_tf_available()
							    else ()
							)
							__lowercase:						List[str]							 =      (
							    {
							        """feature-extraction""": TFEfficientFormerModel,
							        """image-classification""": (
							            TFEfficientFormerForImageClassification,
							            TFEfficientFormerForImageClassificationWithTeacher,
							        ),
							    }
							    if is_tf_available()
							    else {}
							)

							__lowercase:						Optional[int]							 =      False

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



							def 						lowerCAmelCase    (			self							: int    )   ->Union[str, Any]:



														"""simple docstring"""



														snake_case_          =						TFEfficientFormerModelTester(self    )
														snake_case_          =						ConfigTester(
														    self						,    config_class=UpperCAmelCase_						,    has_text_modality=UpperCAmelCase_						,    hidden_size=37    )



							def 						lowerCAmelCase    (			self							: Dict    )   ->Any:



														"""simple docstring"""



														self.config_tester.run_common_tests()



							@unittest.skip(reason="""EfficientFormer does not use inputs_embeds"""    )
							def 						lowerCAmelCase    (			self							: List[str]    )   ->int:



														"""simple docstring"""



														pass



							@unittest.skip(reason="""EfficientFormer does not support input and output embeddings"""    )
							def 						lowerCAmelCase    (			self							: Optional[Any]    )   ->Tuple:



														"""simple docstring"""



														pass



							def 						lowerCAmelCase    (			self							: Tuple    )   ->Tuple:



														"""simple docstring"""



														snake_case_    ,  snake_case_          =						self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					snake_case_          =						model_class(UpperCAmelCase_    )
																					snake_case_          =						inspect.signature(model.call    )
																					# signature.parameters is an OrderedDict => so arg_names order is deterministic
																					snake_case_          =						[*signature.parameters.keys()]

																					snake_case_          =						["""pixel_values"""]
																					self.assertListEqual(arg_names[:1]						,    UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: Tuple    )   ->Dict:



														"""simple docstring"""



														def check_hidden_states_output(UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: str						,    UpperCAmelCase_							: Optional[int]    ):
																					snake_case_          =						model_class(UpperCAmelCase_    )

																					snake_case_          =						model(**self._prepare_for_class(UpperCAmelCase_						,    UpperCAmelCase_    )						,    training=UpperCAmelCase_    )
																					snake_case_          =						outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

																					snake_case_          =						getattr(
																					    self.model_tester						,    """expected_num_hidden_layers"""						,    self.model_tester.num_hidden_layers + 1    )
																					self.assertEqual(len(UpperCAmelCase_    )						,    UpperCAmelCase_    )

																					if hasattr(self.model_tester						,    """encoder_seq_length"""    ):
																												snake_case_          =						self.model_tester.encoder_seq_length
																												if hasattr(self.model_tester						,    """chunk_length"""    ) and self.model_tester.chunk_length > 1:
																																			snake_case_          =						seq_length * self.model_tester.chunk_length
																					else:
																												snake_case_          =						self.model_tester.seq_length

																					self.assertListEqual(
																					    list(hidden_states[-1].shape[-2:]    )						,    [seq_length, self.model_tester.hidden_size]						,    )

																					if config.is_encoder_decoder:
																												snake_case_          =						outputs.decoder_hidden_states

																												self.asseretIsInstance(UpperCAmelCase_						,    (list, tuple)    )
																												self.assertEqual(len(UpperCAmelCase_    )						,    UpperCAmelCase_    )
																												snake_case_          =						getattr(self.model_tester						,    """seq_length"""						,    UpperCAmelCase_    )
																												snake_case_          =						getattr(self.model_tester						,    """decoder_seq_length"""						,    UpperCAmelCase_    )

																												self.assertListEqual(
																												    list(hidden_states[-1].shape[-2:]    )						,    [decoder_seq_length, self.model_tester.hidden_size]						,    )

														snake_case_    ,  snake_case_          =						self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					snake_case_          =						True
																					check_hidden_states_output(UpperCAmelCase_						,    UpperCAmelCase_						,    UpperCAmelCase_    )

																					# check that output_hidden_states also work using config
																					del inputs_dict["output_hidden_states"]
																					snake_case_          =						True

																					check_hidden_states_output(UpperCAmelCase_						,    UpperCAmelCase_						,    UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: Optional[Any]						,    UpperCAmelCase_							: List[str]						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: Dict=False    )   ->List[Any]:



														"""simple docstring"""



														snake_case_          =						super()._prepare_for_class(UpperCAmelCase_						,    UpperCAmelCase_						,    return_labels=UpperCAmelCase_    )

														if return_labels:
																					if model_class.__name__ == "TFEfficientFormerForImageClassificationWithTeacher":
																												del inputs_dict["labels"]

														return inputs_dict



							def 						lowerCAmelCase    (			self							: List[Any]    )   ->int:



														"""simple docstring"""



														snake_case_          =						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*UpperCAmelCase_    )



							@unittest.skip(reason="""EfficientFormer does not implement masked image modeling yet"""    )
							def 						lowerCAmelCase    (			self							: str    )   ->Optional[int]:



														"""simple docstring"""



														snake_case_          =						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_masked_image_modeling(*UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: Optional[Any]    )   ->Optional[int]:



														"""simple docstring"""



														snake_case_          =						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_image_classification(*UpperCAmelCase_    )



							@slow
							def 						lowerCAmelCase    (			self							: Tuple    )   ->str:



														"""simple docstring"""



														for model_name in TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					snake_case_          =						TFEfficientFormerModel.from_pretrained(UpperCAmelCase_    )
																					self.assertIsNotNone(UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: int    )   ->Optional[int]:



														"""simple docstring"""



														snake_case_    ,  snake_case_          =						self.model_tester.prepare_config_and_inputs_for_common()
														snake_case_          =						True

														snake_case_          =						getattr(self.model_tester						,    """seq_length"""						,    UpperCAmelCase_    )
														snake_case_          =						getattr(self.model_tester						,    """encoder_seq_length"""						,    UpperCAmelCase_    )
														snake_case_          =						getattr(self.model_tester						,    """key_length"""						,    UpperCAmelCase_    )
														snake_case_          =						getattr(self.model_tester						,    """chunk_length"""						,    UpperCAmelCase_    )

														if chunk_length is not None and hasattr(self.model_tester						,    """num_hashes"""    ):
																					snake_case_          =						encoder_seq_length * self.model_tester.num_hashes

														for model_class in self.all_model_classes:
																					snake_case_          =						True
																					snake_case_          =						False
																					snake_case_          =						True
																					snake_case_          =						model_class(UpperCAmelCase_    )

																					snake_case_          =						model(**self._prepare_for_class(UpperCAmelCase_						,    UpperCAmelCase_    )						,    training=UpperCAmelCase_    )
																					snake_case_          =						outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
																					self.assertEqual(len(UpperCAmelCase_    )						,    self.model_tester.num_attention_outputs    )

																					# check that output_attentions also work using config
																					del inputs_dict["output_attentions"]
																					snake_case_          =						True
																					snake_case_          =						model_class(UpperCAmelCase_    )
																					snake_case_          =						model(**self._prepare_for_class(UpperCAmelCase_						,    UpperCAmelCase_    )						,    training=UpperCAmelCase_    )

																					snake_case_          =						outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
																					self.assertEqual(len(UpperCAmelCase_    )						,    self.model_tester.num_attention_outputs    )

																					if chunk_length is not None:
																												self.assertListEqual(
																												    list(attentions[0].shape[-4:]    )						,    [self.model_tester.num_attention_heads, encoder_seq_length, chunk_length, encoder_key_length]						,    )
																					else:
																												self.assertListEqual(
																												    list(attentions[0].shape[-3:]    )						,    [self.model_tester.num_attention_heads, encoder_seq_length, encoder_key_length]						,    )



							def 						lowerCAmelCase    (			self							: Union[str, Any]    )   ->Optional[int]:



														"""simple docstring"""



														snake_case_    ,  snake_case_          =						self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					# Prepare our model
																					snake_case_          =						model_class(UpperCAmelCase_    )
																					# These are maximally general inputs for the model, with multiple None dimensions
																					# Hopefully this will catch any conditionals that fail for flexible shapes
																					snake_case_          =						{
																					    key: tf.keras.Input(shape=val.shape[1:]						,    dtype=val.dtype						,    name=UpperCAmelCase_    )
																					    for key, val in model.input_signature.items()
																					    if key in model.dummy_inputs
																					}
																					snake_case_          =						model(UpperCAmelCase_    )
																					self.assertTrue(outputs_dict is not None    )







def   _a			( )      ->			List[str]:
							snake_case_          =						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 						lowerCAmelCase    (			self							: Tuple    )   ->Any:



														"""simple docstring"""



														return (
														    EfficientFormerImageProcessor.from_pretrained("""snap-research/efficientformer-l1-300"""    )
														    if is_vision_available()
														    else None
														)



							@slow
							def 						lowerCAmelCase    (			self							: Tuple    )   ->Dict:



														"""simple docstring"""



														snake_case_          =						TFEfficientFormerForImageClassification.from_pretrained("""snap-research/efficientformer-l1-300"""    )
														snake_case_          =						self.default_image_processor
														snake_case_          =						prepare_img()
														snake_case_          =						image_processor(images=UpperCAmelCase_						,    return_tensors="""tf"""    )
														# forward pass
														snake_case_          =						model(**UpperCAmelCase_						,    training=UpperCAmelCase_    )
														# verify the logits
														snake_case_          =						tf.TensorShape((1, 1_000)    )
														self.assertEqual(outputs.logits.shape						,    UpperCAmelCase_    )
														snake_case_          =						tf.constant([-0.0_555, 0.4_825, -0.0_852]    )
														self.assertTrue(np.allclose(outputs.logits[0, :3]						,    UpperCAmelCase_						,    atol=1E-4    )    )



							@slow
							def 						lowerCAmelCase    (			self							: List[Any]    )   ->Optional[int]:



														"""simple docstring"""



														snake_case_          =						TFEfficientFormerForImageClassificationWithTeacher.from_pretrained(
														    """snap-research/efficientformer-l1-300"""    )
														snake_case_          =						self.default_image_processor
														snake_case_          =						prepare_img()
														snake_case_          =						image_processor(images=UpperCAmelCase_						,    return_tensors="""tf"""    )
														# forward pass
														snake_case_          =						model(**UpperCAmelCase_						,    training=UpperCAmelCase_    )
														# verify the logits
														snake_case_          =						tf.TensorShape((1, 1_000)    )
														self.assertEqual(outputs.logits.shape						,    UpperCAmelCase_    )
														snake_case_          =						tf.constant([-0.1_312, 0.4_353, -1.0_499]    )
														self.assertTrue(np.allclose(outputs.logits[0, :3]						,    UpperCAmelCase_						,    atol=1E-4    )    )







"""simple docstring"""
def   _a			( _SCREAMING_SNAKE_CASE			)      ->			list:

							if len(_SCREAMING_SNAKE_CASE			) <= 1:
														return [tuple(_SCREAMING_SNAKE_CASE			)]

							snake_case_          =						[]

							def generate(_SCREAMING_SNAKE_CASE			,	_SCREAMING_SNAKE_CASE			):
														if k == 1:
																					res.append(tuple(arr[:]			)			)
																					return

														generate(k - 1			,	_SCREAMING_SNAKE_CASE			)

														for i in range(k - 1			):
																					if k % 2 == 0:  # k is even
																												snake_case_    ,  snake_case_          =						arr[k - 1], arr[i]
																					else:  # k is odd
																												snake_case_    ,  snake_case_          =						arr[k - 1], arr[0]
																					generate(k - 1			,	_SCREAMING_SNAKE_CASE			)

							generate(len(_SCREAMING_SNAKE_CASE			)			,	_SCREAMING_SNAKE_CASE			)
							return res


if __name__ == "__main__":
				__SCREAMING_SNAKE_CASE							:      List[Any]						=      input('Enter numbers separated by a comma:\n').strip()
				__SCREAMING_SNAKE_CASE							:      str						=      [int(item) for item in user_input.split(',')]
				print(heaps(arr))



