






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 							A_    (						unittest.TestCase			):






 '''simple docstring'''




 _SCREAMING_SNAKE_CASE							:			List[str] =					MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
 _SCREAMING_SNAKE_CASE							:			List[Any] =					TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING


 def  snake_case__				(	self							,  _A							,  _A							,  _A) ->		Any:

     """simple docstring"""



     _UpperCAmelCase				:      Union[str, Any]			  =				AudioClassificationPipeline(model=_A							,  feature_extractor=_A)

     # test with a raw waveform
     _UpperCAmelCase				:      Union[str, Any]			  =				np.zeros((34000,))
     _UpperCAmelCase				:      str			  =				np.zeros((14000,))
     return audio_classifier, [audioa, audio]


 def  snake_case__				(	self							,  _A							,  _A) ->		Optional[int]:

     """simple docstring"""



     _UpperCAmelCase  , _UpperCAmelCase				:      Tuple			  =				examples
     _UpperCAmelCase				:      Optional[Any]			  =				audio_classifier(_A)
     # by default a model is initialized with num_labels=2
     self.assertEqual(
         _A							,  [
             {'''score''': ANY(_A), '''label''': ANY(_A)},
             {'''score''': ANY(_A), '''label''': ANY(_A)},
         ]							,  )
     _UpperCAmelCase				:      List[str]			  =				audio_classifier(_A							,  top_k=1)
     self.assertEqual(
         _A							,  [
             {'''score''': ANY(_A), '''label''': ANY(_A)},
         ]							,  )

     self.run_torchaudio(_A)


 @require_torchaudio
 def  snake_case__				(	self							,  _A) ->		Union[str, Any]:

     """simple docstring"""



     import datasets

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


 @require_torch
 def  snake_case__				(	self) ->		Optional[Any]:

     """simple docstring"""



     _UpperCAmelCase				:      Optional[int]			  =				'''anton-l/wav2vec2-random-tiny-classifier'''

     _UpperCAmelCase				:      Dict			  =				pipeline('''audio-classification'''							,  model=_A)

     _UpperCAmelCase				:      Union[str, Any]			  =				np.ones((8000,))
     _UpperCAmelCase				:      Optional[int]			  =				audio_classifier(_A							,  top_k=4)

     _UpperCAmelCase				:      Dict			  =				[
         {'''score''': 0.0842, '''label''': '''no'''},
         {'''score''': 0.0838, '''label''': '''up'''},
         {'''score''': 0.0837, '''label''': '''go'''},
         {'''score''': 0.0834, '''label''': '''right'''},
     ]
     _UpperCAmelCase				:      Optional[Any]			  =				[
         {'''score''': 0.0845, '''label''': '''stop'''},
         {'''score''': 0.0844, '''label''': '''on'''},
         {'''score''': 0.0841, '''label''': '''right'''},
         {'''score''': 0.0834, '''label''': '''left'''},
     ]
     self.assertIn(nested_simplify(_A							,  decimals=4)							,  [EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2])

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


 @require_torch
 @slow
 def  snake_case__				(	self) ->		Any:

     """simple docstring"""



     import datasets

     _UpperCAmelCase				:      Union[str, Any]			  =				'''superb/wav2vec2-base-superb-ks'''

     _UpperCAmelCase				:      Optional[Any]			  =				pipeline('''audio-classification'''							,  model=_A)
     _UpperCAmelCase				:      List[Any]			  =				datasets.load_dataset('''anton-l/superb_dummy'''							,  '''ks'''							,  split='''test''')

     _UpperCAmelCase				:      List[str]			  =				np.array(dataset[3]['''speech''']							,  dtype=np.floataa)
     _UpperCAmelCase				:      Any			  =				audio_classifier(_A							,  top_k=4)
     self.assertEqual(
         nested_simplify(_A							,  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  snake_case__				(	self) ->		Union[str, Any]:

     """simple docstring"""



     pass












import math

def      _lowerCamelCase	(						__A    :							int )      ->					int:

    if not isinstance(__A		,		__A ):
        _UpperCAmelCase				:      List[Any]			  =				f'''Input value of [number={number}] must be an integer'''
        raise TypeError(__A )

    if number < 1:
        _UpperCAmelCase				:      Optional[Any]			  =				f'''Input value of [number={number}] must be > 0'''
        raise ValueError(__A )
    elif number == 1:
        return 3
    elif number == 2:
        return 5
    else:
        _UpperCAmelCase				:      Any			  =				int(math.log(number // 3		,		2 ) ) + 2

        _UpperCAmelCase				:      Dict			  =				[3, 5]
        _UpperCAmelCase				:      Tuple			  =				2
        _UpperCAmelCase				:      Dict			  =				3
        for block in range(1		,		__A ):
            for _ in range(__A ):
                proth_list.append(2 ** (block + 1) + proth_list[proth_index - 1] )
                proth_index += 1
            increment *= 2

    return proth_list[number - 1]


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  for number in range(11):
    SCREAMING_SNAKE_CASE 							=						0
    try:
      SCREAMING_SNAKE_CASE 							=						proth(number)
    except ValueError:
      print(F'ValueError: there is no {number}th Proth number')
      continue

    print(F'The {number}th Proth number: {value}')




