
'''simple docstring'''

import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import MobileNetVaForImageClassification, MobileNetVaModel
    from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
    from PIL import Image

    from transformers import MobileNetVaImageProcessor


class  _UpperCAmelCase ( lowerCAmelCase__    ):

     """simple docstring"""

     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       a_      :	Any      =							self.config_class(**self.inputs_dict )
       self.parent.assertTrue(hasattr(lowerCAmelCase_							,		"""tf_padding""" ) )
       self.parent.assertTrue(hasattr(lowerCAmelCase_							,		"""depth_multiplier""" ) )







class  _UpperCAmelCase :

     """simple docstring"""

     def __init__(      self							,		lowerCAmelCase_							,		lowerCAmelCase_=13							,		lowerCAmelCase_=3							,		lowerCAmelCase_=32							,		lowerCAmelCase_=0.25							,		lowerCAmelCase_=8							,		lowerCAmelCase_=True							,		lowerCAmelCase_=10_24							,		lowerCAmelCase_=32							,		lowerCAmelCase_="relu6"							,		lowerCAmelCase_=0.1							,		lowerCAmelCase_=0.02							,		lowerCAmelCase_=True							,		lowerCAmelCase_=True							,		lowerCAmelCase_=10							,		lowerCAmelCase_=None							,		):

       '''simple docstring'''

       a_      :	List[Any]      =							parent
       a_      :	Optional[int]      =							batch_size
       a_      :	Tuple      =							num_channels
       a_      :	List[str]      =							image_size
       a_      :	Any      =							depth_multiplier
       a_      :	Tuple      =							min_depth
       a_      :	Dict      =							tf_padding
       a_      :	Optional[int]      =							int(last_hidden_size * depth_multiplier )
       a_      :	Tuple      =							output_stride
       a_      :	Union[str, Any]      =							hidden_act
       a_      :	List[str]      =							classifier_dropout_prob
       a_      :	str      =							use_labels
       a_      :	Tuple      =							is_training
       a_      :	Optional[int]      =							num_labels
       a_      :	Dict      =							initializer_range
       a_      :	Union[str, Any]      =							scope


     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       a_      :	str      =							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size] )

       a_      :	Dict      =							None
       a_      :	str      =							None
       if self.use_labels:
         a_      :	List[Any]      =							ids_tensor([self.batch_size]							,		self.num_labels )
         a_      :	Optional[int]      =							ids_tensor([self.batch_size, self.image_size, self.image_size]							,		self.num_labels )

       a_      :	Union[str, Any]      =							self.get_config()

       return config, pixel_values, labels, pixel_labels


     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       return MobileNetVaConfig(
           num_channels=self.num_channels							,		image_size=self.image_size							,		depth_multiplier=self.depth_multiplier							,		min_depth=self.min_depth							,		tf_padding=self.tf_padding							,		hidden_act=self.hidden_act							,		classifier_dropout_prob=self.classifier_dropout_prob							,		initializer_range=self.initializer_range							,		)


     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_ ):

       '''simple docstring'''

       a_      :	Dict      =							MobileNetVaModel(config=lowerCAmelCase_ )
       model.to(lowerCAmelCase_ )
       model.eval()
       a_      :	Union[str, Any]      =							model(lowerCAmelCase_ )
       self.parent.assertEqual(
           result.last_hidden_state.shape							,		(
               self.batch_size,
               self.last_hidden_size,
               self.image_size // self.output_stride,
               self.image_size // self.output_stride,
           )							,		)


     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_ ):

       '''simple docstring'''

       a_      :	List[Any]      =							self.num_labels
       a_      :	Any      =							MobileNetVaForImageClassification(lowerCAmelCase_ )
       model.to(lowerCAmelCase_ )
       model.eval()
       a_      :	int      =							model(lowerCAmelCase_							,		labels=lowerCAmelCase_ )
       self.parent.assertEqual(result.logits.shape							,		(self.batch_size, self.num_labels) )






     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       a_      :	List[Any]      =							self.prepare_config_and_inputs()
       a_      , a_      , a_      , a_      :	Dict      =							config_and_inputs
       a_      :	int      =							{"""pixel_values""": pixel_values}
       return config, inputs_dict







