"""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       			=      5_03_58
__A       			=      5_03_62






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



  def        lowerCAmelCase_				(		self   :    Optional[Any]     )      -> Union[str, Any]:
      __a			      =						"""openai/whisper-small.en"""
      __a			      =						tempfile.mkdtemp()



  def        lowerCAmelCase_				(		self   :    Dict						,  **lowerCamelCase_   :    Optional[Any]     )      -> str:
      return WhisperTokenizer.from_pretrained(self.checkpoint						,  **lowerCamelCase_     )



  def        lowerCAmelCase_				(		self   :    List[str]						,  **lowerCamelCase_   :    List[str]     )      -> int:
      return WhisperFeatureExtractor.from_pretrained(self.checkpoint						,  **lowerCamelCase_     )



  def        lowerCAmelCase_				(		self   :    Optional[Any]     )      -> int:
      shutil.rmtree(self.tmpdirname     )



  def        lowerCAmelCase_				(		self   :    List[str]     )      -> List[str]:
      __a			      =						self.get_tokenizer()
      __a			      =						self.get_feature_extractor()

      __a			      =						WhisperProcessor(tokenizer=lowerCamelCase_						,  feature_extractor=lowerCamelCase_     )

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

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

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



  def        lowerCAmelCase_				(		self   :    Dict     )      -> str:
      __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=lowerCamelCase_						,  padding_value=1.0     )

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

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

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



  def        lowerCAmelCase_				(		self   :    Optional[Any]     )      -> int:
      __a			      =						self.get_feature_extractor()
      __a			      =						self.get_tokenizer()

      __a			      =						WhisperProcessor(tokenizer=lowerCamelCase_						,  feature_extractor=lowerCamelCase_     )

      __a			      =						floats_list((3, 10_00)     )

      __a			      =						feature_extractor(lowerCamelCase_						,  return_tensors="""np"""     )
      __a			      =						processor(lowerCamelCase_						,  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   :    Dict     )      -> Tuple:
      __a			      =						self.get_feature_extractor()
      __a			      =						self.get_tokenizer()

      __a			      =						WhisperProcessor(tokenizer=lowerCamelCase_						,  feature_extractor=lowerCamelCase_     )

      __a			      =						"""This is a test string"""

      __a			      =						processor(text=lowerCamelCase_     )

      __a			      =						tokenizer(lowerCamelCase_     )

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



  def        lowerCAmelCase_				(		self   :    Dict     )      -> Union[str, Any]:
      __a			      =						self.get_feature_extractor()
      __a			      =						self.get_tokenizer()

      __a			      =						WhisperProcessor(tokenizer=lowerCamelCase_						,  feature_extractor=lowerCamelCase_     )

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

      __a			      =						processor.batch_decode(lowerCamelCase_     )
      __a			      =						tokenizer.batch_decode(lowerCamelCase_     )

      self.assertListEqual(lowerCamelCase_						,  lowerCamelCase_     )



  def        lowerCAmelCase_				(		self   :    Tuple     )      -> Union[str, Any]:
      __a			      =						self.get_feature_extractor()
      __a			      =						self.get_tokenizer()

      __a			      =						WhisperProcessor(tokenizer=lowerCamelCase_						,  feature_extractor=lowerCamelCase_     )

      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   :    List[str]     )      -> Dict:
      __a			      =						self.get_feature_extractor()
      __a			      =						self.get_tokenizer()

      __a			      =						WhisperProcessor(tokenizer=lowerCamelCase_						,  feature_extractor=lowerCamelCase_     )
      __a			      =						processor.get_decoder_prompt_ids(task="""transcribe"""						,  no_timestamps=lowerCamelCase_     )

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

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



  def        lowerCAmelCase_				(		self   :    Dict     )      -> int:
      __a			      =						WhisperProcessor(tokenizer=self.get_tokenizer()						,  feature_extractor=self.get_feature_extractor()     )
      __a			      =						processor.get_prompt_ids("""Mr. Quilter"""     )
      __a			      =						processor.tokenizer.decode(lowerCamelCase_     )

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



  def        lowerCAmelCase_				(		self   :    List[Any]     )      -> List[Any]:
      __a			      =						WhisperProcessor(tokenizer=self.get_tokenizer()						,  feature_extractor=self.get_feature_extractor()     )
      __a			      =						processor.get_prompt_ids(""""""     )
      __a			      =						processor.tokenizer.decode(lowerCamelCase_     )

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



  def        lowerCAmelCase_				(		self   :    List[Any]     )      -> int:
      __a			      =						WhisperProcessor(tokenizer=self.get_tokenizer()						,  feature_extractor=self.get_feature_extractor()     )

      def _test_prompt_error_raised_helper(lowerCamelCase_   :    Any						,  lowerCamelCase_   :    Tuple     ):
          with pytest.raises(lowerCamelCase_     ) as excinfo:
              processor.get_prompt_ids(lowerCamelCase_     )
          __a			      =						F"""Encountered text in the prompt corresponding to disallowed special token: {special_token}."""
          self.assertEqual(lowerCamelCase_						,  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"""


def 						UpperCamelCase				(	_lowerCAmelCase   :							Dict				, _lowerCAmelCase   :							Tuple						):
    __a			      =						len(_lowerCAmelCase						)
    # Create a stack and push index of fist element to it
    __a			      =						[]
    st.append(0						)

    # Span value of first element is always 1
    __a			      =						1

    # Calculate span values for rest of the elements
    for i in range(1				, _lowerCAmelCase						):
        # Pop elements from stack while stack is not
        # empty and top of stack is smaller than price[i]
        while len(_lowerCAmelCase						) > 0 and price[st[0]] <= price[i]:
            st.pop()

        # If stack becomes empty, then price[i] is greater
        # than all elements on left of it, i.e. price[0],
        # price[1], ..price[i-1]. Else the price[i]  is
        # greater than elements after top of stack
        __a			      =						i + 1 if len(_lowerCAmelCase						) <= 0 else (i - st[0])

        # Push this element to stack
        st.append(_lowerCAmelCase						)

def 						UpperCamelCase				(	_lowerCAmelCase   :							Dict				, _lowerCAmelCase   :							Optional[Any]						):
    for i in range(0				, _lowerCAmelCase						):
        print(arr[i]				, end=""" """						)


# Driver program to test above function
__A       			=      [10, 4, 5, 90, 1_20, 80]
__A       			=      [0 for i in range(len(price) + 1)]

# Fill the span values in array S[]
calculation_span(price, S)






print_array(S, len(price))
