


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


__lowerCamelCase												=						random.Random()


def        a__     (					UpperCamelCase_						:      Optional[Any],   UpperCamelCase_						:      Dict=1.0,   UpperCamelCase_						:      List[Any]=None,   UpperCamelCase_						:      List[Any]=None						):
   if rng is None:
      UpperCAmelCase__	:List[str]      =      global_rng

   UpperCAmelCase__	: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
class 				UpperCAmelCase			(			unittest.TestCase						):


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


 def        __SCREAMING_SNAKE_CASE					(      self							:	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        __SCREAMING_SNAKE_CASE					(      self							:	Optional[int]			,       __lowerCamelCase							:	Tuple=False			,       __lowerCamelCase							:	Tuple=False ):
    def _flatten(__lowerCamelCase							:	List[str] ):
       return list(itertools.chain(*__lowerCamelCase ) )

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

    return speech_inputs





 def        __SCREAMING_SNAKE_CASE					(      self							:	List[str]			,       __lowerCamelCase							:	Union[str, Any]=False			,       __lowerCamelCase							:	Dict=False ):
    if equal_length:
       UpperCAmelCase__	:Union[str, 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__	:int      =      [np.asarray(__lowerCamelCase ) for x in speech_inputs]

    return speech_inputs




@require_torch
class 				UpperCAmelCase			(			_snake_case						, unittest.TestCase						):
 UpperCAmelCase				=					SpeechTaFeatureExtractor


 def        __SCREAMING_SNAKE_CASE					(      self							:	Union[str, Any] ):
    UpperCAmelCase__	:Dict      =      SpeechTaFeatureExtractionTester(self )


 def        __SCREAMING_SNAKE_CASE					(      self							:	Dict			,       __lowerCamelCase							:	List[Any] ):
    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        __SCREAMING_SNAKE_CASE					(      self							:	Tuple ):
    # Tests that all call wrap to encode_plus and batch_encode_plus
    UpperCAmelCase__	:Dict      =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
    # create three inputs of length 800, 1000, and 1200
    UpperCAmelCase__	:Dict      =      [floats_list((1, x) )[0] for x in range(8_0_0			,       1_4_0_0			,       2_0_0 )]
    UpperCAmelCase__	:str      =      [np.asarray(__lowerCamelCase ) for speech_input in speech_inputs]

    # Test not batched input
    UpperCAmelCase__	:Dict      =      feat_extract(speech_inputs[0]			,       return_tensors='''np''' ).input_values
    UpperCAmelCase__	:Tuple      =      feat_extract(np_speech_inputs[0]			,       return_tensors='''np''' ).input_values
    self.assertTrue(np.allclose(__lowerCamelCase			,       __lowerCamelCase			,       atol=1e-3 ) )

    # Test batched
    UpperCAmelCase__	:Optional[Any]      =      feat_extract(__lowerCamelCase			,       return_tensors='''np''' ).input_values
    UpperCAmelCase__	:str      =      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        __SCREAMING_SNAKE_CASE					(      self							:	Any ):
    UpperCAmelCase__	:Optional[Any]      =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
    UpperCAmelCase__	:Dict      =      [floats_list((1, x) )[0] for x in range(8_0_0			,       1_4_0_0			,       2_0_0 )]

    UpperCAmelCase__	:Any      =      ['''longest''', '''max_length''', '''do_not_pad''']
    UpperCAmelCase__	:List[Any]      =      [None, 1_6_0_0, None]
    for max_length, padding in zip(__lowerCamelCase			,       __lowerCamelCase ):
       UpperCAmelCase__	:Tuple      =      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        __SCREAMING_SNAKE_CASE					(      self							:	Dict ):
    UpperCAmelCase__	:Optional[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__	:Any      =      [floats_list((1, x) )[0] for x in lengths]

    UpperCAmelCase__	:Dict      =      ['''longest''', '''max_length''', '''do_not_pad''']
    UpperCAmelCase__	:Optional[int]      =      [None, 1_6_0_0, None]

    for max_length, padding in zip(__lowerCamelCase			,       __lowerCamelCase ):
       UpperCAmelCase__	:Union[str, Any]      =      feat_extract(__lowerCamelCase			,       max_length=__lowerCamelCase			,       padding=__lowerCamelCase )
       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][:1_2_0_0] )


 def        __SCREAMING_SNAKE_CASE					(      self							:	Optional[int] ):
    UpperCAmelCase__	:Optional[int]      =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
    UpperCAmelCase__	:List[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__	: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] )
    self._check_zero_mean_unit_variance(input_values[2] )


 def        __SCREAMING_SNAKE_CASE					(      self							:	str ):
    UpperCAmelCase__	:Union[str, Any]      =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
    UpperCAmelCase__	:Optional[int]      =      [floats_list((1, x) )[0] for x in range(8_0_0			,       1_4_0_0			,       2_0_0 )]
    UpperCAmelCase__	:Tuple      =      feat_extract(
        __lowerCamelCase			,       truncation=__lowerCamelCase			,       max_length=1_0_0_0			,       padding='''longest'''			,       return_tensors='''np''' )
    UpperCAmelCase__	: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 max_length
    self.assertTrue(input_values.shape == (3, 1_0_0_0) )

    UpperCAmelCase__	:Any      =      [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__	: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] )

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


 def        __SCREAMING_SNAKE_CASE					(      self							:	Any ):
    UpperCAmelCase__	:Union[str, Any]      =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
    UpperCAmelCase__	:List[str]      =      np.random.rand(1_0_0 ).astype(np.floataa )
    UpperCAmelCase__	:Any      =      np_speech_inputs.tolist()

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


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

    # Test feature size
    UpperCAmelCase__	:Union[str, Any]      =      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__	:Tuple      =      feature_extractor(speech_inputs[0]			,       return_tensors='''np''' ).input_values
    UpperCAmelCase__	:Optional[int]      =      feature_extractor(np_speech_inputs[0]			,       return_tensors='''np''' ).input_values
    self.assertTrue(np.allclose(__lowerCamelCase			,       __lowerCamelCase			,       atol=1e-3 ) )

    # Test batched
    UpperCAmelCase__	:List[Any]      =      feature_extractor(__lowerCamelCase			,       return_tensors='''np''' ).input_values
    UpperCAmelCase__	:List[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__	:Tuple      =      [floats_list((1, x) )[0] for x in (8_0_0, 8_0_0, 8_0_0)]
    UpperCAmelCase__	:Any      =      np.asarray(__lowerCamelCase )
    UpperCAmelCase__	:Tuple      =      feature_extractor(__lowerCamelCase			,       return_tensors='''np''' ).input_values
    UpperCAmelCase__	:List[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        __SCREAMING_SNAKE_CASE					(      self							:	List[str] ):
    UpperCAmelCase__	:Optional[Any]      =      self.feat_extract_tester.prepare_inputs_for_target()
    UpperCAmelCase__	:List[str]      =      self.feature_extraction_class(**self.feat_extract_dict )
    UpperCAmelCase__	:Dict      =      feat_extract.model_input_names[0]

    UpperCAmelCase__	:str      =      BatchFeature({input_name: speech_inputs} )

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

    UpperCAmelCase__	:Dict      =      self.feat_extract_tester.prepare_inputs_for_target(equal_length=__lowerCamelCase )
    UpperCAmelCase__	:Optional[Any]      =      BatchFeature({input_name: speech_inputs}			,       tensor_type='''np''' )

    UpperCAmelCase__	:Any      =      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        __SCREAMING_SNAKE_CASE					(      self							:	Union[str, Any] ):
    UpperCAmelCase__	:List[Any]      =      self.feat_extract_tester.prepare_inputs_for_target(equal_length=__lowerCamelCase )
    UpperCAmelCase__	:Tuple      =      self.feature_extraction_class(**self.feat_extract_dict )
    UpperCAmelCase__	:int      =      feat_extract.model_input_names[0]

    UpperCAmelCase__	:int      =      BatchFeature({input_name: speech_inputs}			,       tensor_type='''pt''' )

    UpperCAmelCase__	:Tuple      =      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        __SCREAMING_SNAKE_CASE					(      self							:	Union[str, Any] ):
    UpperCAmelCase__	:Union[str, Any]      =      self.feature_extraction_class(**self.feat_extract_dict )
    UpperCAmelCase__	:List[Any]      =      self.feat_extract_tester.prepare_inputs_for_target()
    UpperCAmelCase__	:Optional[Any]      =      feat_extract.model_input_names[0]

    UpperCAmelCase__	:Any      =      BatchFeature({input_name: speech_inputs} )

    UpperCAmelCase__	:str      =      feat_extract.num_mel_bins  # hack!

    UpperCAmelCase__	:Optional[Any]      =      feat_extract.pad(__lowerCamelCase			,       padding='''longest'''			,       return_tensors='''np''' )[input_name]
    UpperCAmelCase__	:Any      =      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        __SCREAMING_SNAKE_CASE					(      self							:	Dict ):
    UpperCAmelCase__	:List[Any]      =      self.feat_extract_dict
    UpperCAmelCase__	:Dict      =      True
    UpperCAmelCase__	:List[str]      =      self.feature_extraction_class(**__lowerCamelCase )
    UpperCAmelCase__	:str      =      self.feat_extract_tester.prepare_inputs_for_target()
    UpperCAmelCase__	:Union[str, Any]      =      [len(__lowerCamelCase ) for x in speech_inputs]
    UpperCAmelCase__	:List[Any]      =      feat_extract.model_input_names[0]

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

    UpperCAmelCase__	:Tuple      =      feat_extract.num_mel_bins  # hack!

    UpperCAmelCase__	:Tuple      =      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        __SCREAMING_SNAKE_CASE					(      self							:	Optional[Any] ):
    UpperCAmelCase__	:List[Any]      =      self.feat_extract_dict
    UpperCAmelCase__	:Optional[int]      =      True
    UpperCAmelCase__	:int      =      self.feature_extraction_class(**__lowerCamelCase )
    UpperCAmelCase__	:List[Any]      =      self.feat_extract_tester.prepare_inputs_for_target()
    UpperCAmelCase__	:Any      =      [len(__lowerCamelCase ) for x in speech_inputs]
    UpperCAmelCase__	:List[str]      =      feat_extract.model_input_names[0]

    UpperCAmelCase__	:str      =      BatchFeature({input_name: speech_inputs} )
    UpperCAmelCase__	:int      =      min(__lowerCamelCase )

    UpperCAmelCase__	:Optional[int]      =      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        __SCREAMING_SNAKE_CASE					(      self							:	int			,       __lowerCamelCase							:	List[Any] ):
    from datasets import load_dataset

    UpperCAmelCase__	:List[Any]      =      load_dataset('''hf-internal-testing/librispeech_asr_dummy'''			,       '''clean'''			,       split='''validation''' )
    # automatic decoding with librispeech
    UpperCAmelCase__	:Any      =      ds.sort('''id''' ).select(range(__lowerCamelCase ) )[:num_samples]['''audio''']

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


 def        __SCREAMING_SNAKE_CASE					(      self							:	Optional[Any] ):
    # fmt: off
    UpperCAmelCase__	:Union[str, 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

    UpperCAmelCase__	:Dict      =      self._load_datasamples(1 )
    UpperCAmelCase__	:List[str]      =      SpeechTaFeatureExtractor()
    UpperCAmelCase__	:Optional[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        __SCREAMING_SNAKE_CASE					(      self							:	List[str] ):
    # fmt: off
    UpperCAmelCase__	:Union[str, Any]      =      torch.tensor(
        [-2.68_70, -3.01_04, -3.13_56, -3.53_52, -3.00_44, -3.03_53, -3.47_19, -3.67_77,
         -3.15_20, -2.94_35, -2.65_53, -2.87_95, -2.99_44, -2.59_21, -3.02_79, -3.03_86,
         -3.08_64, -3.12_91, -3.23_53, -2.74_44, -2.68_31, -2.72_87, -3.17_61, -3.15_71,
         -3.27_26, -3.05_82, -3.10_07, -3.45_33, -3.46_95, -3.09_98] )
    # fmt: on

    UpperCAmelCase__	:Optional[Any]      =      self._load_datasamples(1 )
    UpperCAmelCase__	:Union[str, Any]      =      SpeechTaFeatureExtractor()
    UpperCAmelCase__	:List[Any]      =      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 ) )







'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__lowerCamelCase												=						{
    '''configuration_maskformer''': ['''MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''MaskFormerConfig'''],
    '''configuration_maskformer_swin''': ['''MaskFormerSwinConfig'''],
}

try:
    if not is_vision_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase												=						['''MaskFormerFeatureExtractor''']
    __lowerCamelCase												=						['''MaskFormerImageProcessor''']


try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase												=						[
        '''MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
        '''MaskFormerForInstanceSegmentation''',
        '''MaskFormerModel''',
        '''MaskFormerPreTrainedModel''',
    ]
    __lowerCamelCase												=						[
        '''MaskFormerSwinBackbone''',
        '''MaskFormerSwinModel''',
        '''MaskFormerSwinPreTrainedModel''',
    ]

if TYPE_CHECKING:
    from .configuration_maskformer import MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, MaskFormerConfig
    from .configuration_maskformer_swin import MaskFormerSwinConfig

    try:
        if not is_vision_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .feature_extraction_maskformer import MaskFormerFeatureExtractor
        from .image_processing_maskformer import MaskFormerImageProcessor
    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_maskformer import (
            MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
            MaskFormerForInstanceSegmentation,
            MaskFormerModel,
            MaskFormerPreTrainedModel,
        )
        from .modeling_maskformer_swin import (
            MaskFormerSwinBackbone,
            MaskFormerSwinModel,
            MaskFormerSwinPreTrainedModel,
        )


else:
    import sys

    __lowerCamelCase												=						_LazyModule(__name__, globals()['''__file__'''], _import_structure)



