

import itertools
import random
import unittest

import numpy as np

from transformers import BatchFeature, SpeechTaFeatureExtractor
from transformers.testing_utils import require_torch
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
  import torch


_a		       =   random.Random()







def _a (       SCREAMING_SNAKE_CASE		:			int    ,					SCREAMING_SNAKE_CASE		:			Union[str, Any]=1.0    ,					SCREAMING_SNAKE_CASE		:			List[str]=None    ,					SCREAMING_SNAKE_CASE		:			Any=None		)    ->    Any:

 """simple docstring"""






 if rng is None:
  __lowerCAmelCase:   List[str]   	=      global_rng

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

 return values






@require_torch
class 							A_ (		unittest.TestCase					):


     def __init__(							self			:		Optional[Any]			,  UpperCAmelCase			:		List[str]			,  UpperCAmelCase			:		Tuple=7			,  UpperCAmelCase			:		Union[str, Any]=4_0_0			,  UpperCAmelCase			:		Any=2_0_0_0			,  UpperCAmelCase			:		Dict=1			,  UpperCAmelCase			:		Optional[Any]=0.0			,  UpperCAmelCase			:		List[Any]=1_6_0_0_0			,  UpperCAmelCase			:		List[Any]=True			,  UpperCAmelCase			:		List[Any]=8_0			,  UpperCAmelCase			:		Dict=1_6			,  UpperCAmelCase			:		str=6_4			,  UpperCAmelCase			:		Tuple="hann_window"			,  UpperCAmelCase			:		Union[str, Any]=8_0			,  UpperCAmelCase			:		Optional[Any]=7_6_0_0			,  UpperCAmelCase			:		str=1E-10			,  UpperCAmelCase			:		Any=True			,  )							->	Union[str, Any]:
      __lowerCAmelCase:   Optional[int]   	=      parent
      __lowerCAmelCase:   Optional[Any]   	=      batch_size
      __lowerCAmelCase:   List[Any]   	=      min_seq_length
      __lowerCAmelCase:   List[Any]   	=      max_seq_length
      __lowerCAmelCase:   Any   	=      (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
      __lowerCAmelCase:   Tuple   	=      feature_size
      __lowerCAmelCase:   List[Any]   	=      padding_value
      __lowerCAmelCase:   Any   	=      sampling_rate
      __lowerCAmelCase:   Dict   	=      do_normalize
      __lowerCAmelCase:   Union[str, Any]   	=      num_mel_bins
      __lowerCAmelCase:   Any   	=      hop_length
      __lowerCAmelCase:   Any   	=      win_length
      __lowerCAmelCase:   Any   	=      win_function
      __lowerCAmelCase:   Optional[int]   	=      fmin
      __lowerCAmelCase:   int   	=      fmax
      __lowerCAmelCase:   Union[str, Any]   	=      mel_floor
      __lowerCAmelCase:   Union[str, Any]   	=      return_attention_mask


     def   UpperCAmelCase  (							self			:		Optional[int]					)							->	List[str]:
      return {
          "feature_size": self.feature_size,
          "padding_value": self.padding_value,
          "sampling_rate": self.sampling_rate,
          "do_normalize": self.do_normalize,
          "num_mel_bins": self.num_mel_bins,
          "hop_length": self.hop_length,
          "win_length": self.win_length,
          "win_function": self.win_function,
          "fmin": self.fmin,
          "fmax": self.fmax,
          "mel_floor": self.mel_floor,
          "return_attention_mask": self.return_attention_mask,
      }


     def   UpperCAmelCase  (							self			:		Any			,  UpperCAmelCase			:		Optional[Any]=False			,  UpperCAmelCase			:		List[str]=False					)							->	Union[str, Any]:
      def _flatten(UpperCAmelCase			:		List[str]					):
       return list(itertools.chain(*_snake_case					)					)

      if equal_length:
       __lowerCAmelCase:   Any   	=      floats_list((self.batch_size, self.max_seq_length)					)
      else:
       # make sure that inputs increase in size
       __lowerCAmelCase:   int   	=      [
           _flatten(floats_list((x, self.feature_size)					)					)
           for x in range(self.min_seq_length			,  self.max_seq_length			,  self.seq_length_diff					)
       ]

      if numpify:
       __lowerCAmelCase:   Any   	=      [np.asarray(_snake_case					) for x in speech_inputs]

      return speech_inputs


     def   UpperCAmelCase  (							self			:		Union[str, Any]			,  UpperCAmelCase			:		str=False			,  UpperCAmelCase			:		Dict=False					)							->	List[str]:
      if equal_length:
       __lowerCAmelCase:   Optional[Any]   	=      [floats_list((self.max_seq_length, self.num_mel_bins)					) for _ in range(self.batch_size					)]
      else:
       # make sure that inputs increase in size
       __lowerCAmelCase:   List[str]   	=      [
           floats_list((x, self.num_mel_bins)					)
           for x in range(self.min_seq_length			,  self.max_seq_length			,  self.seq_length_diff					)
       ]

      if numpify:
       __lowerCAmelCase:   int   	=      [np.asarray(_snake_case					) for x in speech_inputs]

      return speech_inputs







@require_torch
class 							A_ (		lowerCAmelCase_							,	unittest.TestCase					):
     _lowercase			:     int								=	SpeechTaFeatureExtractor


     def   UpperCAmelCase  (							self			:		int					)							->	Union[str, Any]:
      __lowerCAmelCase:   List[str]   	=      SpeechTaFeatureExtractionTester(self					)


     def   UpperCAmelCase  (							self			:		Any			,  UpperCAmelCase			:		Dict					)							->	Any:
      self.assertTrue(np.all(np.mean(_snake_case			,  axis=0					) < 1E-3					)					)
      self.assertTrue(np.all(np.abs(np.var(_snake_case			,  axis=0					) - 1					) < 1E-3					)					)


     def   UpperCAmelCase  (							self			:		List[Any]					)							->	Union[str, Any]:
      # Tests that all call wrap to encode_plus and batch_encode_plus
      __lowerCAmelCase:   Optional[Any]   	=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
      # create three inputs of length 800, 1000, and 1200
      __lowerCAmelCase:   int   	=      [floats_list((1, x)					)[0] for x in range(8_0_0			,  1_4_0_0			,  2_0_0					)]
      __lowerCAmelCase:   Tuple   	=      [np.asarray(_snake_case					) for speech_input in speech_inputs]

      # Test not batched input
      __lowerCAmelCase:   str   	=      feat_extract(speech_inputs[0]			,  return_tensors='np'					).input_values
      __lowerCAmelCase:   List[str]   	=      feat_extract(np_speech_inputs[0]			,  return_tensors='np'					).input_values
      self.assertTrue(np.allclose(_snake_case			,  _snake_case			,  atol=1E-3					)					)

      # Test batched
      __lowerCAmelCase:   Any   	=      feat_extract(_snake_case			,  return_tensors='np'					).input_values
      __lowerCAmelCase:   Union[str, Any]   	=      feat_extract(_snake_case			,  return_tensors='np'					).input_values
      for enc_seq_a, enc_seq_a in zip(_snake_case			,  _snake_case					):
       self.assertTrue(np.allclose(_snake_case			,  _snake_case			,  atol=1E-3					)					)


     def   UpperCAmelCase  (							self			:		int					)							->	Optional[int]:
      __lowerCAmelCase:   List[Any]   	=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
      __lowerCAmelCase:   Tuple   	=      [floats_list((1, x)					)[0] for x in range(8_0_0			,  1_4_0_0			,  2_0_0					)]

      __lowerCAmelCase:   int   	=      ['longest', 'max_length', 'do_not_pad']
      __lowerCAmelCase:   List[str]   	=      [None, 1_6_0_0, None]
      for max_length, padding in zip(_snake_case			,  _snake_case					):
       __lowerCAmelCase:   Optional[int]   	=      feat_extract(_snake_case			,  padding=_snake_case			,  max_length=_snake_case			,  return_tensors='np'					)
       __lowerCAmelCase:   Optional[int]   	=      processed.input_values

       self._check_zero_mean_unit_variance(input_values[0][:8_0_0]					)
       self.assertTrue(input_values[0][8_0_0:].sum() < 1E-6					)
       self._check_zero_mean_unit_variance(input_values[1][:1_0_0_0]					)
       self.assertTrue(input_values[0][1_0_0_0:].sum() < 1E-6					)
       self._check_zero_mean_unit_variance(input_values[2][:1_2_0_0]					)


     def   UpperCAmelCase  (							self			:		Union[str, Any]					)							->	Optional[Any]:
      __lowerCAmelCase:   Optional[Any]   	=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
      __lowerCAmelCase:   Tuple   	=      range(8_0_0			,  1_4_0_0			,  2_0_0					)
      __lowerCAmelCase:   Optional[Any]   	=      [floats_list((1, x)					)[0] for x in lengths]

      __lowerCAmelCase:   Union[str, Any]   	=      ['longest', 'max_length', 'do_not_pad']
      __lowerCAmelCase:   str   	=      [None, 1_6_0_0, None]

      for max_length, padding in zip(_snake_case			,  _snake_case					):
       __lowerCAmelCase:   List[str]   	=      feat_extract(_snake_case			,  max_length=_snake_case			,  padding=_snake_case					)
       __lowerCAmelCase:   Tuple   	=      processed.input_values

       self._check_zero_mean_unit_variance(input_values[0][:8_0_0]					)
       self._check_zero_mean_unit_variance(input_values[1][:1_0_0_0]					)
       self._check_zero_mean_unit_variance(input_values[2][:1_2_0_0]					)


     def   UpperCAmelCase  (							self			:		List[Any]					)							->	Optional[Any]:
      __lowerCAmelCase:   Any   	=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
      __lowerCAmelCase:   str   	=      [floats_list((1, x)					)[0] for x in range(8_0_0			,  1_4_0_0			,  2_0_0					)]
      __lowerCAmelCase:   Optional[Any]   	=      feat_extract(
          _snake_case			,  truncation=_snake_case			,  max_length=1_0_0_0			,  padding='max_length'			,  return_tensors='np'					)
      __lowerCAmelCase:   int   	=      processed.input_values

      self._check_zero_mean_unit_variance(input_values[0, :8_0_0]					)
      self._check_zero_mean_unit_variance(input_values[1]					)
      self._check_zero_mean_unit_variance(input_values[2]					)


     def   UpperCAmelCase  (							self			:		int					)							->	Union[str, Any]:
      __lowerCAmelCase:   str   	=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
      __lowerCAmelCase:   Dict   	=      [floats_list((1, x)					)[0] for x in range(8_0_0			,  1_4_0_0			,  2_0_0					)]
      __lowerCAmelCase:   str   	=      feat_extract(
          _snake_case			,  truncation=_snake_case			,  max_length=1_0_0_0			,  padding='longest'			,  return_tensors='np'					)
      __lowerCAmelCase:   Dict   	=      processed.input_values

      self._check_zero_mean_unit_variance(input_values[0, :8_0_0]					)
      self._check_zero_mean_unit_variance(input_values[1, :1_0_0_0]					)
      self._check_zero_mean_unit_variance(input_values[2]					)

      # make sure that if max_length < longest -> then pad to max_length
      self.assertTrue(input_values.shape == (3, 1_0_0_0)					)

      __lowerCAmelCase:   Tuple   	=      [floats_list((1, x)					)[0] for x in range(8_0_0			,  1_4_0_0			,  2_0_0					)]
      __lowerCAmelCase:   List[str]   	=      feat_extract(
          _snake_case			,  truncation=_snake_case			,  max_length=2_0_0_0			,  padding='longest'			,  return_tensors='np'					)
      __lowerCAmelCase:   Optional[Any]   	=      processed.input_values

      self._check_zero_mean_unit_variance(input_values[0, :8_0_0]					)
      self._check_zero_mean_unit_variance(input_values[1, :1_0_0_0]					)
      self._check_zero_mean_unit_variance(input_values[2]					)

      # make sure that if max_length > longest -> then pad to longest
      self.assertTrue(input_values.shape == (3, 1_2_0_0)					)


     def   UpperCAmelCase  (							self			:		List[str]					)							->	Dict:
      __lowerCAmelCase:   Dict   	=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
      __lowerCAmelCase:   List[Any]   	=      np.random.rand(1_0_0					).astype(np.floataa					)
      __lowerCAmelCase:   int   	=      np_speech_inputs.tolist()

      for inputs in [py_speech_inputs, np_speech_inputs]:
       __lowerCAmelCase:   int   	=      feature_extractor.pad([{'input_values': inputs}]			,  return_tensors='np'					)
       self.assertTrue(np_processed.input_values.dtype == np.floataa					)
       __lowerCAmelCase:   Optional[int]   	=      feature_extractor.pad([{'input_values': inputs}]			,  return_tensors='pt'					)
       self.assertTrue(pt_processed.input_values.dtype == torch.floataa					)


     def   UpperCAmelCase  (							self			:		Optional[int]					)							->	Optional[Any]:
      # Tests that all call wrap to encode_plus and batch_encode_plus
      __lowerCAmelCase:   str   	=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
      # create three inputs of length 800, 1000, and 1200
      __lowerCAmelCase:   List[Any]   	=      [floats_list((1, x)					)[0] for x in range(8_0_0			,  1_4_0_0			,  2_0_0					)]
      __lowerCAmelCase:   Dict   	=      [np.asarray(_snake_case					) for speech_input in speech_inputs]

      # Test feature size
      __lowerCAmelCase:   Optional[int]   	=      feature_extractor(audio_target=_snake_case			,  padding=_snake_case			,  return_tensors='np'					).input_values
      self.assertTrue(input_values.ndim == 3					)
      self.assertTrue(input_values.shape[-1] == feature_extractor.num_mel_bins					)

      # Test not batched input
      __lowerCAmelCase:   Dict   	=      feature_extractor(speech_inputs[0]			,  return_tensors='np'					).input_values
      __lowerCAmelCase:   Any   	=      feature_extractor(np_speech_inputs[0]			,  return_tensors='np'					).input_values
      self.assertTrue(np.allclose(_snake_case			,  _snake_case			,  atol=1E-3					)					)

      # Test batched
      __lowerCAmelCase:   Dict   	=      feature_extractor(_snake_case			,  return_tensors='np'					).input_values
      __lowerCAmelCase:   Dict   	=      feature_extractor(_snake_case			,  return_tensors='np'					).input_values
      for enc_seq_a, enc_seq_a in zip(_snake_case			,  _snake_case					):
       self.assertTrue(np.allclose(_snake_case			,  _snake_case			,  atol=1E-3					)					)

      # Test 2-D numpy arrays are batched.
      __lowerCAmelCase:   Optional[Any]   	=      [floats_list((1, x)					)[0] for x in (8_0_0, 8_0_0, 8_0_0)]
      __lowerCAmelCase:   int   	=      np.asarray(_snake_case					)
      __lowerCAmelCase:   Union[str, Any]   	=      feature_extractor(_snake_case			,  return_tensors='np'					).input_values
      __lowerCAmelCase:   Union[str, Any]   	=      feature_extractor(_snake_case			,  return_tensors='np'					).input_values
      for enc_seq_a, enc_seq_a in zip(_snake_case			,  _snake_case					):
       self.assertTrue(np.allclose(_snake_case			,  _snake_case			,  atol=1E-3					)					)


     def   UpperCAmelCase  (							self			:		Union[str, Any]					)							->	str:
      __lowerCAmelCase:   int   	=      self.feat_extract_tester.prepare_inputs_for_target()
      __lowerCAmelCase:   List[str]   	=      self.feature_extraction_class(**self.feat_extract_dict					)
      __lowerCAmelCase:   Optional[Any]   	=      feat_extract.model_input_names[0]

      __lowerCAmelCase:   Tuple   	=      BatchFeature({input_name: speech_inputs}					)

      self.assertTrue(all(len(_snake_case					) == len(_snake_case					) for x, y in zip(_snake_case			,  processed_features[input_name]					)					)					)

      __lowerCAmelCase:   int   	=      self.feat_extract_tester.prepare_inputs_for_target(equal_length=_snake_case					)
      __lowerCAmelCase:   Union[str, Any]   	=      BatchFeature({input_name: speech_inputs}			,  tensor_type='np'					)

      __lowerCAmelCase:   Dict   	=      processed_features[input_name]

      if len(batch_features_input.shape					) < 3:
       __lowerCAmelCase:   List[str]   	=      batch_features_input[:, :, None]

      self.assertTrue(
          batch_features_input.shape
          == (self.feat_extract_tester.batch_size, len(speech_inputs[0]					), self.feat_extract_tester.num_mel_bins)					)


     @require_torch
     def   UpperCAmelCase  (							self			:		List[str]					)							->	Any:
      __lowerCAmelCase:   int   	=      self.feat_extract_tester.prepare_inputs_for_target(equal_length=_snake_case					)
      __lowerCAmelCase:   Optional[Any]   	=      self.feature_extraction_class(**self.feat_extract_dict					)
      __lowerCAmelCase:   Tuple   	=      feat_extract.model_input_names[0]

      __lowerCAmelCase:   List[Any]   	=      BatchFeature({input_name: speech_inputs}			,  tensor_type='pt'					)

      __lowerCAmelCase:   Tuple   	=      processed_features[input_name]

      if len(batch_features_input.shape					) < 3:
       __lowerCAmelCase:   Any   	=      batch_features_input[:, :, None]

      self.assertTrue(
          batch_features_input.shape
          == (self.feat_extract_tester.batch_size, len(speech_inputs[0]					), self.feat_extract_tester.num_mel_bins)					)


     @require_torch
     def   UpperCAmelCase  (							self			:		Optional[int]					)							->	Tuple:
      __lowerCAmelCase:   Dict   	=      self.feature_extraction_class(**self.feat_extract_dict					)
      __lowerCAmelCase:   Union[str, Any]   	=      self.feat_extract_tester.prepare_inputs_for_target()
      __lowerCAmelCase:   Optional[Any]   	=      feat_extract.model_input_names[0]

      __lowerCAmelCase:   List[str]   	=      BatchFeature({input_name: speech_inputs}					)

      __lowerCAmelCase:   int   	=      feat_extract.num_mel_bins  # hack!

      __lowerCAmelCase:   Tuple   	=      feat_extract.pad(_snake_case			,  padding='longest'			,  return_tensors='np'					)[input_name]
      __lowerCAmelCase:   Union[str, Any]   	=      feat_extract.pad(_snake_case			,  padding='longest'			,  return_tensors='pt'					)[input_name]

      self.assertTrue(abs(input_np.astype(np.floataa					).sum() - input_pt.numpy().astype(np.floataa					).sum()					) < 1E-2					)


     def   UpperCAmelCase  (							self			:		int					)							->	Any:
      __lowerCAmelCase:   Any   	=      self.feat_extract_dict
      __lowerCAmelCase:   List[Any]   	=      True
      __lowerCAmelCase:   Union[str, Any]   	=      self.feature_extraction_class(**_snake_case					)
      __lowerCAmelCase:   Any   	=      self.feat_extract_tester.prepare_inputs_for_target()
      __lowerCAmelCase:   List[Any]   	=      [len(_snake_case					) for x in speech_inputs]
      __lowerCAmelCase:   Union[str, Any]   	=      feat_extract.model_input_names[0]

      __lowerCAmelCase:   Optional[int]   	=      BatchFeature({input_name: speech_inputs}					)

      __lowerCAmelCase:   List[str]   	=      feat_extract.num_mel_bins  # hack!

      __lowerCAmelCase:   str   	=      feat_extract.pad(_snake_case			,  padding='longest'			,  return_tensors='np'					)
      self.assertIn('attention_mask'			,  _snake_case					)
      self.assertListEqual(list(processed.attention_mask.shape					)			,  list(processed[input_name].shape[:2]					)					)
      self.assertListEqual(processed.attention_mask.sum(-1					).tolist()			,  _snake_case					)


     def   UpperCAmelCase  (							self			:		Optional[int]					)							->	str:
      __lowerCAmelCase:   int   	=      self.feat_extract_dict
      __lowerCAmelCase:   List[str]   	=      True
      __lowerCAmelCase:   Tuple   	=      self.feature_extraction_class(**_snake_case					)
      __lowerCAmelCase:   List[str]   	=      self.feat_extract_tester.prepare_inputs_for_target()
      __lowerCAmelCase:   str   	=      [len(_snake_case					) for x in speech_inputs]
      __lowerCAmelCase:   Optional[Any]   	=      feat_extract.model_input_names[0]

      __lowerCAmelCase:   Optional[int]   	=      BatchFeature({input_name: speech_inputs}					)
      __lowerCAmelCase:   Optional[Any]   	=      min(_snake_case					)

      __lowerCAmelCase:   Union[str, Any]   	=      feat_extract.num_mel_bins  # hack!

      __lowerCAmelCase:   Tuple   	=      feat_extract.pad(
          _snake_case			,  padding='max_length'			,  max_length=_snake_case			,  truncation=_snake_case			,  return_tensors='np'					)
      self.assertIn('attention_mask'			,  _snake_case					)
      self.assertListEqual(
          list(processed_pad.attention_mask.shape					)			,  [processed_pad[input_name].shape[0], max_length]					)
      self.assertListEqual(
          processed_pad.attention_mask[:, :max_length].sum(-1					).tolist()			,  [max_length for x in speech_inputs]					)


     def   UpperCAmelCase  (							self			:		List[Any]			,  UpperCAmelCase			:		Optional[int]					)							->	Optional[Any]:
      from datasets import load_dataset

      __lowerCAmelCase:   str   	=      load_dataset('hf-internal-testing/librispeech_asr_dummy'			,  'clean'			,  split='validation'					)
      # automatic decoding with librispeech
      __lowerCAmelCase:   Dict   	=      ds.sort('id'					).select(range(_snake_case					)					)[:num_samples]['audio']

      return [x["array"] for x in speech_samples]


     def   UpperCAmelCase  (							self			:		str					)							->	str:
      # fmt: off
      __lowerCAmelCase:   List[Any]   	=      torch.tensor(
          [2.38_04E-03, 2.07_52E-03, 1.98_36E-03, 2.10_57E-03, 1.61_74E-03,
           3.05_18E-04, 9.15_53E-05, 3.35_69E-04, 9.76_56E-04, 1.83_11E-03,
           2.01_42E-03, 2.10_57E-03, 1.73_95E-03, 4.57_76E-04, -3.96_73E-04,
           4.57_76E-04, 1.00_71E-03, 9.15_53E-05, 4.88_28E-04, 1.15_97E-03,
           7.32_42E-04, 9.46_04E-04, 1.80_05E-03, 1.83_11E-03, 8.85_01E-04,
           4.27_25E-04, 4.88_28E-04, 7.32_42E-04, 1.09_86E-03, 2.10_57E-03]					)
      # fmt: on

      __lowerCAmelCase:   Union[str, Any]   	=      self._load_datasamples(1					)
      __lowerCAmelCase:   Optional[int]   	=      SpeechTaFeatureExtractor()
      __lowerCAmelCase:   List[Any]   	=      feature_extractor(_snake_case			,  return_tensors='pt'					).input_values
      self.assertEquals(input_values.shape			,  (1, 9_3_6_8_0)					)
      self.assertTrue(torch.allclose(input_values[0, :3_0]			,  _snake_case			,  atol=1E-6					)					)


     def   UpperCAmelCase  (							self			:		Any					)							->	str:
      # fmt: off
      __lowerCAmelCase:   Optional[Any]   	=      torch.tensor(
          [-2.6870, -3.0104, -3.1356, -3.5352, -3.0044, -3.0353, -3.4719, -3.6777,
           -3.1520, -2.9435, -2.6553, -2.8795, -2.9944, -2.5921, -3.0279, -3.0386,
           -3.0864, -3.1291, -3.2353, -2.7444, -2.6831, -2.7287, -3.1761, -3.1571,
           -3.2726, -3.0582, -3.1007, -3.4533, -3.4695, -3.0998]					)
      # fmt: on

      __lowerCAmelCase:   List[str]   	=      self._load_datasamples(1					)
      __lowerCAmelCase:   str   	=      SpeechTaFeatureExtractor()
      __lowerCAmelCase:   Optional[Any]   	=      feature_extractor(audio_target=_snake_case			,  return_tensors='pt'					).input_values
      self.assertEquals(input_values.shape			,  (1, 3_6_6, 8_0)					)
      self.assertTrue(torch.allclose(input_values[0, 0, :3_0]			,  _snake_case			,  atol=1E-4					)					)










from collections import deque

from .hash_table import HashTable




class 					snake_case__						(       lowerCAmelCase_     ):






     """simple docstring"""


     def __init__(       self  :  Optional[Any], *_snake_case  :  Optional[Any], **_snake_case  :  List[Any]					)   ->Optional[int]:
            super().__init__(*_snake_case, **_snake_case					)






     def    lowercase_   (       self  :  Optional[Any], _snake_case  :  Tuple, _snake_case  :  Dict					)   ->Dict:
            snake_case__							:	int   	=	deque([]					) if self.values[key] is None else self.values[key]
            self.values[key].appendleft(_snake_case					)
            snake_case__							:	Dict   	=	self.values[key]






     def    lowercase_   (       self  :  Any					)   ->Optional[Any]:
            return (
                sum(self.charge_factor - len(_snake_case					) for slot in self.values					)
                / self.size_table
                * self.charge_factor
            )






     def    lowercase_   (       self  :  Union[str, Any], _snake_case  :  str, _snake_case  :  Optional[int]=None					)   ->Optional[Any]:
            if not (
                len(self.values[key]					) == self.charge_factor and self.values.count(_snake_case					) == 0
            ):
                   return key
            return super()._collision_resolution(_snake_case, _snake_case					)






