import collections
import importlib.util
import os
import re
from pathlib import Path


lowercase_     :   List[str] 				=				'src/transformers'


# Matches is_xxx_available()
lowercase_     :   Optional[int] 				=				re.compile(R'is\_([a-z_]*)_available()')
# Catches a one-line _import_struct = {xxx}
lowercase_     :   Dict 				=				re.compile(R'^_import_structure\s+=\s+\{([^\}]+)\}')
# Catches a line with a key-values pattern: "bla": ["foo", "bar"]
lowercase_     :   int 				=				re.compile(R'\s+"\S*":\s+\[([^\]]*)\]')
# Catches a line if not is_foo_available
lowercase_     :   Tuple 				=				re.compile(R'^\s*if\s+not\s+is\_[a-z_]*\_available\(\)')
# Catches a line _import_struct["bla"].append("foo")
lowercase_     :   int 				=				re.compile(R'^\s*_import_structure\["\S*"\]\.append\("(\S*)"\)')
# Catches a line _import_struct["bla"].extend(["foo", "bar"]) or _import_struct["bla"] = ["foo", "bar"]
lowercase_     :   List[Any] 				=				re.compile(R'^\s*_import_structure\[\S*\](?:\.extend\(|\s*=\s+)\[([^\]]*)\]')
# Catches a line with an object between quotes and a comma:     "MyModel",
lowercase_     :   Optional[int] 				=				re.compile('^\s+"([^"]+)",')
# Catches a line with objects between brackets only:    ["foo", "bar"],
lowercase_     :   Dict 				=				re.compile('^\s+\[([^\]]+)\]')
# Catches a line with from foo import bar, bla, boo
lowercase_     :   Union[str, Any] 				=				re.compile(R'\s+from\s+\S*\s+import\s+([^\(\s].*)\n')
# Catches a line with try:
lowercase_     :   List[Any] 				=				re.compile(R'^\s*try:')
# Catches a line with else:
lowercase_     :   List[Any] 				=				re.compile(R'^\s*else:')







def 			A__      (	snake_case_ :		Union[str, Any]      ):
 if _re_test_backend.search(snake_case_      ) is None:
  return None
 SCREAMING_SNAKE_CASE__:   Optional[Any]=      [b[0] for b in _re_backend.findall(snake_case_      )]
 backends.sort()
 return "_and_".join(snake_case_      )







