





"""simple docstring"""


import shutil
import tempfile
import unittest

import pytest

from transformers import WhisperTokenizer, is_speech_available
from transformers.testing_utils import require_sentencepiece, require_torch, require_torchaudio

from .test_feature_extraction_whisper import floats_list


if is_speech_available():
   from transformers import WhisperFeatureExtractor, WhisperProcessor


a__					:     List[Any]							=				5_0_3_5_8
a__					:     Any							=				5_0_3_6_2



@require_torch
@require_torchaudio
@require_sentencepiece
class      lowercase_				(     unittest.TestCase							):

       def 		_SCREAMING_SNAKE_CASE(			self     ):






        '''simple docstring'''

        snake_case__    							=				"openai/whisper-small.en"
        snake_case__    							=				tempfile.mkdtemp()

       def 		_SCREAMING_SNAKE_CASE(			self   ,					**__SCREAMING_SNAKE_CASE     ):






        '''simple docstring'''

        return WhisperTokenizer.from_pretrained(self.checkpoint   ,					**__SCREAMING_SNAKE_CASE     )

       def 		_SCREAMING_SNAKE_CASE(			self   ,					**__SCREAMING_SNAKE_CASE     ):






        '''simple docstring'''

        return WhisperFeatureExtractor.from_pretrained(self.checkpoint   ,					**__SCREAMING_SNAKE_CASE     )

       def 		_SCREAMING_SNAKE_CASE(			self     ):






        '''simple docstring'''

        shutil.rmtree(self.tmpdirname     )

       def 		_SCREAMING_SNAKE_CASE(			self     ):






        '''simple docstring'''

        snake_case__    							=				self.get_tokenizer()
        snake_case__    							=				self.get_feature_extractor()

        snake_case__    							=				WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE   ,					feature_extractor=__SCREAMING_SNAKE_CASE     )

        processor.save_pretrained(self.tmpdirname     )
        snake_case__    							=				WhisperProcessor.from_pretrained(self.tmpdirname     )

        self.assertEqual(processor.tokenizer.get_vocab()   ,					tokenizer.get_vocab()     )
        self.assertIsInstance(processor.tokenizer   ,					__SCREAMING_SNAKE_CASE     )

        self.assertEqual(processor.feature_extractor.to_json_string()   ,					feature_extractor.to_json_string()     )
        self.assertIsInstance(processor.feature_extractor   ,					__SCREAMING_SNAKE_CASE     )

       def 		_SCREAMING_SNAKE_CASE(			self     ):






        '''simple docstring'''

        snake_case__    							=				WhisperProcessor(tokenizer=self.get_tokenizer()   ,					feature_extractor=self.get_feature_extractor()     )
        processor.save_pretrained(self.tmpdirname     )

        snake_case__    							=				self.get_tokenizer(bos_token="(BOS)"   ,					eos_token="(EOS)"     )
        snake_case__    							=				self.get_feature_extractor(do_normalize=__SCREAMING_SNAKE_CASE   ,					padding_value=1.0     )

        snake_case__    							=				WhisperProcessor.from_pretrained(
            self.tmpdirname   ,					bos_token="(BOS)"   ,					eos_token="(EOS)"   ,					do_normalize=__SCREAMING_SNAKE_CASE   ,					padding_value=1.0     )

        self.assertEqual(processor.tokenizer.get_vocab()   ,					tokenizer_add_kwargs.get_vocab()     )
        self.assertIsInstance(processor.tokenizer   ,					__SCREAMING_SNAKE_CASE     )

        self.assertEqual(processor.feature_extractor.to_json_string()   ,					feature_extractor_add_kwargs.to_json_string()     )
        self.assertIsInstance(processor.feature_extractor   ,					__SCREAMING_SNAKE_CASE     )

       def 		_SCREAMING_SNAKE_CASE(			self     ):






        '''simple docstring'''

        snake_case__    							=				self.get_feature_extractor()
        snake_case__    							=				self.get_tokenizer()

        snake_case__    							=				WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE   ,					feature_extractor=__SCREAMING_SNAKE_CASE     )

        snake_case__    							=				floats_list((3, 1000)     )

        snake_case__    							=				feature_extractor(__SCREAMING_SNAKE_CASE   ,					return_tensors="np"     )
        snake_case__    							=				processor(__SCREAMING_SNAKE_CASE   ,					return_tensors="np"     )

        for key in input_feat_extract.keys():
         self.assertAlmostEqual(input_feat_extract[key].sum()   ,					input_processor[key].sum()   ,					delta=1e-2     )

       def 		_SCREAMING_SNAKE_CASE(			self     ):






        '''simple docstring'''

        snake_case__    							=				self.get_feature_extractor()
        snake_case__    							=				self.get_tokenizer()

        snake_case__    							=				WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE   ,					feature_extractor=__SCREAMING_SNAKE_CASE     )

        snake_case__    							=				"This is a test string"

        snake_case__    							=				processor(text=__SCREAMING_SNAKE_CASE     )

        snake_case__    							=				tokenizer(__SCREAMING_SNAKE_CASE     )

        for key in encoded_tok.keys():
         self.assertListEqual(encoded_tok[key]   ,					encoded_processor[key]     )

       def 		_SCREAMING_SNAKE_CASE(			self     ):






        '''simple docstring'''

        snake_case__    							=				self.get_feature_extractor()
        snake_case__    							=				self.get_tokenizer()

        snake_case__    							=				WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE   ,					feature_extractor=__SCREAMING_SNAKE_CASE     )

        snake_case__    							=				[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

        snake_case__    							=				processor.batch_decode(__SCREAMING_SNAKE_CASE     )
        snake_case__    							=				tokenizer.batch_decode(__SCREAMING_SNAKE_CASE     )

        self.assertListEqual(__SCREAMING_SNAKE_CASE   ,					__SCREAMING_SNAKE_CASE     )

       def 		_SCREAMING_SNAKE_CASE(			self     ):






        '''simple docstring'''

        snake_case__    							=				self.get_feature_extractor()
        snake_case__    							=				self.get_tokenizer()

        snake_case__    							=				WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE   ,					feature_extractor=__SCREAMING_SNAKE_CASE     )

        self.assertListEqual(
            processor.model_input_names   ,					feature_extractor.model_input_names   ,					msg="`processor` and `feature_extractor` model input names do not match"   ,					)

       def 		_SCREAMING_SNAKE_CASE(			self     ):






        '''simple docstring'''

        snake_case__    							=				self.get_feature_extractor()
        snake_case__    							=				self.get_tokenizer()

        snake_case__    							=				WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE   ,					feature_extractor=__SCREAMING_SNAKE_CASE     )
        snake_case__    							=				processor.get_decoder_prompt_ids(task="transcribe"   ,					no_timestamps=__SCREAMING_SNAKE_CASE     )

        self.assertIsInstance(__SCREAMING_SNAKE_CASE   ,					__SCREAMING_SNAKE_CASE     )
        for ids in forced_decoder_ids:
         self.assertIsInstance(__SCREAMING_SNAKE_CASE   ,					(list, tuple)     )

        snake_case__    							=				[TRANSCRIBE, NOTIMESTAMPS]
        self.assertListEqual([ids[-1] for ids in forced_decoder_ids]   ,					__SCREAMING_SNAKE_CASE     )

       def 		_SCREAMING_SNAKE_CASE(			self     ):






        '''simple docstring'''

        snake_case__    							=				WhisperProcessor(tokenizer=self.get_tokenizer()   ,					feature_extractor=self.get_feature_extractor()     )
        snake_case__    							=				processor.get_prompt_ids("Mr. Quilter"     )
        snake_case__    							=				processor.tokenizer.decode(__SCREAMING_SNAKE_CASE     )

        self.assertListEqual(prompt_ids.tolist()   ,					[5_0360, 1770, 13, 2264, 346, 353]     )
        self.assertEqual(__SCREAMING_SNAKE_CASE   ,					"<|startofprev|> Mr. Quilter"     )

       def 		_SCREAMING_SNAKE_CASE(			self     ):






        '''simple docstring'''

        snake_case__    							=				WhisperProcessor(tokenizer=self.get_tokenizer()   ,					feature_extractor=self.get_feature_extractor()     )
        snake_case__    							=				processor.get_prompt_ids(""     )
        snake_case__    							=				processor.tokenizer.decode(__SCREAMING_SNAKE_CASE     )

        self.assertListEqual(prompt_ids.tolist()   ,					[5_0360, 220]     )
        self.assertEqual(__SCREAMING_SNAKE_CASE   ,					"<|startofprev|> "     )

       def 		_SCREAMING_SNAKE_CASE(			self     ):






        '''simple docstring'''

        snake_case__    							=				WhisperProcessor(tokenizer=self.get_tokenizer()   ,					feature_extractor=self.get_feature_extractor()     )

        def _test_prompt_error_raised_helper(__SCREAMING_SNAKE_CASE   ,					__SCREAMING_SNAKE_CASE     ):
         with pytest.raises(__SCREAMING_SNAKE_CASE     ) as excinfo:
          processor.get_prompt_ids(__SCREAMING_SNAKE_CASE     )
         snake_case__    							=				F"Encountered text in the prompt corresponding to disallowed special token: {special_token}."
         self.assertEqual(__SCREAMING_SNAKE_CASE   ,					str(excinfo.value     )     )

        _test_prompt_error_raised_helper("<|startofprev|> test"   ,					"<|startofprev|>"     )
        _test_prompt_error_raised_helper("test <|notimestamps|>"   ,					"<|notimestamps|>"     )
        _test_prompt_error_raised_helper("test <|zh|> test <|transcribe|>"   ,					"<|zh|>"     )