@require_torch
class  _UpperCAmelCase ( lowerCAmelCase__	,lowerCAmelCase__	,unittest.TestCase    ):

     """simple docstring"""

     a_    	=					(MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
     a_    	=					(
         {"feature-extraction": MobileNetVaModel, "image-classification": MobileNetVaForImageClassification}
         if is_torch_available()
         else {}
     )

     a_    	=					False
     a_    	=					False
     a_    	=					False
     a_    	=					False


     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       a_      :	Any      =							MobileNetVaModelTester(self )
       a_      :	Optional[Any]      =							MobileNetVaConfigTester(self							,		config_class=lowerCAmelCase_							,		has_text_modality=lowerCAmelCase_ )


     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       self.config_tester.run_common_tests()


     @unittest.skip(reason="""MobileNetV1 does not use inputs_embeds""" )
     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       pass


     @unittest.skip(reason="""MobileNetV1 does not support input and output embeddings""" )
     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       pass


     @unittest.skip(reason="""MobileNetV1 does not output attentions""" )
     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       pass


     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       a_      , a_      :	Tuple      =							self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
         a_      :	Tuple      =							model_class(lowerCAmelCase_ )
         a_      :	Optional[Any]      =							inspect.signature(model.forward )
         # signature.parameters is an OrderedDict => so arg_names order is deterministic
         a_      :	Optional[Any]      =							[*signature.parameters.keys()]

         a_      :	List[Any]      =							["""pixel_values"""]
         self.assertListEqual(arg_names[:1]							,		lowerCAmelCase_ )


     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       a_      :	Any      =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*lowerCAmelCase_ )


     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       def check_hidden_states_output(lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_ ):
         a_      :	int      =							model_class(lowerCAmelCase_ )
         model.to(lowerCAmelCase_ )
         model.eval()

         with torch.no_grad():
           a_      :	Dict      =							model(**self._prepare_for_class(lowerCAmelCase_							,		lowerCAmelCase_ ) )

         a_      :	List[Any]      =							outputs.hidden_states

         a_      :	List[str]      =							26
         self.assertEqual(len(lowerCAmelCase_ )							,		lowerCAmelCase_ )

       a_      , a_      :	Optional[Any]      =							self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
         a_      :	str      =							True
         check_hidden_states_output(lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_ )

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

         check_hidden_states_output(lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_ )


     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       a_      :	Tuple      =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase_ )






     @slow
     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         a_      :	List[str]      =							MobileNetVaModel.from_pretrained(lowerCAmelCase_ )
         self.assertIsNotNone(lowerCAmelCase_ )







def 	_snake_case						(      ):
  """simple docstring"""







  a_      :	str      =							Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""   )
  return image




@require_torch
@require_vision
class  _UpperCAmelCase ( unittest.TestCase    ):

     """simple docstring"""

     @cached_property
     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       return (
           MobileNetVaImageProcessor.from_pretrained("""google/mobilenet_v1_1.0_224""" ) if is_vision_available() else None
       )






     @slow
     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       a_      :	int      =							MobileNetVaForImageClassification.from_pretrained("""google/mobilenet_v1_1.0_224""" ).to(lowerCAmelCase_ )

       a_      :	Any      =							self.default_image_processor
       a_      :	Optional[Any]      =							prepare_img()
       a_      :	List[Any]      =							image_processor(images=lowerCAmelCase_							,		return_tensors="""pt""" ).to(lowerCAmelCase_ )

       # forward pass
       with torch.no_grad():
         a_      :	Optional[int]      =							model(**lowerCAmelCase_ )

       # verify the logits
       a_      :	Any      =							torch.Size((1, 10_01) )
       self.assertEqual(outputs.logits.shape							,		lowerCAmelCase_ )

       a_      :	str      =							torch.tensor([-4.1739, -1.1233, 3.1205] ).to(lowerCAmelCase_ )

       self.assertTrue(torch.allclose(outputs.logits[0, :3]							,		lowerCAmelCase_							,		atol=1E-4 ) )




'''simple docstring'''

def 	_snake_case						(      A_       :    list   ):
  """simple docstring"""







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

  a_      :	List[Any]      =							[]

  def generate(A_       :    int     ,		A_       :    list   ):
    a_      :	List[Any]      =							[0] * n
    res.append(tuple(A_   )   )

    a_      :	List[str]      =							0
    while i < n:
      if c[i] < i:
        if i % 2 == 0:
          a_      , a_      :	Union[str, Any]      =							arr[i], arr[0]
        else:
          a_      , a_      :	List[str]      =							arr[i], arr[c[i]]
        res.append(tuple(A_   )   )
        c[i] += 1
        a_      :	Optional[Any]      =							0
      else:
        a_      :	Union[str, Any]      =							0
        i += 1

  generate(len(A_   )     ,		A_   )
  return res


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