def 			A__      (	snake_case_ :		Optional[int]      ):
 with open(snake_case_       ,				'''r'''       ,				encoding='''utf-8'''       ,				newline='''\n'''      ) as f:
  SCREAMING_SNAKE_CASE__:   str=      f.readlines()

 SCREAMING_SNAKE_CASE__:   Union[str, Any]=      0
 while line_index < len(snake_case_      ) and not lines[line_index].startswith('''_import_structure = {'''      ):
  line_index += 1

 # If this is a traditional init, just return.
 if line_index >= len(snake_case_      ):
  return None

 # First grab the objects without a specific backend in _import_structure
 SCREAMING_SNAKE_CASE__:   int=      []
 while not lines[line_index].startswith('''if TYPE_CHECKING'''      ) and find_backend(lines[line_index]      ) is None:
  SCREAMING_SNAKE_CASE__:   List[Any]=      lines[line_index]
  # If we have everything on a single line, let's deal with it.
  if _re_one_line_import_struct.search(snake_case_      ):
   SCREAMING_SNAKE_CASE__:   Optional[int]=      _re_one_line_import_struct.search(snake_case_      ).groups()[0]
   SCREAMING_SNAKE_CASE__:   Optional[Any]=      re.findall('''\[([^\]]+)\]'''       ,				snake_case_      )
   for imp in imports:
    objects.extend([obj[1:-1] for obj in imp.split(''', '''      )]      )
   line_index += 1
   continue
  SCREAMING_SNAKE_CASE__:   Optional[Any]=      _re_import_struct_key_value.search(snake_case_      )
  if single_line_import_search is not None:
   SCREAMING_SNAKE_CASE__:   Union[str, Any]=      [obj[1:-1] for obj in single_line_import_search.groups()[0].split(''', '''      ) if len(snake_case_      ) > 0]
   objects.extend(snake_case_      )
  elif line.startswith(''' ''' * 8 + '''"'''      ):
   objects.append(line[9:-3]      )
  line_index += 1

 SCREAMING_SNAKE_CASE__:   Dict=      {'''none''': objects}
 # Let's continue with backend-specific objects in _import_structure
 while not lines[line_index].startswith('''if TYPE_CHECKING'''      ):
  # If the line is an if not is_backend_available, we grab all objects associated.
  SCREAMING_SNAKE_CASE__:   Optional[int]=      find_backend(lines[line_index]      )
  # Check if the backend declaration is inside a try block:
  if _re_try.search(lines[line_index - 1]      ) is None:
   SCREAMING_SNAKE_CASE__:   List[Any]=      None

  if backend is not None:
   line_index += 1

   # Scroll until we hit the else block of try-except-else
   while _re_else.search(lines[line_index]      ) is None:
    line_index += 1

   line_index += 1

   SCREAMING_SNAKE_CASE__:   List[str]=      []
   # Until we unindent, add backend objects to the list
   while len(lines[line_index]      ) <= 1 or lines[line_index].startswith(''' ''' * 4      ):
    SCREAMING_SNAKE_CASE__:   int=      lines[line_index]
    if _re_import_struct_add_one.search(snake_case_      ) is not None:
     objects.append(_re_import_struct_add_one.search(snake_case_      ).groups()[0]      )
    elif _re_import_struct_add_many.search(snake_case_      ) is not None:
     SCREAMING_SNAKE_CASE__:   Tuple=      _re_import_struct_add_many.search(snake_case_      ).groups()[0].split(''', '''      )
     SCREAMING_SNAKE_CASE__:   List[str]=      [obj[1:-1] for obj in imports if len(snake_case_      ) > 0]
     objects.extend(snake_case_      )
    elif _re_between_brackets.search(snake_case_      ) is not None:
     SCREAMING_SNAKE_CASE__:   List[Any]=      _re_between_brackets.search(snake_case_      ).groups()[0].split(''', '''      )
     SCREAMING_SNAKE_CASE__:   int=      [obj[1:-1] for obj in imports if len(snake_case_      ) > 0]
     objects.extend(snake_case_      )
    elif _re_quote_object.search(snake_case_      ) is not None:
     objects.append(_re_quote_object.search(snake_case_      ).groups()[0]      )
    elif line.startswith(''' ''' * 8 + '''"'''      ):
     objects.append(line[9:-3]      )
    elif line.startswith(''' ''' * 12 + '''"'''      ):
     objects.append(line[13:-3]      )
    line_index += 1

   SCREAMING_SNAKE_CASE__:   List[Any]=      objects
  else:
   line_index += 1

    # At this stage we are in the TYPE_CHECKING part, first grab the objects without a specific backend
 SCREAMING_SNAKE_CASE__:   Dict=      []
 while (
     line_index < len(snake_case_      )
     and find_backend(lines[line_index]      ) is None
     and not lines[line_index].startswith('''else'''      )
 ):
  SCREAMING_SNAKE_CASE__:   Tuple=      lines[line_index]
  SCREAMING_SNAKE_CASE__:   Any=      _re_import.search(snake_case_      )
  if single_line_import_search is not None:
   objects.extend(single_line_import_search.groups()[0].split(''', '''      )      )
  elif line.startswith(''' ''' * 8      ):
   objects.append(line[8:-2]      )
  line_index += 1

 SCREAMING_SNAKE_CASE__:   str=      {'''none''': objects}
 # Let's continue with backend-specific objects
 while line_index < len(snake_case_      ):
  # If the line is an if is_backend_available, we grab all objects associated.
  SCREAMING_SNAKE_CASE__:   int=      find_backend(lines[line_index]      )
  # Check if the backend declaration is inside a try block:
  if _re_try.search(lines[line_index - 1]      ) is None:
   SCREAMING_SNAKE_CASE__:   List[Any]=      None

  if backend is not None:
   line_index += 1

   # Scroll until we hit the else block of try-except-else
   while _re_else.search(lines[line_index]      ) is None:
    line_index += 1

   line_index += 1

   SCREAMING_SNAKE_CASE__:   Union[str, Any]=      []
   # Until we unindent, add backend objects to the list
   while len(lines[line_index]      ) <= 1 or lines[line_index].startswith(''' ''' * 8      ):
    SCREAMING_SNAKE_CASE__:   Dict=      lines[line_index]
    SCREAMING_SNAKE_CASE__:   Optional[int]=      _re_import.search(snake_case_      )
    if single_line_import_search is not None:
     objects.extend(single_line_import_search.groups()[0].split(''', '''      )      )
    elif line.startswith(''' ''' * 12      ):
     objects.append(line[12:-2]      )
    line_index += 1

   SCREAMING_SNAKE_CASE__:   List[Any]=      objects
  else:
   line_index += 1

 return import_dict_objects, type_hint_objects







