




'''simple docstring'''


import unittest

import numpy as np

from transformers import MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING, TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
from transformers.pipelines import AudioClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_torchaudio,
    slow,
)

from .test_pipelines_common import ANY





@is_pipeline_test
class  __lowercase    (	unittest.TestCase			):
   _a    						=   MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
   _a    						=   TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   )					->     List[Any]:
     __a								=       AudioClassificationPipeline(model=UpperCamelCase   ,				feature_extractor=UpperCamelCase   )

     # test with a raw waveform
     __a								=       np.zeros((3_4000,)   )
     __a								=       np.zeros((1_4000,)   )
     return audio_classifier, [audioa, audio]







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase   )					->     List[str]:
     __a						,							__a								=       examples
     __a								=       audio_classifier(UpperCamelCase   )
     # by default a model is initialized with num_labels=2
     self.assertEqual(
         UpperCamelCase   ,				[
             {'score': ANY(UpperCamelCase   ), 'label': ANY(UpperCamelCase   )},
             {'score': ANY(UpperCamelCase   ), 'label': ANY(UpperCamelCase   )},
         ]   ,				)
     __a								=       audio_classifier(UpperCamelCase   ,				top_k=1   )
     self.assertEqual(
         UpperCamelCase   ,				[
             {'score': ANY(UpperCamelCase   ), 'label': ANY(UpperCamelCase   )},
         ]   ,				)

     self.run_torchaudio(UpperCamelCase   )







   @require_torchaudio
   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   )					->     List[Any]:
     import datasets

     # test with a local file
     __a								=       datasets.load_dataset('hf-internal-testing/librispeech_asr_dummy'   ,				'clean'   ,				split='validation'   )
     __a								=       dataset[0]['audio']['array']
     __a								=       audio_classifier(UpperCamelCase   )
     self.assertEqual(
         UpperCamelCase   ,				[
             {'score': ANY(UpperCamelCase   ), 'label': ANY(UpperCamelCase   )},
             {'score': ANY(UpperCamelCase   ), 'label': ANY(UpperCamelCase   )},
         ]   ,				)







   @require_torch
   def 		UpperCamelCase__      (						self   )					->     Optional[int]:
     __a								=       'anton-l/wav2vec2-random-tiny-classifier'

     __a								=       pipeline('audio-classification'   ,				model=UpperCamelCase   )

     __a								=       np.ones((8000,)   )
     __a								=       audio_classifier(UpperCamelCase   ,				top_k=4   )

     __a								=       [
         {'score': 0.0_842, 'label': 'no'},
         {'score': 0.0_838, 'label': 'up'},
         {'score': 0.0_837, 'label': 'go'},
         {'score': 0.0_834, 'label': 'right'},
     ]
     __a								=       [
         {'score': 0.0_845, 'label': 'stop'},
         {'score': 0.0_844, 'label': 'on'},
         {'score': 0.0_841, 'label': 'right'},
         {'score': 0.0_834, 'label': 'left'},
     ]
     self.assertIn(nested_simplify(UpperCamelCase   ,				decimals=4   )   ,				[EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]   )

     __a								=       {'array': np.ones((8000,)   ), 'sampling_rate': audio_classifier.feature_extractor.sampling_rate}
     __a								=       audio_classifier(UpperCamelCase   ,				top_k=4   )
     self.assertIn(nested_simplify(UpperCamelCase   ,				decimals=4   )   ,				[EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]   )







   @require_torch
   @slow
   def 		UpperCamelCase__      (						self   )					->     List[Any]:
     import datasets

     __a								=       'superb/wav2vec2-base-superb-ks'

     __a								=       pipeline('audio-classification'   ,				model=UpperCamelCase   )
     __a								=       datasets.load_dataset('anton-l/superb_dummy'   ,				'ks'   ,				split='test'   )

     __a								=       np.array(dataset[3]['speech']   ,				dtype=np.floataa   )
     __a								=       audio_classifier(UpperCamelCase   ,				top_k=4   )
     self.assertEqual(
         nested_simplify(UpperCamelCase   ,				decimals=3   )   ,				[
             {'score': 0.981, 'label': 'go'},
             {'score': 0.007, 'label': 'up'},
             {'score': 0.006, 'label': '_unknown_'},
             {'score': 0.001, 'label': 'down'},
         ]   ,				)







   @require_tf
   @unittest.skip('Audio classification is not implemented for TF'   )
   def 		UpperCamelCase__      (						self   )					->     Optional[int]:
     pass









'''simple docstring'''


import math


def     SCREAMING_SNAKE_CASE							(   a_						:				float					,       a_						:				float      ):

  if initial_intensity < 0:
    raise ValueError('The value of intensity cannot be negative'      )
    # handling of negative values of initial intensity
  if angle < 0 or angle > 360:
    raise ValueError('In Malus Law, the angle is in the range 0-360 degrees'      )
    # handling of values out of allowed range
  return initial_intensity * (math.cos(math.radians(a_      )      ) ** 2)


if __name__ == "__main__":
  import doctest

  doctest.testmod(name="malus_law")



