

"""simple docstring"""



import inspect
import unittest

from huggingface_hub import hf_hub_download

from transformers import ASTConfig
from transformers.testing_utils import require_torch, require_torchaudio, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_torchaudio_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 torch import nn

 from transformers import ASTForAudioClassification, ASTModel
 from transformers.models.audio_spectrogram_transformer.modeling_audio_spectrogram_transformer import (
     AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
 )


if is_torchaudio_available():
 import torchaudio

 from transformers import ASTFeatureExtractor



class 					a						:



    """simple docstring"""



    def __init__(     self: Tuple    ,						UpperCamelCase: Union[str, Any]    ,						UpperCamelCase: List[Any]=13    ,						UpperCamelCase: Any=2    ,						UpperCamelCase: Tuple=24    ,						UpperCamelCase: Any=16    ,						UpperCamelCase: List[Any]=True    ,						UpperCamelCase: Tuple=True    ,						UpperCamelCase: Any=32    ,						UpperCamelCase: Optional[Any]=5    ,						UpperCamelCase: Optional[int]=4    ,						UpperCamelCase: Union[str, Any]=37    ,						UpperCamelCase: List[str]="gelu"    ,						UpperCamelCase: List[Any]=0.1    ,						UpperCamelCase: Dict=0.1    ,						UpperCamelCase: List[Any]=10    ,						UpperCamelCase: Optional[int]=0.02    ,						UpperCamelCase: List[str]=None    ,						UpperCamelCase: Optional[Any]=2    ,						UpperCamelCase: Union[str, Any]=2    ,						):






         """simple docstring"""


         A__										=  parent
         A__										=  batch_size
         A__										=  patch_size
         A__										=  max_length
         A__										=  num_mel_bins
         A__										=  is_training
         A__										=  use_labels
         A__										=  hidden_size
         A__										=  num_hidden_layers
         A__										=  num_attention_heads
         A__										=  intermediate_size
         A__										=  hidden_act
         A__										=  hidden_dropout_prob
         A__										=  attention_probs_dropout_prob
         A__										=  type_sequence_label_size
         A__										=  initializer_range
         A__										=  scope
         A__										=  frequency_stride
         A__										=  time_stride

         # in AST, the seq length equals the number of patches + 2 (we add 2 for the [CLS] and distillation tokens)
         A__										=  (self.num_mel_bins - self.patch_size) // self.frequency_stride + 1
         A__										=  (self.max_length - self.patch_size) // self.time_stride + 1
         A__										=  frequency_out_dimension * time_out_dimension
         A__										=  num_patches + 2

    def 				UpperCamelCase	(     self: Union[str, Any]       ):






         """simple docstring"""


         A__										=  floats_tensor([self.batch_size, self.max_length, self.num_mel_bins]       )

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

         A__										=  self.get_config()

         return config, input_values, labels

    def 				UpperCamelCase	(     self: Optional[Any]       ):






         """simple docstring"""


         return ASTConfig(
             patch_size=self.patch_size    ,						max_length=self.max_length    ,						num_mel_bins=self.num_mel_bins    ,						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    ,						frequency_stride=self.frequency_stride    ,						time_stride=self.time_stride    ,						)

    def 				UpperCamelCase	(     self: List[Any]    ,						UpperCamelCase: Optional[int]    ,						UpperCamelCase: List[Any]    ,						UpperCamelCase: Optional[int]       ):






         """simple docstring"""


         A__										=  ASTModel(config=UpperCamelCase       )
         model.to(UpperCamelCase       )
         model.eval()
         A__										=  model(UpperCamelCase       )
         self.parent.assertEqual(result.last_hidden_state.shape    ,						(self.batch_size, self.seq_length, self.hidden_size)       )





    def 				UpperCamelCase	(     self: Union[str, Any]       ):






         """simple docstring"""


         A__										=  self.prepare_config_and_inputs()
         (
             (
             A__
         )			,				(
             A__
         )			,				(
             A__
         )			,				
         )										=  config_and_inputs
         A__										=  {"""input_values""": input_values}
         return config, inputs_dict



