



'''simple docstring'''





import unittest

from datasets import load_dataset

from transformers.pipelines import pipeline
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_torch, slow






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



 '''simple docstring'''







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


      """simple docstring"""



      _a											=						pipeline(
          task='''zero-shot-audio-classification'''				,     model='''hf-internal-testing/tiny-clap-htsat-unfused''' )
      _a											=						load_dataset('''ashraq/esc50''' )
      _a											=						dataset['''train''']['''audio'''][-1]['''array''']
      _a											=						audio_classifier(_lowerCAmelCase				,     candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner'''] )
      self.assertEqual(
          nested_simplify(_lowerCAmelCase )				,     [{'''score''': 0.501, '''label''': '''Sound of a dog'''}, {'''score''': 0.499, '''label''': '''Sound of vaccum cleaner'''}]				,     )



 @unittest.skip('''No models are available in TF''' )
 def       a__						(self )					->  int:


      """simple docstring"""



      pass



 @slow
 @require_torch
 def       a__						(self )					->  Tuple:


      """simple docstring"""



      _a											=						pipeline(
          task='''zero-shot-audio-classification'''				,     model='''laion/clap-htsat-unfused'''				,     )
      # This is an audio of a dog
      _a											=						load_dataset('''ashraq/esc50''' )
      _a											=						dataset['''train''']['''audio'''][-1]['''array''']
      _a											=						audio_classifier(_lowerCAmelCase				,     candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner'''] )

      self.assertEqual(
          nested_simplify(_lowerCAmelCase )				,     [
              {'''score''': 0.999, '''label''': '''Sound of a dog'''},
              {'''score''': 0.001, '''label''': '''Sound of vaccum cleaner'''},
          ]				,     )

      _a											=						audio_classifier([audio] * 5				,     candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner'''] )
      self.assertEqual(
          nested_simplify(_lowerCAmelCase )				,     [
              [
                  {'''score''': 0.999, '''label''': '''Sound of a dog'''},
                  {'''score''': 0.001, '''label''': '''Sound of vaccum cleaner'''},
              ],
          ]
          * 5				,     )
      _a											=						audio_classifier(
          [audio] * 5				,     candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']				,     batch_size=5 )
      self.assertEqual(
          nested_simplify(_lowerCAmelCase )				,     [
              [
                  {'''score''': 0.999, '''label''': '''Sound of a dog'''},
                  {'''score''': 0.001, '''label''': '''Sound of vaccum cleaner'''},
              ],
          ]
          * 5				,     )



 @unittest.skip('''No models are available in TF''' )
 def       a__						(self )					->  int:


      """simple docstring"""



      pass








'''simple docstring'''





lowercase_	 =						256
# Modulus to hash a string
lowercase_	 =						1_000_003




def lowerCAmelCase						(__A						,			__A):



     """simple docstring"""



     _a											=						len(__A)
     _a											=						len(__A)
     if p_len > t_len:
          return False

     _a											=						0
     _a											=						0
     _a											=						1

     # Calculating the hash of pattern and substring of text
     for i in range(__A):
          _a											=						(ord(pattern[i]) + p_hash * alphabet_size) % modulus
          _a											=						(ord(text[i]) + text_hash * alphabet_size) % modulus
          if i == p_len - 1:
               continue
          _a											=						(modulus_power * alphabet_size) % modulus

     for i in range(0						,			t_len - p_len + 1):
          if text_hash == p_hash and text[i : i + p_len] == pattern:
               return True
          if i == t_len - p_len:
               continue
          # Calculate the https://en.wikipedia.org/wiki/Rolling_hash
          _a											=						(
              (text_hash - ord(text[i]) * modulus_power) * alphabet_size
              + ord(text[i + p_len])
          ) % modulus
     return False




def lowerCAmelCase						():



     """simple docstring"""



     _a											=						'''abc1abc12'''
     _a											=						'''alskfjaldsabc1abc1abc12k23adsfabcabc'''
     _a											=						'''alskfjaldsk23adsfabcabc'''
     assert rabin_karp(__A						,			__A) and not rabin_karp(__A						,			__A)

     # Test 2)
     _a											=						'''ABABX'''
     _a											=						'''ABABZABABYABABX'''
     assert rabin_karp(__A						,			__A)

     # Test 3)
     _a											=						'''AAAB'''
     _a											=						'''ABAAAAAB'''
     assert rabin_karp(__A						,			__A)

     # Test 4)
     _a											=						'''abcdabcy'''
     _a											=						'''abcxabcdabxabcdabcdabcy'''
     assert rabin_karp(__A						,			__A)

     # Test 5)
     _a											=						'''Lü'''
     _a											=						'''Lüsai'''
     assert rabin_karp(__A						,			__A)
     _a											=						'''Lue'''
     assert not rabin_karp(__A						,			__A)
     print('''Success.''')


if __name__ == "__main__":
  test_rabin_karp()



