




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  :     Optional[int]   ,       __snake_case  :     List[Any]   ,       __snake_case  :     List[Any]=13   ,       __snake_case  :     int=2   ,       __snake_case  :     List[str]=24   ,       __snake_case  :     List[str]=16   ,       __snake_case  :     Dict=True   ,       __snake_case  :     str=True   ,       __snake_case  :     Optional[Any]=32   ,       __snake_case  :     Any=5   ,       __snake_case  :     str=4   ,       __snake_case  :     List[str]=37   ,       __snake_case  :     List[str]="gelu"   ,       __snake_case  :     int=0.1   ,       __snake_case  :     str=0.1   ,       __snake_case  :     List[str]=10   ,       __snake_case  :     List[Any]=0.02   ,       __snake_case  :     Optional[int]=None   ,       __snake_case  :     Any=2   ,       __snake_case  :     List[Any]=2   ,       ):
         UpperCAmelCase_									=	parent
         UpperCAmelCase_									=	batch_size
         UpperCAmelCase_									=	patch_size
         UpperCAmelCase_									=	max_length
         UpperCAmelCase_									=	num_mel_bins
         UpperCAmelCase_									=	is_training
         UpperCAmelCase_									=	use_labels
         UpperCAmelCase_									=	hidden_size
         UpperCAmelCase_									=	num_hidden_layers
         UpperCAmelCase_									=	num_attention_heads
         UpperCAmelCase_									=	intermediate_size
         UpperCAmelCase_									=	hidden_act
         UpperCAmelCase_									=	hidden_dropout_prob
         UpperCAmelCase_									=	attention_probs_dropout_prob
         UpperCAmelCase_									=	type_sequence_label_size
         UpperCAmelCase_									=	initializer_range
         UpperCAmelCase_									=	scope
         UpperCAmelCase_									=	frequency_stride
         UpperCAmelCase_									=	time_stride

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

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

         UpperCAmelCase_									=	self.get_config()

         return config, input_values, labels
     def     lowerCamelCase_  (      self  :     Any							):
         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     lowerCamelCase_  (      self  :     int   ,       __snake_case  :     Union[str, Any]   ,       __snake_case  :     Optional[int]   ,       __snake_case  :     Tuple							):
         UpperCAmelCase_									=	ASTModel(config=__UpperCamelCase							)
         model.to(__UpperCamelCase							)
         model.eval()
         UpperCAmelCase_									=	model(__UpperCamelCase							)
         self.parent.assertEqual(result.last_hidden_state.shape   ,       (self.batch_size, self.seq_length, self.hidden_size)							)




     def     lowerCamelCase_  (      self  :     Union[str, Any]							):
         UpperCAmelCase_									=	self.prepare_config_and_inputs()
         (
             (
             UpperCAmelCase_							
         )					,				(
             UpperCAmelCase_							
         )					,				(
             UpperCAmelCase_							
         )					,											
         )									=	config_and_inputs
         UpperCAmelCase_									=	{'''input_values''': input_values}
         return config, inputs_dict



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

     '''simple docstring'''





     lowerCAmelCase							:			Any  						=    (
         (
             ASTModel,
             ASTForAudioClassification,
         )
         if is_torch_available()
         else ()
     )
     lowerCAmelCase							:			Optional[Any]  						=    (
         {'audio-classification': ASTForAudioClassification, 'feature-extraction': ASTModel}
         if is_torch_available()
         else {}
     )
     lowerCAmelCase							:			Optional[int]  						=    False
     lowerCAmelCase							:			Tuple  						=    False
     lowerCAmelCase							:			Union[str, Any]  						=    False
     lowerCAmelCase							:			List[Any]  						=    False
     def     lowerCamelCase_  (      self  :     Optional[Any]   ,       __snake_case  :     Union[str, Any]   ,       __snake_case  :     Union[str, Any]   ,       __snake_case  :     int   ,       __snake_case  :     int   ,       __snake_case  :     Tuple							):


         if pipeline_test_casse_name == "AudioClassificationPipelineTests":
             return True

         return False
     def     lowerCamelCase_  (      self  :     List[str]							):
         UpperCAmelCase_									=	ASTModelTester(self							)
         UpperCAmelCase_									=	ConfigTester(self   ,       config_class=__UpperCamelCase   ,       has_text_modality=__UpperCamelCase   ,       hidden_size=37							)
     def     lowerCamelCase_  (      self  :     str							):
         self.config_tester.run_common_tests()
     @unittest.skip(reason='''AST does not use inputs_embeds'''							)
     def     lowerCamelCase_  (      self  :     Optional[Any]							):
         pass
     def     lowerCamelCase_  (      self  :     int							):
         UpperCAmelCase_					,				UpperCAmelCase_									=	self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
             UpperCAmelCase_									=	model_class(__UpperCamelCase							)
             self.assertIsInstance(model.get_input_embeddings()   ,       (nn.Module)							)
             UpperCAmelCase_									=	model.get_output_embeddings()
             self.assertTrue(x is None or isinstance(__UpperCamelCase   ,       nn.Linear							)							)
     def     lowerCamelCase_  (      self  :     List[str]							):
         UpperCAmelCase_					,				UpperCAmelCase_									=	self.model_tester.prepare_config_and_inputs_for_common()

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

             UpperCAmelCase_									=	['''input_values''']
             self.assertListEqual(arg_names[:1]   ,       __UpperCamelCase							)
     def     lowerCamelCase_  (      self  :     Tuple							):
         UpperCAmelCase_									=	self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*__UpperCamelCase							)




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


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




