





"""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


_snake_case	:						Union[str, Any]					=					5_0358
_snake_case	:						List[Any]					=					5_0362






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


					def       lowerCamelCase			(   self     :Optional[Any]						):
												A						=    """openai/whisper-small.en"""
												A						=    tempfile.mkdtemp()


					def       lowerCamelCase			(   self     :Union[str, Any]	,			**__UpperCamelCase     :Optional[int]						):
												return WhisperTokenizer.from_pretrained(self.checkpoint	,			**UpperCamelCase__						)


					def       lowerCamelCase			(   self     :int	,			**__UpperCamelCase     :Optional[int]						):
												return WhisperFeatureExtractor.from_pretrained(self.checkpoint	,			**UpperCamelCase__						)


					def       lowerCamelCase			(   self     :Any						):
												shutil.rmtree(self.tmpdirname						)


					def       lowerCamelCase			(   self     :int						):
												A						=    self.get_tokenizer()
												A						=    self.get_feature_extractor()

												A						=    WhisperProcessor(tokenizer=UpperCamelCase__	,			feature_extractor=UpperCamelCase__						)

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

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

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


					def       lowerCamelCase			(   self     :Optional[Any]						):
												A						=    WhisperProcessor(tokenizer=self.get_tokenizer()	,			feature_extractor=self.get_feature_extractor()						)
												processor.save_pretrained(self.tmpdirname						)

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

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

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

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


					def       lowerCamelCase			(   self     :Optional[int]						):
												A						=    self.get_feature_extractor()
												A						=    self.get_tokenizer()

												A						=    WhisperProcessor(tokenizer=UpperCamelCase__	,			feature_extractor=UpperCamelCase__						)

												A						=    floats_list((3, 10_00)						)

												A						=    feature_extractor(UpperCamelCase__	,			return_tensors="np"						)
												A						=    processor(UpperCamelCase__	,			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       lowerCamelCase			(   self     :Optional[int]						):
												A						=    self.get_feature_extractor()
												A						=    self.get_tokenizer()

												A						=    WhisperProcessor(tokenizer=UpperCamelCase__	,			feature_extractor=UpperCamelCase__						)

												A						=    """This is a test string"""

												A						=    processor(text=UpperCamelCase__						)

												A						=    tokenizer(UpperCamelCase__						)

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


					def       lowerCamelCase			(   self     :Dict						):
												A						=    self.get_feature_extractor()
												A						=    self.get_tokenizer()

												A						=    WhisperProcessor(tokenizer=UpperCamelCase__	,			feature_extractor=UpperCamelCase__						)

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

												A						=    processor.batch_decode(UpperCamelCase__						)
												A						=    tokenizer.batch_decode(UpperCamelCase__						)

												self.assertListEqual(UpperCamelCase__	,			UpperCamelCase__						)


					def       lowerCamelCase			(   self     :List[Any]						):
												A						=    self.get_feature_extractor()
												A						=    self.get_tokenizer()

												A						=    WhisperProcessor(tokenizer=UpperCamelCase__	,			feature_extractor=UpperCamelCase__						)

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


					def       lowerCamelCase			(   self     :Optional[int]						):
												A						=    self.get_feature_extractor()
												A						=    self.get_tokenizer()

												A						=    WhisperProcessor(tokenizer=UpperCamelCase__	,			feature_extractor=UpperCamelCase__						)
												A						=    processor.get_decoder_prompt_ids(task="transcribe"	,			no_timestamps=UpperCamelCase__						)

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

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


					def       lowerCamelCase			(   self     :Dict						):
												A						=    WhisperProcessor(tokenizer=self.get_tokenizer()	,			feature_extractor=self.get_feature_extractor()						)
												A						=    processor.get_prompt_ids("Mr. Quilter"						)
												A						=    processor.tokenizer.decode(UpperCamelCase__						)

												self.assertListEqual(prompt_ids.tolist()	,			[5_03_60, 17_70, 13, 22_64, 3_46, 3_53]						)
												self.assertEqual(UpperCamelCase__	,			"<|startofprev|> Mr. Quilter"						)


					def       lowerCamelCase			(   self     :Any						):
												A						=    WhisperProcessor(tokenizer=self.get_tokenizer()	,			feature_extractor=self.get_feature_extractor()						)
												A						=    processor.get_prompt_ids(""						)
												A						=    processor.tokenizer.decode(UpperCamelCase__						)

												self.assertListEqual(prompt_ids.tolist()	,			[5_03_60, 2_20]						)
												self.assertEqual(UpperCamelCase__	,			"<|startofprev|> "						)


					def       lowerCamelCase			(   self     :Optional[int]						):
												A						=    WhisperProcessor(tokenizer=self.get_tokenizer()	,			feature_extractor=self.get_feature_extractor()						)

												def _test_prompt_error_raised_helper(__UpperCamelCase     :Optional[Any]	,			__UpperCamelCase     :Any						):
																			with pytest.raises(UpperCamelCase__						) as excinfo:
																										processor.get_prompt_ids(UpperCamelCase__						)
																			A						=    f"Encountered text in the prompt corresponding to disallowed special token: {special_token}."
																			self.assertEqual(UpperCamelCase__	,			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 __future__ import annotations





def 					SCREAMING_SNAKE_CASE_			(UpperCamelCase							,     UpperCamelCase ) ->			Dict:
							lowerCamelCase__   :      List[str]			    =			0
							lowerCamelCase__   :      Tuple			    =			len(UpperCamelCase ) - 1
							while left <= right:
														lowerCamelCase__   :      List[str]			    =			(left + right) // 2
														if left == right:
																					if sorted_list[middle] < item:
																												lowerCamelCase__   :      Any			    =			middle + 1
																					break
														elif sorted_list[middle] < item:
																					lowerCamelCase__   :      Optional[Any]			    =			middle + 1
														else:
																					lowerCamelCase__   :      Dict			    =			middle - 1
							sorted_list.insert(UpperCamelCase							,     UpperCamelCase )
							return sorted_list





def 					SCREAMING_SNAKE_CASE_			(UpperCamelCase							,     UpperCamelCase ) ->			Tuple:
							lowerCamelCase__   :      Any			    =			[]
							while left and right:
														if left[0][0] < right[0][0]:
																					result.append(left.pop(0 ) )
														else:
																					result.append(right.pop(0 ) )
							return result + left + right





def 					SCREAMING_SNAKE_CASE_			(UpperCamelCase ) ->			Any:
							lowerCamelCase__   :      Optional[Any]			    =			len(UpperCamelCase )
							if length <= 1:
														return list_ad
							lowerCamelCase__   :      Tuple			    =			length // 2
							return merge(sortlist_ad(list_ad[:middle] )							,     sortlist_ad(list_ad[middle:] ) )





def 					SCREAMING_SNAKE_CASE_			(UpperCamelCase ) ->			list[int]:

							if len(UpperCamelCase ) <= 1:
														return collection
							lowerCamelCase__   :      int			    =			[]
							lowerCamelCase__   :      int			    =			False
							for i in range(0							,     len(UpperCamelCase )							,     2 ):
														if i == len(UpperCamelCase ) - 1:
																					lowerCamelCase__   :      List[Any]			    =			True
														else:
																					if collection[i] < collection[i + 1]:
																												two_paired_list.append([collection[i], collection[i + 1]] )
																					else:
																												two_paired_list.append([collection[i + 1], collection[i]] )
							lowerCamelCase__   :      List[Any]			    =			sortlist_ad(UpperCamelCase )
							lowerCamelCase__   :      List[Any]			    =			[i[0] for i in sorted_list_ad]
							result.append(sorted_list_ad[-1][1] )
							if has_last_odd_item:
														lowerCamelCase__   :      int			    =			collection[-1]
														lowerCamelCase__   :      str			    =			binary_search_insertion(UpperCamelCase							,     UpperCamelCase )
							lowerCamelCase__   :      Any			    =			False
							for i in range(len(UpperCamelCase ) - 1 ):
														if result[i] == collection[-1] and has_last_odd_item:
																					lowerCamelCase__   :      Any			    =			True
														lowerCamelCase__   :      Dict			    =			sorted_list_ad[i][1]
														# If last_odd_item is inserted before the item's index,
														# you should forward index one more.
														if is_last_odd_item_inserted_before_this_index:
																					lowerCamelCase__   :      List[str]			    =			result[: i + 2] + binary_search_insertion(result[i + 2 :]							,     UpperCamelCase )
														else:
																					lowerCamelCase__   :      Dict			    =			result[: i + 1] + binary_search_insertion(result[i + 1 :]							,     UpperCamelCase )

							return result


if __name__ == "__main__":
			_A      :     Tuple       	=input('''Enter numbers separated by a comma:\n''').strip()
			_A      :     List[Any]       	=[int(item) for item in user_input.split(''',''')]
			print(merge_insertion_sort(unsorted))