def 			A__      (	snake_case_ :		Tuple       ,				snake_case_ :		Any      ):

 def find_duplicates(snake_case_ :		List[str]      ):
  return [k for k, v in collections.Counter(snake_case_      ).items() if v > 1]

 if list(import_dict_objects.keys()      ) != list(type_hint_objects.keys()      ):
  return ["Both sides of the init do not have the same backends!"]

 SCREAMING_SNAKE_CASE__:   Optional[int]=      []
 for key in import_dict_objects.keys():
  SCREAMING_SNAKE_CASE__:   List[str]=      find_duplicates(import_dict_objects[key]      )
  if duplicate_imports:
   errors.append(F'Duplicate _import_structure definitions for: {duplicate_imports}'      )
  SCREAMING_SNAKE_CASE__:   Union[str, Any]=      find_duplicates(type_hint_objects[key]      )
  if duplicate_type_hints:
   errors.append(F'Duplicate TYPE_CHECKING objects for: {duplicate_type_hints}'      )

  if sorted(set(import_dict_objects[key]      )      ) != sorted(set(type_hint_objects[key]      )      ):
   SCREAMING_SNAKE_CASE__:   Any=      '''base imports''' if key == '''none''' else F'{key} backend'
   errors.append(F'Differences for {name}:'      )
   for a in type_hint_objects[key]:
    if a not in import_dict_objects[key]:
     errors.append(F'  {a} in TYPE_HINT but not in _import_structure.'      )
   for a in import_dict_objects[key]:
    if a not in type_hint_objects[key]:
     errors.append(F'  {a} in _import_structure but not in TYPE_HINT.'      )
 return errors







def 			A__      (	):
 SCREAMING_SNAKE_CASE__:   Dict=      []
 for root, _, files in os.walk(snake_case_      ):
  if "__init__.py" in files:
   SCREAMING_SNAKE_CASE__:   List[Any]=      os.path.join(snake_case_       ,				'''__init__.py'''      )
   SCREAMING_SNAKE_CASE__:   List[Any]=      parse_init(snake_case_      )
   if objects is not None:
    SCREAMING_SNAKE_CASE__:   int=      analyze_results(*snake_case_      )
    if len(snake_case_      ) > 0:
     SCREAMING_SNAKE_CASE__:   Dict=      F'Problem in {fname}, both halves do not define the same objects.\n{errors[0]}'
     failures.append('''\n'''.join(snake_case_      )      )
 if len(snake_case_      ) > 0:
  raise ValueError('''\n\n'''.join(snake_case_      )      )