@require_torch
class 					a						(       _lowerCamelCase,	_lowerCamelCase,	unittest.TestCase				):



    """simple docstring"""



    UpperCAmelCase						 =					(
        (
            ASTModel,
            ASTForAudioClassification,
        )
        if is_torch_available()
        else ()
    )
    UpperCAmelCase						 =					(
        {"audio-classification": ASTForAudioClassification, "feature-extraction": ASTModel}
        if is_torch_available()
        else {}
    )
    UpperCAmelCase						 =					False
    UpperCAmelCase						 =					False
    UpperCAmelCase						 =					False
    UpperCAmelCase						 =					False

    def 				UpperCamelCase	(     self: List[str]    ,						UpperCamelCase: Optional[Any]    ,						UpperCamelCase: Dict    ,						UpperCamelCase: Any    ,						UpperCamelCase: Optional[int]    ,						UpperCamelCase: Tuple       ):






         """simple docstring"""


         if pipeline_test_casse_name == "AudioClassificationPipelineTests":
              return True

         return False

    def 				UpperCamelCase	(     self: List[str]       ):






         """simple docstring"""


         A__										=  ASTModelTester(self       )
         A__										=  ConfigTester(self    ,						config_class=UpperCamelCase    ,						has_text_modality=UpperCamelCase    ,						hidden_size=37       )

    def 				UpperCamelCase	(     self: Optional[Any]       ):






         """simple docstring"""


         self.config_tester.run_common_tests()

    @unittest.skip(reason="""AST does not use inputs_embeds"""       )
    def 				UpperCamelCase	(     self: Optional[int]       ):






         """simple docstring"""


         pass

    def 				UpperCamelCase	(     self: Dict       ):






         """simple docstring"""


         A__			,				A__										=  self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
              A__										=  model_class(UpperCamelCase       )
              self.assertIsInstance(model.get_input_embeddings()    ,						(nn.Module)       )
              A__										=  model.get_output_embeddings()
              self.assertTrue(x is None or isinstance(UpperCamelCase    ,						nn.Linear       )       )

    def 				UpperCamelCase	(     self: List[str]       ):






         """simple docstring"""


         A__			,				A__										=  self.model_tester.prepare_config_and_inputs_for_common()

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

              A__										=  ["""input_values"""]
              self.assertListEqual(arg_names[:1]    ,						UpperCamelCase       )

    def 				UpperCamelCase	(     self: Any       ):






         """simple docstring"""


         A__										=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*UpperCamelCase       )





    @slow
    def 				UpperCamelCase	(     self: Union[str, Any]       ):






         """simple docstring"""


         for model_name in AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              A__										=  ASTModel.from_pretrained(UpperCamelCase       )
              self.assertIsNotNone(UpperCamelCase       )





def  _snake_case     (    ):
     A__										=  hf_hub_download(
         repo_id="""nielsr/audio-spectogram-transformer-checkpoint"""					,   filename="""sample_audio.flac"""					,   repo_type="""dataset"""			)

     A__			,				A__										=  torchaudio.load(UpperCAmelCase_			)

     return audio, sampling_rate



@require_torch
@require_torchaudio
class 					a						(       unittest.TestCase				):



    """simple docstring"""



    @cached_property
    def 				UpperCamelCase	(     self: List[str]       ):






         """simple docstring"""


         return (
             ASTFeatureExtractor.from_pretrained("""MIT/ast-finetuned-audioset-10-10-0.4593"""       )
             if is_torchaudio_available()
             else None
         )





    @slow
    def 				UpperCamelCase	(     self: List[Any]       ):






         """simple docstring"""


         A__										=  self.default_feature_extractor
         A__										=  ASTForAudioClassification.from_pretrained("""MIT/ast-finetuned-audioset-10-10-0.4593"""       ).to(UpperCamelCase       )

         A__										=  self.default_feature_extractor
         A__			,				A__										=  prepare_audio()
         A__										=  audio.squeeze().numpy()
         A__										=  feature_extractor(UpperCamelCase    ,						sampling_rate=UpperCamelCase    ,						return_tensors="""pt"""       ).to(UpperCamelCase       )

         # forward pass
         with torch.no_grad():
              A__										=  model(**UpperCamelCase       )

         # verify the logits
         A__										=  torch.Size((1, 5_27)       )
         self.assertEqual(outputs.logits.shape    ,						UpperCamelCase       )

         A__										=  torch.tensor([-0.8_760, -7.0_042, -8.6_602]       ).to(UpperCamelCase       )

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









"""simple docstring"""



def  _snake_case     (    UpperCAmelCase_  :					list			):
     if len(UpperCAmelCase_			) <= 1:
          return lst

     A__										=  1

     while i < len(UpperCAmelCase_			):
          if lst[i - 1] <= lst[i]:
               i += 1
          else:
               A__			,				A__										=  lst[i], lst[i - 1]
               i -= 1
               if i == 0:
                    A__										=  1

     return lst


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