"""simple docstring"""


from math import sqrt





def 							a__			(  _UpperCAmelCase	)    ->  list[int]:

 '''simple docstring'''






 snake_case__    							=				[1]
 for i in range(2	,     int(sqrt(_UpperCAmelCase	)	) + 1	,     1	):
  if number % i == 0:
   values.append(_UpperCAmelCase	)
   if int(number // i	) != i:
    values.append(int(number // i	)	)
 return sorted(_UpperCAmelCase	)





def 							a__			(  _UpperCAmelCase	)    ->  bool:

 '''simple docstring'''






 return sum(factors(_UpperCAmelCase	)	) > n





def 							a__			(  _UpperCAmelCase	)    ->  bool:

 '''simple docstring'''






 snake_case__    							=				factors(_UpperCAmelCase	)
 snake_case__    							=				len(_UpperCAmelCase	)
 snake_case__    							=				[[0 for i in range(number + 1	)] for j in range(r + 1	)]
 for i in range(r + 1	):
  snake_case__    							=				True

 for i in range(1	,     number + 1	):
  snake_case__    							=				False

 for i in range(1	,     r + 1	):
  for j in range(1	,     number + 1	):
   if j < values[i - 1]:
    snake_case__    							=				subset[i - 1][j]
   else:
    snake_case__    							=				subset[i - 1][j] or subset[i - 1][j - values[i - 1]]

 return subset[r][number] != 0





def 							a__			(  _UpperCAmelCase	)    ->  bool:

 '''simple docstring'''






 return abundant(_UpperCAmelCase	) and not semi_perfect(_UpperCAmelCase	)


if __name__ == "__main__":
   import doctest

   doctest.testmod(verbose=True)
   for number in (6_9, 7_0, 7_1):
      print(f'''{number} is {'' if weird(number) else 'not '}weird.''')