def 			A__      (	):
 SCREAMING_SNAKE_CASE__:   str=      []
 for path, directories, files in os.walk(snake_case_      ):
  for folder in directories:
   # Ignore private modules
   if folder.startswith('''_'''      ):
    directories.remove(snake_case_      )
    continue
   # Ignore leftovers from branches (empty folders apart from pycache)
   if len(list((Path(snake_case_      ) / folder).glob('''*.py'''      )      )      ) == 0:
    continue
   SCREAMING_SNAKE_CASE__:   str=      str((Path(snake_case_      ) / folder).relative_to(snake_case_      )      )
   SCREAMING_SNAKE_CASE__:   Optional[int]=      short_path.replace(os.path.sep       ,				'''.'''      )
   submodules.append(snake_case_      )
  for fname in files:
   if fname == "__init__.py":
    continue
   SCREAMING_SNAKE_CASE__:   Optional[Any]=      str((Path(snake_case_      ) / fname).relative_to(snake_case_      )      )
   SCREAMING_SNAKE_CASE__:   Dict=      short_path.replace('''.py'''       ,				''''''      ).replace(os.path.sep       ,				'''.'''      )
   if len(submodule.split('''.'''      )      ) == 1:
    submodules.append(snake_case_      )
 return submodules


lowercase_     :   Optional[Any] 				=				[
    'convert_pytorch_checkpoint_to_tf2',
    'modeling_flax_pytorch_utils',
]







def 			A__      (	):
 # This is to make sure the transformers module imported is the one in the repo.
 SCREAMING_SNAKE_CASE__:   Optional[Any]=      importlib.util.spec_from_file_location(
     '''transformers'''       ,				os.path.join(snake_case_       ,				'''__init__.py'''      )       ,				submodule_search_locations=[PATH_TO_TRANSFORMERS]       ,				)
 SCREAMING_SNAKE_CASE__:   str=      spec.loader.load_module()

 SCREAMING_SNAKE_CASE__:   Dict=      [
     module
     for module in get_transformers_submodules()
     if module not in IGNORE_SUBMODULES and module not in transformers._import_structure.keys()
 ]
 if len(snake_case_      ) > 0:
  SCREAMING_SNAKE_CASE__:   Optional[Any]=      '''\n'''.join(F'- {module}' for module in module_not_registered      )
  raise ValueError(
      '''The following submodules are not properly registered in the main init of Transformers:\n'''
      F'{list_of_modules}\n'
      '''Make sure they appear somewhere in the keys of `_import_structure` with an empty list as value.'''      )


if __name__ == "__main__":
      check_all_inits()
      check_submodules()


import itertools
import os
import random
import tempfile
import unittest

import numpy as np
from datasets import load_dataset

from transformers import is_speech_available
from transformers.testing_utils import check_json_file_has_correct_format, require_torch, require_torchaudio
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_speech_available():
      from transformers import WhisperFeatureExtractor

if is_torch_available():
      import torch

lowercase_     :   Any 				=				random.Random()







def 			A__      (	snake_case_ :		int       ,				snake_case_ :		Tuple=1.0       ,				snake_case_ :		Optional[Any]=None       ,				snake_case_ :		List[Any]=None      ):
 if rng is None:
  SCREAMING_SNAKE_CASE__:   Tuple=      global_rng

 SCREAMING_SNAKE_CASE__:   List[str]=      []
 for batch_idx in range(shape[0]      ):
  values.append([]      )
  for _ in range(shape[1]      ):
   values[-1].append(rng.random() * scale      )

 return values