def    SCREAMING_SNAKE_CASE      (			)    ->				str:
    UpperCAmelCase_									=	hf_hub_download(
        repo_id='''nielsr/audio-spectogram-transformer-checkpoint'''			,	filename='''sample_audio.flac'''			,	repo_type='''dataset''' )

    UpperCAmelCase_					,				UpperCAmelCase_									=	torchaudio.load(lowercase__ )

    return audio, sampling_rate



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

     '''simple docstring'''





     @cached_property
     def     lowerCamelCase_  (      self  :     str							):
         return (
             ASTFeatureExtractor.from_pretrained('''MIT/ast-finetuned-audioset-10-10-0.4593'''							)
             if is_torchaudio_available()
             else None
         )




     @slow
     def     lowerCamelCase_  (      self  :     Optional[int]							):
         UpperCAmelCase_									=	self.default_feature_extractor
         UpperCAmelCase_									=	ASTForAudioClassification.from_pretrained('''MIT/ast-finetuned-audioset-10-10-0.4593'''							).to(__UpperCamelCase							)

         UpperCAmelCase_									=	self.default_feature_extractor
         UpperCAmelCase_					,				UpperCAmelCase_									=	prepare_audio()
         UpperCAmelCase_									=	audio.squeeze().numpy()
         UpperCAmelCase_									=	feature_extractor(__UpperCamelCase   ,       sampling_rate=__UpperCamelCase   ,       return_tensors='''pt'''							).to(__UpperCamelCase							)

         # forward pass
         with torch.no_grad():
             UpperCAmelCase_									=	model(**__UpperCamelCase							)

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

         UpperCAmelCase_									=	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							)							)








from __future__ import annotations





def a(lowercase__      ,			lowercase__      ,			lowercase__      ,			lowercase__						):





	'''simple docstring'''
	if (direction == 1 and array[indexa] > array[indexa]) or (
	    direction == 0 and array[indexa] < array[indexa]
	):
		snake_case_		,							snake_case_   		=			array[indexa], array[indexa]





def a(lowercase__      ,			lowercase__      ,			lowercase__      ,			lowercase__						):





	'''simple docstring'''
	if length > 1:
		snake_case_   		=			int(length / 2						)
		for i in range(lowercase__      ,			low + middle						):
			comp_and_swap(lowercase__      ,			lowercase__      ,			i + middle      ,			lowercase__						)
		bitonic_merge(lowercase__      ,			lowercase__      ,			lowercase__      ,			lowercase__						)
		bitonic_merge(lowercase__      ,			low + middle      ,			lowercase__      ,			lowercase__						)





def a(lowercase__      ,			lowercase__      ,			lowercase__      ,			lowercase__						):





	'''simple docstring'''
	if length > 1:
		snake_case_   		=			int(length / 2						)
		bitonic_sort(lowercase__      ,			lowercase__      ,			lowercase__      ,			1						)
		bitonic_sort(lowercase__      ,			low + middle      ,			lowercase__      ,			0						)
		bitonic_merge(lowercase__      ,			lowercase__      ,			lowercase__      ,			lowercase__						)


if __name__ == "__main__":
		A									=  input('Enter numbers separated by a comma:\n').strip()
		A									=  [int(item.strip()) for item in user_input.split(',')]

		bitonic_sort(unsorted, 0, len(unsorted), 1)
		print('\nSorted array in ascending order is: ', end='')
		print(*unsorted, sep=', ')

		bitonic_merge(unsorted, 0, len(unsorted), 0)
		print('Sorted array in descending order is: ', end='')
		print(*unsorted, sep=', ')
