'''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       :






       def __init__(      self				,     UpperCamelCase_				,     UpperCamelCase_=13				,     UpperCamelCase_=2				,     UpperCamelCase_=24				,     UpperCamelCase_=16				,     UpperCamelCase_=True				,     UpperCamelCase_=True				,     UpperCamelCase_=32				,     UpperCamelCase_=5				,     UpperCamelCase_=4				,     UpperCamelCase_=37				,     UpperCamelCase_="gelu"				,     UpperCamelCase_=0.1				,     UpperCamelCase_=0.1				,     UpperCamelCase_=10				,     UpperCamelCase_=0.0_2				,     UpperCamelCase_=None				,     UpperCamelCase_=2				,     UpperCamelCase_=2				,     ):
              __UpperCAmelCase  :				Dict       				=		parent
              __UpperCAmelCase  :				List[Any]       				=		batch_size
              __UpperCAmelCase  :				Optional[int]       				=		patch_size
              __UpperCAmelCase  :				List[Any]       				=		max_length
              __UpperCAmelCase  :				Optional[Any]       				=		num_mel_bins
              __UpperCAmelCase  :				Union[str, Any]       				=		is_training
              __UpperCAmelCase  :				Optional[Any]       				=		use_labels
              __UpperCAmelCase  :				int       				=		hidden_size
              __UpperCAmelCase  :				Optional[int]       				=		num_hidden_layers
              __UpperCAmelCase  :				Tuple       				=		num_attention_heads
              __UpperCAmelCase  :				List[Any]       				=		intermediate_size
              __UpperCAmelCase  :				Union[str, Any]       				=		hidden_act
              __UpperCAmelCase  :				Optional[Any]       				=		hidden_dropout_prob
              __UpperCAmelCase  :				Optional[int]       				=		attention_probs_dropout_prob
              __UpperCAmelCase  :				Union[str, Any]       				=		type_sequence_label_size
              __UpperCAmelCase  :				Union[str, Any]       				=		initializer_range
              __UpperCAmelCase  :				Optional[int]       				=		scope
              __UpperCAmelCase  :				Union[str, Any]       				=		frequency_stride
              __UpperCAmelCase  :				int       				=		time_stride

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






       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				Optional[int]       				=		floats_tensor([self.batch_size, self.max_length, self.num_mel_bins]      )

              __UpperCAmelCase  :				int       				=		None
              if self.use_labels:
                     __UpperCAmelCase  :				List[Any]       				=		ids_tensor([self.batch_size]				,     self.type_sequence_label_size      )

              __UpperCAmelCase  :				str       				=		self.get_config()

              return config, input_values, labels






       def 			_snake_case						(      self      ):
              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=__lowercase				,     initializer_range=self.initializer_range				,     frequency_stride=self.frequency_stride				,     time_stride=self.time_stride				,     )






       def 			_snake_case						(      self				,     UpperCamelCase_				,     UpperCamelCase_				,     UpperCamelCase_      ):
              __UpperCAmelCase  :				Optional[int]       				=		ASTModel(config=__lowercase      )
              model.to(__lowercase      )
              model.eval()
              __UpperCAmelCase  :				str       				=		model(__lowercase      )
              self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.hidden_size)      )







       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				str       				=		self.prepare_config_and_inputs()
              (
                  (
                  __UpperCAmelCase       
              )				, (
                  __UpperCAmelCase       
              )				, (
                  __UpperCAmelCase       
              )				,        
              )  :				Any       				=		config_and_inputs
              __UpperCAmelCase  :				Tuple       				=		{"input_values": input_values}
              return config, inputs_dict






@require_torch
class 		__A       (lowercase__ ,					lowercase__ ,					unittest.TestCase   ):
       snake_case       :List[Any]				    =					(
           (
               ASTModel,
               ASTForAudioClassification,
           )
           if is_torch_available()
           else ()
       )
       snake_case       :Dict				    =					(
           {"""audio-classification""": ASTForAudioClassification, """feature-extraction""": ASTModel}
           if is_torch_available()
           else {}
       )
       snake_case       :Optional[Any]				    =					False
       snake_case       :Union[str, Any]				    =					False
       snake_case       :int				    =					False
       snake_case       :List[str]				    =					False






       def 			_snake_case						(      self				,     UpperCamelCase_				,     UpperCamelCase_				,     UpperCamelCase_				,     UpperCamelCase_				,     UpperCamelCase_      ):
              if pipeline_test_casse_name == "AudioClassificationPipelineTests":
                     return True

              return False






       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				int       				=		ASTModelTester(self      )
              __UpperCAmelCase  :				Dict       				=		ConfigTester(self				,     config_class=__lowercase				,     has_text_modality=__lowercase				,     hidden_size=37      )






       def 			_snake_case						(      self      ):
              self.config_tester.run_common_tests()






       @unittest.skip(reason="AST does not use inputs_embeds"      )
       def 			_snake_case						(      self      ):
              pass






       def 			_snake_case						(      self      ):
              __UpperCAmelCase				, __UpperCAmelCase  :				List[str]       				=		self.model_tester.prepare_config_and_inputs_for_common()

              for model_class in self.all_model_classes:
                     __UpperCAmelCase  :				List[str]       				=		model_class(__lowercase      )
                     self.assertIsInstance(model.get_input_embeddings()				,     (nn.Module)      )
                     __UpperCAmelCase  :				Union[str, Any]       				=		model.get_output_embeddings()
                     self.assertTrue(x is None or isinstance(__lowercase				,     nn.Linear      )      )






       def 			_snake_case						(      self      ):
              __UpperCAmelCase				, __UpperCAmelCase  :				Tuple       				=		self.model_tester.prepare_config_and_inputs_for_common()

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

                     __UpperCAmelCase  :				Optional[Any]       				=		["input_values"]
                     self.assertListEqual(arg_names[:1]				,     __lowercase      )






       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				List[Any]       				=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_model(*__lowercase      )







       @slow
       def 			_snake_case						(      self      ):
              for model_name in AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                     __UpperCAmelCase  :				List[str]       				=		ASTModel.from_pretrained(__lowercase      )
                     self.assertIsNotNone(__lowercase      )





def _lowercase	(      )					->       Dict:





       """simple docstring"""


       __UpperCAmelCase  :				Optional[int]       				=		hf_hub_download(
           repo_id="nielsr/audio-spectogram-transformer-checkpoint"							,    filename="sample_audio.flac"							,    repo_type="dataset"						)

       __UpperCAmelCase				, __UpperCAmelCase  :				Any       				=		torchaudio.load(SCREAMING_SNAKE_CASE_						)

       return audio, sampling_rate






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






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







       @slow
       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				Tuple       				=		self.default_feature_extractor
              __UpperCAmelCase  :				Tuple       				=		ASTForAudioClassification.from_pretrained("MIT/ast-finetuned-audioset-10-10-0.4593"      ).to(__lowercase      )

              __UpperCAmelCase  :				Tuple       				=		self.default_feature_extractor
              __UpperCAmelCase				, __UpperCAmelCase  :				List[Any]       				=		prepare_audio()
              __UpperCAmelCase  :				List[str]       				=		audio.squeeze().numpy()
              __UpperCAmelCase  :				List[Any]       				=		feature_extractor(__lowercase				,     sampling_rate=__lowercase				,     return_tensors="pt"      ).to(__lowercase      )

              # forward pass
              with torch.no_grad():
                     __UpperCAmelCase  :				Dict       				=		model(**__lowercase      )

              # verify the logits
              __UpperCAmelCase  :				Optional[Any]       				=		torch.Size((1, 5_27)      )
              self.assertEqual(outputs.logits.shape				,     __lowercase      )

              __UpperCAmelCase  :				str       				=		torch.tensor([-0.8_7_6_0, -7.0_0_4_2, -8.6_6_0_2]      ).to(__lowercase      )

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







'''simple docstring'''




from maths.is_square_free import is_square_free
from maths.prime_factors import prime_factors

def _lowercase	(      lowerCamelCase__						)					->       int:





       """simple docstring"""


       __UpperCAmelCase  :				Any       				=		prime_factors(lowerCamelCase__						)
       if is_square_free(lowerCamelCase__						):
              return -1 if len(lowerCamelCase__						) % 2 else 1
       return 0


if __name__ == "__main__":
   import doctest

   doctest.testmod()