@require_torch
@require_torchaudio
class 		_lowerCamelCase		(   unittest.TestCase    ):
    def __init__(  self , lowerCAmelCase , lowerCAmelCase=7 , lowerCAmelCase=400 , lowerCAmelCase=2000 , lowerCAmelCase=10 , lowerCAmelCase=160 , lowerCAmelCase=8 , lowerCAmelCase=0.0 , lowerCAmelCase=4000 , lowerCAmelCase=False , lowerCAmelCase=True , )       ->					Tuple:
     SCREAMING_SNAKE_CASE__:   Any=      parent
     SCREAMING_SNAKE_CASE__:   Dict=      batch_size
     SCREAMING_SNAKE_CASE__:   List[Any]=      min_seq_length
     SCREAMING_SNAKE_CASE__:   Tuple=      max_seq_length
     SCREAMING_SNAKE_CASE__:   Optional[int]=      (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
     SCREAMING_SNAKE_CASE__:   str=      padding_value
     SCREAMING_SNAKE_CASE__:   Union[str, Any]=      sampling_rate
     SCREAMING_SNAKE_CASE__:   List[str]=      return_attention_mask
     SCREAMING_SNAKE_CASE__:   Union[str, Any]=      do_normalize
     SCREAMING_SNAKE_CASE__:   Optional[int]=      feature_size
     SCREAMING_SNAKE_CASE__:   Union[str, Any]=      chunk_length
     SCREAMING_SNAKE_CASE__:   List[Any]=      hop_length
    def 						UpperCamelCase_				(  self   )       ->					str:
     return {
         "feature_size": self.feature_size,
         "hop_length": self.hop_length,
         "chunk_length": self.chunk_length,
         "padding_value": self.padding_value,
         "sampling_rate": self.sampling_rate,
         "return_attention_mask": self.return_attention_mask,
         "do_normalize": self.do_normalize,
     }



    def 						UpperCamelCase_				(  self , lowerCAmelCase=False , lowerCAmelCase=False   )       ->					Optional[Any]:
     def _flatten(lowerCAmelCase   ):
      return list(itertools.chain(*lowerCAmelCase   )   )

     if equal_length:
      SCREAMING_SNAKE_CASE__:   Dict=      [floats_list((self.max_seq_length, self.feature_size)   ) for _ in range(self.batch_size   )]
     else:
      # make sure that inputs increase in size
      SCREAMING_SNAKE_CASE__:   Union[str, Any]=      [
          floats_list((x, self.feature_size)   )
          for x in range(self.min_seq_length , self.max_seq_length , self.seq_length_diff   )
      ]
     if numpify:
      SCREAMING_SNAKE_CASE__:   str=      [np.asarray(lowerCAmelCase   ) for x in speech_inputs]
     return speech_inputs






@require_torch
@require_torchaudio
class 		_lowerCamelCase		(   UpperCamelCase_    ,     unittest.TestCase    ):
    __a  =      WhisperFeatureExtractor if is_speech_available() else None
    def 						UpperCamelCase_				(  self   )       ->					Dict:
     SCREAMING_SNAKE_CASE__:   Any=      WhisperFeatureExtractionTester(self   )
    def 						UpperCamelCase_				(  self   )       ->					int:
     SCREAMING_SNAKE_CASE__:   List[str]=      self.feature_extraction_class(**self.feat_extract_dict   )

     with tempfile.TemporaryDirectory() as tmpdirname:
      SCREAMING_SNAKE_CASE__:   List[str]=      feat_extract_first.save_pretrained(lowerCAmelCase   )[0]
      check_json_file_has_correct_format(lowerCAmelCase   )
      SCREAMING_SNAKE_CASE__:   str=      self.feature_extraction_class.from_pretrained(lowerCAmelCase   )

     SCREAMING_SNAKE_CASE__:   int=      feat_extract_first.to_dict()
     SCREAMING_SNAKE_CASE__:   Union[str, Any]=      feat_extract_second.to_dict()
     SCREAMING_SNAKE_CASE__:   int=      feat_extract_first.mel_filters
     SCREAMING_SNAKE_CASE__:   Any=      feat_extract_second.mel_filters
     self.assertTrue(np.allclose(lowerCAmelCase , lowerCAmelCase   )   )
     self.assertEqual(lowerCAmelCase , lowerCAmelCase   )
    def 						UpperCamelCase_				(  self   )       ->					Tuple:
     SCREAMING_SNAKE_CASE__:   List[Any]=      self.feature_extraction_class(**self.feat_extract_dict   )

     with tempfile.TemporaryDirectory() as tmpdirname:
      SCREAMING_SNAKE_CASE__:   List[str]=      os.path.join(lowerCAmelCase , '''feat_extract.json'''   )
      feat_extract_first.to_json_file(lowerCAmelCase   )
      SCREAMING_SNAKE_CASE__:   Tuple=      self.feature_extraction_class.from_json_file(lowerCAmelCase   )

     SCREAMING_SNAKE_CASE__:   Tuple=      feat_extract_first.to_dict()
     SCREAMING_SNAKE_CASE__:   Union[str, Any]=      feat_extract_second.to_dict()
     SCREAMING_SNAKE_CASE__:   List[str]=      feat_extract_first.mel_filters
     SCREAMING_SNAKE_CASE__:   Optional[int]=      feat_extract_second.mel_filters
     self.assertTrue(np.allclose(lowerCAmelCase , lowerCAmelCase   )   )
     self.assertEqual(lowerCAmelCase , lowerCAmelCase   )
    def 						UpperCamelCase_				(  self   )       ->					Tuple:
     # Tests that all call wrap to encode_plus and batch_encode_plus
     SCREAMING_SNAKE_CASE__:   Union[str, Any]=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
     # create three inputs of length 800, 1000, and 1200
     SCREAMING_SNAKE_CASE__:   str=      [floats_list((1, x)   )[0] for x in range(800 , 1400 , 200   )]
     SCREAMING_SNAKE_CASE__:   Tuple=      [np.asarray(lowerCAmelCase   ) for speech_input in speech_inputs]

     # Test feature size
     SCREAMING_SNAKE_CASE__:   Optional[Any]=      feature_extractor(lowerCAmelCase , padding='''max_length''' , return_tensors='''np'''   ).input_features
     self.assertTrue(input_features.ndim == 3   )
     self.assertTrue(input_features.shape[-1] == feature_extractor.nb_max_frames   )
     self.assertTrue(input_features.shape[-2] == feature_extractor.feature_size   )

     # Test not batched input
     SCREAMING_SNAKE_CASE__:   List[str]=      feature_extractor(speech_inputs[0] , return_tensors='''np'''   ).input_features
     SCREAMING_SNAKE_CASE__:   Union[str, Any]=      feature_extractor(np_speech_inputs[0] , return_tensors='''np'''   ).input_features
     self.assertTrue(np.allclose(lowerCAmelCase , lowerCAmelCase , atol=1e-3   )   )

     # Test batched
     SCREAMING_SNAKE_CASE__:   Optional[int]=      feature_extractor(lowerCAmelCase , return_tensors='''np'''   ).input_features
     SCREAMING_SNAKE_CASE__:   List[Any]=      feature_extractor(lowerCAmelCase , return_tensors='''np'''   ).input_features
     for enc_seq_a, enc_seq_a in zip(lowerCAmelCase , lowerCAmelCase   ):
      self.assertTrue(np.allclose(lowerCAmelCase , lowerCAmelCase , atol=1e-3   )   )

     # Test 2-D numpy arrays are batched.
     SCREAMING_SNAKE_CASE__:   Optional[int]=      [floats_list((1, x)   )[0] for x in (800, 800, 800)]
     SCREAMING_SNAKE_CASE__:   Any=      np.asarray(lowerCAmelCase   )
     SCREAMING_SNAKE_CASE__:   List[str]=      feature_extractor(lowerCAmelCase , return_tensors='''np'''   ).input_features
     SCREAMING_SNAKE_CASE__:   List[Any]=      feature_extractor(lowerCAmelCase , return_tensors='''np'''   ).input_features
     for enc_seq_a, enc_seq_a in zip(lowerCAmelCase , lowerCAmelCase   ):
      self.assertTrue(np.allclose(lowerCAmelCase , lowerCAmelCase , atol=1e-3   )   )

     # Test truncation required
     SCREAMING_SNAKE_CASE__:   str=      [floats_list((1, x)   )[0] for x in range(200 , (feature_extractor.n_samples + 500) , 200   )]
     SCREAMING_SNAKE_CASE__:   str=      [np.asarray(lowerCAmelCase   ) for speech_input in speech_inputs]

     SCREAMING_SNAKE_CASE__:   str=      [x[: feature_extractor.n_samples] for x in speech_inputs]
     SCREAMING_SNAKE_CASE__:   int=      [np.asarray(lowerCAmelCase   ) for speech_input in speech_inputs_truncated]

     SCREAMING_SNAKE_CASE__:   Dict=      feature_extractor(lowerCAmelCase , return_tensors='''np'''   ).input_features
     SCREAMING_SNAKE_CASE__:   List[str]=      feature_extractor(lowerCAmelCase , return_tensors='''np'''   ).input_features
     for enc_seq_a, enc_seq_a in zip(lowerCAmelCase , lowerCAmelCase   ):
      self.assertTrue(np.allclose(lowerCAmelCase , lowerCAmelCase , atol=1e-3   )   )
    def 						UpperCamelCase_				(  self   )       ->					Dict:
     import torch

     SCREAMING_SNAKE_CASE__:   List[Any]=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
     SCREAMING_SNAKE_CASE__:   Dict=      np.random.rand(100 , 32   ).astype(np.floataa   )
     SCREAMING_SNAKE_CASE__:   Union[str, Any]=      np_speech_inputs.tolist()

     for inputs in [py_speech_inputs, np_speech_inputs]:
      SCREAMING_SNAKE_CASE__:   Tuple=      feature_extractor.pad([{'''input_features''': inputs}] , return_tensors='''np'''   )
      self.assertTrue(np_processed.input_features.dtype == np.floataa   )
      SCREAMING_SNAKE_CASE__:   Any=      feature_extractor.pad([{'''input_features''': inputs}] , return_tensors='''pt'''   )
      self.assertTrue(pt_processed.input_features.dtype == torch.floataa   )
    def 						UpperCamelCase_				(  self , lowerCAmelCase   )       ->					str:
     SCREAMING_SNAKE_CASE__:   Union[str, Any]=      load_dataset('''hf-internal-testing/librispeech_asr_dummy''' , '''clean''' , split='''validation'''   )
     # automatic decoding with librispeech
     SCREAMING_SNAKE_CASE__:   List[str]=      ds.sort('''id'''   ).select(range(lowerCAmelCase   )   )[:num_samples]['''audio''']

     return [x["array"] for x in speech_samples]
    def 						UpperCamelCase_				(  self   )       ->					int:
     # fmt: off
     SCREAMING_SNAKE_CASE__:   Dict=      torch.tensor(
         [
             0.1193, -0.0946, -0.1098, -0.0196, 0.0225, -0.0690, -0.1736, 0.0951,
             0.0971, -0.0817, -0.0702, 0.0162, 0.0260, 0.0017, -0.0192, -0.1678,
             0.0709, -0.1867, -0.0655, -0.0274, -0.0234, -0.1884, -0.0516, -0.0554,
             -0.0274, -0.1425, -0.1423, 0.0837, 0.0377, -0.0854
         ]   )
     # fmt: on

     SCREAMING_SNAKE_CASE__:   str=      self._load_datasamples(1   )
     SCREAMING_SNAKE_CASE__:   Dict=      WhisperFeatureExtractor()
     SCREAMING_SNAKE_CASE__:   Optional[int]=      feature_extractor(lowerCAmelCase , return_tensors='''pt'''   ).input_features
     self.assertEqual(input_features.shape , (1, 80, 3000)   )
     self.assertTrue(torch.allclose(input_features[0, 0, :30] , lowerCAmelCase , atol=1e-4   )   )



    def 						UpperCamelCase_				(  self   )       ->					Optional[Any]:
     SCREAMING_SNAKE_CASE__:   List[str]=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
     SCREAMING_SNAKE_CASE__:   Dict=      self._load_datasamples(1   )[0]
     SCREAMING_SNAKE_CASE__:   str=      ((audio - audio.min()) / (audio.max() - audio.min())) * 65535  # Rescale to [0, 65535] to show issue
     SCREAMING_SNAKE_CASE__:   Optional[int]=      feat_extract.zero_mean_unit_var_norm([audio] , attention_mask=lowerCAmelCase   )[0]

     self.assertTrue(np.all(np.mean(lowerCAmelCase   ) < 1e-3   )   )
     self.assertTrue(np.all(np.abs(np.var(lowerCAmelCase   ) - 1   ) < 1e-3   )   )

