'''simple docstring'''






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    __UpperCAmelCase			(  a_:       List[Any],					a_:       List[Any]=1.0,					a_:       Dict=None,					a_:       Tuple=None							):
   if rng is None:
      _UpperCAmelCase							:	Union[str, Any]							=   global_rng

   _UpperCAmelCase							:	Optional[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   ):





   """simple docstring"""





   def __init__( self     :		str						,     lowerCAmelCase__     :		Dict						,     lowerCAmelCase__     :		Tuple=7						,     lowerCAmelCase__     :		int=4_0_0						,     lowerCAmelCase__     :		Any=2_0_0_0						,     lowerCAmelCase__     :		Any=1						,     lowerCAmelCase__     :		List[Any]=0.0						,     lowerCAmelCase__     :		List[Any]=1_6_0_0_0						,     lowerCAmelCase__     :		List[str]=True						,     lowerCAmelCase__     :		List[Any]=8_0						,     lowerCAmelCase__     :		List[Any]=1_6						,     lowerCAmelCase__     :		Tuple=6_4						,     lowerCAmelCase__     :		Optional[Any]="hann_window"						,     lowerCAmelCase__     :		List[Any]=8_0						,     lowerCAmelCase__     :		str=7_6_0_0						,     lowerCAmelCase__     :		Optional[int]=1e-10						,     lowerCAmelCase__     :		Optional[int]=True						,     )       ->    int:







      """simple docstring"""




      _UpperCAmelCase							:	Optional[Any]							=   parent
      _UpperCAmelCase							:	Optional[Any]							=   batch_size
      _UpperCAmelCase							:	str							=   min_seq_length
      _UpperCAmelCase							:	str							=   max_seq_length
      _UpperCAmelCase							:	Tuple							=   (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
      _UpperCAmelCase							:	Union[str, Any]							=   feature_size
      _UpperCAmelCase							:	List[str]							=   padding_value
      _UpperCAmelCase							:	List[str]							=   sampling_rate
      _UpperCAmelCase							:	Any							=   do_normalize
      _UpperCAmelCase							:	str							=   num_mel_bins
      _UpperCAmelCase							:	Tuple							=   hop_length
      _UpperCAmelCase							:	Tuple							=   win_length
      _UpperCAmelCase							:	List[str]							=   win_function
      _UpperCAmelCase							:	Optional[int]							=   fmin
      _UpperCAmelCase							:	Dict							=   fmax
      _UpperCAmelCase							:	Dict							=   mel_floor
      _UpperCAmelCase							:	List[str]							=   return_attention_mask




   def 			_lowerCAmelCase		( self     :		Optional[int]			)       ->    Optional[int]:







      """simple docstring"""




      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 			_lowerCAmelCase		( self     :		List[str]						,     lowerCAmelCase__     :		Tuple=False						,     lowerCAmelCase__     :		Union[str, Any]=False			)       ->    Tuple:







      """simple docstring"""




      def _flatten(lowerCAmelCase__     :		Union[str, Any]			):
         return list(itertools.chain(*lowerCAmelCase_			)			)

      if equal_length:
         _UpperCAmelCase							:	Tuple							=   floats_list((self.batch_size, self.max_seq_length)			)
      else:
         # make sure that inputs increase in size
         _UpperCAmelCase							:	str							=   [
             _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:
         _UpperCAmelCase							:	Tuple							=   [np.asarray(lowerCAmelCase_			) for x in speech_inputs]

      return speech_inputs




   def 			_lowerCAmelCase		( self     :		Optional[int]						,     lowerCAmelCase__     :		Union[str, Any]=False						,     lowerCAmelCase__     :		Optional[int]=False			)       ->    Union[str, Any]:







      """simple docstring"""




      if equal_length:
         _UpperCAmelCase							:	List[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
         _UpperCAmelCase							:	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:
         _UpperCAmelCase							:	str							=   [np.asarray(lowerCAmelCase_			) for x in speech_inputs]

      return speech_inputs





@require_torch
class     A__							(       _UpperCamelCase					,		unittest.TestCase   ):





   """simple docstring"""





   UpperCamelCase_       :						Tuple    				=     SpeechTaFeatureExtractor




   def 			_lowerCAmelCase		( self     :		Any			)       ->    Dict:







      """simple docstring"""




      _UpperCAmelCase							:	Union[str, Any]							=   SpeechTaFeatureExtractionTester(self			)




   def 			_lowerCAmelCase		( self     :		Tuple						,     lowerCAmelCase__     :		List[str]			)       ->    Any:







      """simple docstring"""




      self.assertTrue(np.all(np.mean(lowerCAmelCase_						,     axis=0			) < 1e-3			)			)
      self.assertTrue(np.all(np.abs(np.var(lowerCAmelCase_						,     axis=0			) - 1			) < 1e-3			)			)




   def 			_lowerCAmelCase		( self     :		int			)       ->    Dict:







      """simple docstring"""




      _UpperCAmelCase							:	Tuple							=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
      # create three inputs of length 800, 1000, and 1200
      _UpperCAmelCase							:	str							=   [floats_list((1, x)			)[0] for x in range(8_0_0						,     1_4_0_0						,     2_0_0			)]
      _UpperCAmelCase							:	Optional[Any]							=   [np.asarray(lowerCAmelCase_			) for speech_input in speech_inputs]

      # Test not batched input
      _UpperCAmelCase							:	Tuple							=   feat_extract(speech_inputs[0]						,     return_tensors="np"			).input_values
      _UpperCAmelCase							:	Any							=   feat_extract(np_speech_inputs[0]						,     return_tensors="np"			).input_values
      self.assertTrue(np.allclose(lowerCAmelCase_						,     lowerCAmelCase_						,     atol=1e-3			)			)

      # Test batched
      _UpperCAmelCase							:	str							=   feat_extract(lowerCAmelCase_						,     return_tensors="np"			).input_values
      _UpperCAmelCase							:	int							=   feat_extract(lowerCAmelCase_						,     return_tensors="np"			).input_values
      for enc_seq_a, enc_seq_a in zip(lowerCAmelCase_						,     lowerCAmelCase_			):
         self.assertTrue(np.allclose(lowerCAmelCase_						,     lowerCAmelCase_						,     atol=1e-3			)			)




   def 			_lowerCAmelCase		( self     :		Optional[int]			)       ->    Union[str, Any]:







      """simple docstring"""




      _UpperCAmelCase							:	Optional[int]							=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
      _UpperCAmelCase							:	Tuple							=   [floats_list((1, x)			)[0] for x in range(8_0_0						,     1_4_0_0						,     2_0_0			)]

      _UpperCAmelCase							:	List[str]							=   ["longest", "max_length", "do_not_pad"]
      _UpperCAmelCase							:	str							=   [None, 1_6_0_0, None]
      for max_length, padding in zip(lowerCAmelCase_						,     lowerCAmelCase_			):
         _UpperCAmelCase							:	Any							=   feat_extract(lowerCAmelCase_						,     padding=lowerCAmelCase_						,     max_length=lowerCAmelCase_						,     return_tensors="np"			)
         _UpperCAmelCase							:	Union[str, Any]							=   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 			_lowerCAmelCase		( self     :		List[Any]			)       ->    List[str]:







      """simple docstring"""




      _UpperCAmelCase							:	Union[str, Any]							=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
      _UpperCAmelCase							:	Dict							=   range(8_0_0						,     1_4_0_0						,     2_0_0			)
      _UpperCAmelCase							:	Dict							=   [floats_list((1, x)			)[0] for x in lengths]

      _UpperCAmelCase							:	Optional[int]							=   ["longest", "max_length", "do_not_pad"]
      _UpperCAmelCase							:	Tuple							=   [None, 1_6_0_0, None]

      for max_length, padding in zip(lowerCAmelCase_						,     lowerCAmelCase_			):
         _UpperCAmelCase							:	List[Any]							=   feat_extract(lowerCAmelCase_						,     max_length=lowerCAmelCase_						,     padding=lowerCAmelCase_			)
         _UpperCAmelCase							:	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][:1_2_0_0]			)




   def 			_lowerCAmelCase		( self     :		Optional[int]			)       ->    Optional[int]:







      """simple docstring"""




      _UpperCAmelCase							:	str							=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
      _UpperCAmelCase							:	Union[str, Any]							=   [floats_list((1, x)			)[0] for x in range(8_0_0						,     1_4_0_0						,     2_0_0			)]
      _UpperCAmelCase							:	Union[str, Any]							=   feat_extract(
          lowerCAmelCase_						,     truncation=lowerCAmelCase_						,     max_length=1_0_0_0						,     padding="max_length"						,     return_tensors="np"			)
      _UpperCAmelCase							:	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]			)
      self._check_zero_mean_unit_variance(input_values[2]			)




   def 			_lowerCAmelCase		( self     :		int			)       ->    Optional[int]:







      """simple docstring"""




      _UpperCAmelCase							:	Tuple							=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
      _UpperCAmelCase							:	Optional[Any]							=   [floats_list((1, x)			)[0] for x in range(8_0_0						,     1_4_0_0						,     2_0_0			)]
      _UpperCAmelCase							:	int							=   feat_extract(
          lowerCAmelCase_						,     truncation=lowerCAmelCase_						,     max_length=1_0_0_0						,     padding="longest"						,     return_tensors="np"			)
      _UpperCAmelCase							:	str							=   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)			)

      _UpperCAmelCase							:	int							=   [floats_list((1, x)			)[0] for x in range(8_0_0						,     1_4_0_0						,     2_0_0			)]
      _UpperCAmelCase							:	Dict							=   feat_extract(
          lowerCAmelCase_						,     truncation=lowerCAmelCase_						,     max_length=2_0_0_0						,     padding="longest"						,     return_tensors="np"			)
      _UpperCAmelCase							:	Optional[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, :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 			_lowerCAmelCase		( self     :		Any			)       ->    Tuple:







      """simple docstring"""




      _UpperCAmelCase							:	Union[str, Any]							=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
      _UpperCAmelCase							:	Tuple							=   np.random.rand(1_0_0			).astype(np.floataa			)
      _UpperCAmelCase							:	Dict							=   np_speech_inputs.tolist()

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




   def 			_lowerCAmelCase		( self     :		List[Any]			)       ->    Union[str, Any]:







      """simple docstring"""




      _UpperCAmelCase							:	Union[str, Any]							=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
      # create three inputs of length 800, 1000, and 1200
      _UpperCAmelCase							:	Tuple							=   [floats_list((1, x)			)[0] for x in range(8_0_0						,     1_4_0_0						,     2_0_0			)]
      _UpperCAmelCase							:	Optional[int]							=   [np.asarray(lowerCAmelCase_			) for speech_input in speech_inputs]

      # Test feature size
      _UpperCAmelCase							:	Dict							=   feature_extractor(audio_target=lowerCAmelCase_						,     padding=lowerCAmelCase_						,     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
      _UpperCAmelCase							:	Optional[Any]							=   feature_extractor(speech_inputs[0]						,     return_tensors="np"			).input_values
      _UpperCAmelCase							:	int							=   feature_extractor(np_speech_inputs[0]						,     return_tensors="np"			).input_values
      self.assertTrue(np.allclose(lowerCAmelCase_						,     lowerCAmelCase_						,     atol=1e-3			)			)

      # Test batched
      _UpperCAmelCase							:	Optional[int]							=   feature_extractor(lowerCAmelCase_						,     return_tensors="np"			).input_values
      _UpperCAmelCase							:	Optional[Any]							=   feature_extractor(lowerCAmelCase_						,     return_tensors="np"			).input_values
      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.
      _UpperCAmelCase							:	Optional[int]							=   [floats_list((1, x)			)[0] for x in (8_0_0, 8_0_0, 8_0_0)]
      _UpperCAmelCase							:	int							=   np.asarray(lowerCAmelCase_			)
      _UpperCAmelCase							:	List[str]							=   feature_extractor(lowerCAmelCase_						,     return_tensors="np"			).input_values
      _UpperCAmelCase							:	Union[str, Any]							=   feature_extractor(lowerCAmelCase_						,     return_tensors="np"			).input_values
      for enc_seq_a, enc_seq_a in zip(lowerCAmelCase_						,     lowerCAmelCase_			):
         self.assertTrue(np.allclose(lowerCAmelCase_						,     lowerCAmelCase_						,     atol=1e-3			)			)




   def 			_lowerCAmelCase		( self     :		Any			)       ->    int:







      """simple docstring"""




      _UpperCAmelCase							:	Dict							=   self.feat_extract_tester.prepare_inputs_for_target()
      _UpperCAmelCase							:	List[str]							=   self.feature_extraction_class(**self.feat_extract_dict			)
      _UpperCAmelCase							:	Union[str, Any]							=   feat_extract.model_input_names[0]

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

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

      _UpperCAmelCase							:	Optional[Any]							=   self.feat_extract_tester.prepare_inputs_for_target(equal_length=lowerCAmelCase_			)
      _UpperCAmelCase							:	int							=   BatchFeature({input_name: speech_inputs}						,     tensor_type="np"			)

      _UpperCAmelCase							:	str							=   processed_features[input_name]

      if len(batch_features_input.shape			) < 3:
         _UpperCAmelCase							:	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 			_lowerCAmelCase		( self     :		Dict			)       ->    Optional[Any]:







      """simple docstring"""




      _UpperCAmelCase							:	Optional[int]							=   self.feat_extract_tester.prepare_inputs_for_target(equal_length=lowerCAmelCase_			)
      _UpperCAmelCase							:	List[Any]							=   self.feature_extraction_class(**self.feat_extract_dict			)
      _UpperCAmelCase							:	List[Any]							=   feat_extract.model_input_names[0]

      _UpperCAmelCase							:	List[str]							=   BatchFeature({input_name: speech_inputs}						,     tensor_type="pt"			)

      _UpperCAmelCase							:	Dict							=   processed_features[input_name]

      if len(batch_features_input.shape			) < 3:
         _UpperCAmelCase							:	Dict							=   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 			_lowerCAmelCase		( self     :		Optional[Any]			)       ->    Any:







      """simple docstring"""




      _UpperCAmelCase							:	str							=   self.feature_extraction_class(**self.feat_extract_dict			)
      _UpperCAmelCase							:	Optional[int]							=   self.feat_extract_tester.prepare_inputs_for_target()
      _UpperCAmelCase							:	Optional[int]							=   feat_extract.model_input_names[0]

      _UpperCAmelCase							:	Dict							=   BatchFeature({input_name: speech_inputs}			)

      _UpperCAmelCase							:	Any							=   feat_extract.num_mel_bins  # hack!

      _UpperCAmelCase							:	Optional[Any]							=   feat_extract.pad(lowerCAmelCase_						,     padding="longest"						,     return_tensors="np"			)[input_name]
      _UpperCAmelCase							:	Dict							=   feat_extract.pad(lowerCAmelCase_						,     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 			_lowerCAmelCase		( self     :		List[str]			)       ->    Dict:







      """simple docstring"""




      _UpperCAmelCase							:	List[str]							=   self.feat_extract_dict
      _UpperCAmelCase							:	str							=   True
      _UpperCAmelCase							:	Any							=   self.feature_extraction_class(**lowerCAmelCase_			)
      _UpperCAmelCase							:	Optional[Any]							=   self.feat_extract_tester.prepare_inputs_for_target()
      _UpperCAmelCase							:	List[Any]							=   [len(lowerCAmelCase_			) for x in speech_inputs]
      _UpperCAmelCase							:	Tuple							=   feat_extract.model_input_names[0]

      _UpperCAmelCase							:	Optional[Any]							=   BatchFeature({input_name: speech_inputs}			)

      _UpperCAmelCase							:	List[Any]							=   feat_extract.num_mel_bins  # hack!

      _UpperCAmelCase							:	Dict							=   feat_extract.pad(lowerCAmelCase_						,     padding="longest"						,     return_tensors="np"			)
      self.assertIn("attention_mask"						,     lowerCAmelCase_			)
      self.assertListEqual(list(processed.attention_mask.shape			)						,     list(processed[input_name].shape[:2]			)			)
      self.assertListEqual(processed.attention_mask.sum(-1			).tolist()						,     lowerCAmelCase_			)




   def 			_lowerCAmelCase		( self     :		List[Any]			)       ->    Union[str, Any]:







      """simple docstring"""




      _UpperCAmelCase							:	int							=   self.feat_extract_dict
      _UpperCAmelCase							:	Dict							=   True
      _UpperCAmelCase							:	Optional[int]							=   self.feature_extraction_class(**lowerCAmelCase_			)
      _UpperCAmelCase							:	Any							=   self.feat_extract_tester.prepare_inputs_for_target()
      _UpperCAmelCase							:	str							=   [len(lowerCAmelCase_			) for x in speech_inputs]
      _UpperCAmelCase							:	int							=   feat_extract.model_input_names[0]

      _UpperCAmelCase							:	List[Any]							=   BatchFeature({input_name: speech_inputs}			)
      _UpperCAmelCase							:	str							=   min(lowerCAmelCase_			)

      _UpperCAmelCase							:	List[Any]							=   feat_extract.num_mel_bins  # hack!

      _UpperCAmelCase							:	Optional[int]							=   feat_extract.pad(
          lowerCAmelCase_						,     padding="max_length"						,     max_length=lowerCAmelCase_						,     truncation=lowerCAmelCase_						,     return_tensors="np"			)
      self.assertIn("attention_mask"						,     lowerCAmelCase_			)
      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 			_lowerCAmelCase		( self     :		Dict						,     lowerCAmelCase__     :		List[str]			)       ->    Tuple:







      """simple docstring"""




      from datasets import load_dataset

      _UpperCAmelCase							:	Dict							=   load_dataset("hf-internal-testing/librispeech_asr_dummy"						,     "clean"						,     split="validation"			)
      # automatic decoding with librispeech
      _UpperCAmelCase							:	Optional[Any]							=   ds.sort("id"			).select(range(lowerCAmelCase_			)			)[:num_samples]["audio"]

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




   def 			_lowerCAmelCase		( self     :		Union[str, Any]			)       ->    Optional[Any]:







      """simple docstring"""




      _UpperCAmelCase							:	List[str]							=   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

      _UpperCAmelCase							:	List[Any]							=   self._load_datasamples(1			)
      _UpperCAmelCase							:	Optional[int]							=   SpeechTaFeatureExtractor()
      _UpperCAmelCase							:	Any							=   feature_extractor(lowerCAmelCase_						,     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]						,     lowerCAmelCase_						,     atol=1e-6			)			)




   def 			_lowerCAmelCase		( self     :		str			)       ->    List[str]:







      """simple docstring"""




      _UpperCAmelCase							:	Dict							=   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

      _UpperCAmelCase							:	List[str]							=   self._load_datasamples(1			)
      _UpperCAmelCase							:	Optional[Any]							=   SpeechTaFeatureExtractor()
      _UpperCAmelCase							:	Tuple							=   feature_extractor(audio_target=lowerCAmelCase_						,     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]						,     lowerCAmelCase_						,     atol=1e-4			)			)






# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


_snake_case  :    Dict						    =  {'configuration_mra': ['MRA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MraConfig']}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     _snake_case  :    Optional[int]						    =  [
         'MRA_PRETRAINED_MODEL_ARCHIVE_LIST',
         'MraForMaskedLM',
         'MraForMultipleChoice',
         'MraForQuestionAnswering',
         'MraForSequenceClassification',
         'MraForTokenClassification',
         'MraLayer',
         'MraModel',
         'MraPreTrainedModel',
     ]


if TYPE_CHECKING:
     from .configuration_mra import MRA_PRETRAINED_CONFIG_ARCHIVE_MAP, MraConfig

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_mra import (
              MRA_PRETRAINED_MODEL_ARCHIVE_LIST,
              MraForMaskedLM,
              MraForMultipleChoice,
              MraForQuestionAnswering,
              MraForSequenceClassification,
              MraForTokenClassification,
              MraLayer,
              MraModel,
              MraPreTrainedModel,
          )
else:
     import sys

     _snake_case  :    Tuple						    =  _LazyModule(__name__, globals()['__file__'], _import_structure)

