




import argparse
import struct
import unittest

class       snake_case					:




  def __init__(      self     :	List[str]     , a_     :	bytes				)->       List[str]:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				Tuple			=		data

       # Initialize hash values
       SCREAMING_SNAKE_CASE__				:				Dict			=		[
           0x6_a_0_9_e_6_6_7,
           0xb_b_6_7_a_e_8_5,
           0x3_c_6_e_f_3_7_2,
           0xa_5_4_f_f_5_3_a,
           0x5_1_0_e_5_2_7_f,
           0x9_b_0_5_6_8_8_c,
           0x1_f_8_3_d_9_a_b,
           0x5_b_e_0_c_d_1_9,
       ]

       # Initialize round constants
       SCREAMING_SNAKE_CASE__				:				int			=		[
           0x4_2_8_a_2_f_9_8,
           0x7_1_3_7_4_4_9_1,
           0xb_5_c_0_f_b_c_f,
           0xe_9_b_5_d_b_a_5,
           0x3_9_5_6_c_2_5_b,
           0x5_9_f_1_1_1_f_1,
           0x9_2_3_f_8_2_a_4,
           0xa_b_1_c_5_e_d_5,
           0xd_8_0_7_a_a_9_8,
           0x1_2_8_3_5_b_0_1,
           0x2_4_3_1_8_5_b_e,
           0x5_5_0_c_7_d_c_3,
           0x7_2_b_e_5_d_7_4,
           0x8_0_d_e_b_1_f_e,
           0x9_b_d_c_0_6_a_7,
           0xc_1_9_b_f_1_7_4,
           0xe_4_9_b_6_9_c_1,
           0xe_f_b_e_4_7_8_6,
           0x0_f_c_1_9_d_c_6,
           0x2_4_0_c_a_1_c_c,
           0x2_d_e_9_2_c_6_f,
           0x4_a_7_4_8_4_a_a,
           0x5_c_b_0_a_9_d_c,
           0x7_6_f_9_8_8_d_a,
           0x9_8_3_e_5_1_5_2,
           0xa_8_3_1_c_6_6_d,
           0xb_0_0_3_2_7_c_8,
           0xb_f_5_9_7_f_c_7,
           0xc_6_e_0_0_b_f_3,
           0xd_5_a_7_9_1_4_7,
           0x0_6_c_a_6_3_5_1,
           0x1_4_2_9_2_9_6_7,
           0x2_7_b_7_0_a_8_5,
           0x2_e_1_b_2_1_3_8,
           0x4_d_2_c_6_d_f_c,
           0x5_3_3_8_0_d_1_3,
           0x6_5_0_a_7_3_5_4,
           0x7_6_6_a_0_a_b_b,
           0x8_1_c_2_c_9_2_e,
           0x9_2_7_2_2_c_8_5,
           0xa_2_b_f_e_8_a_1,
           0xa_8_1_a_6_6_4_b,
           0xc_2_4_b_8_b_7_0,
           0xc_7_6_c_5_1_a_3,
           0xd_1_9_2_e_8_1_9,
           0xd_6_9_9_0_6_2_4,
           0xf_4_0_e_3_5_8_5,
           0x1_0_6_a_a_0_7_0,
           0x1_9_a_4_c_1_1_6,
           0x1_e_3_7_6_c_0_8,
           0x2_7_4_8_7_7_4_c,
           0x3_4_b_0_b_c_b_5,
           0x3_9_1_c_0_c_b_3,
           0x4_e_d_8_a_a_4_a,
           0x5_b_9_c_c_a_4_f,
           0x6_8_2_e_6_f_f_3,
           0x7_4_8_f_8_2_e_e,
           0x7_8_a_5_6_3_6_f,
           0x8_4_c_8_7_8_1_4,
           0x8_c_c_7_0_2_0_8,
           0x9_0_b_e_f_f_f_a,
           0xa_4_5_0_6_c_e_b,
           0xb_e_f_9_a_3_f_7,
           0xc_6_7_1_7_8_f_2,
       ]

       SCREAMING_SNAKE_CASE__				:				Tuple			=		self.preprocessing(self.data				)
       self.final_hash()




  @staticmethod
  def 	__lowercase(      a_     :	bytes				)->       Optional[Any]:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		B'\x80' + (B'\x00' * (63 - (len(_snake_case				) + 8) % 64))
       SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		struct.pack('>Q'     , (len(_snake_case				) * 8)				)
       return data + padding + big_endian_integer




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




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		[
           self.preprocessed_data[x : x + 64]
           for x in range(0     , len(self.preprocessed_data				)     , 64				)
       ]

       for block in self.blocks:
            # Convert the given block into a list of 4 byte integers
            SCREAMING_SNAKE_CASE__				:				Optional[int]			=		list(struct.unpack('>16L'     , _snake_case				)				)
            # add 48 0-ed integers
            words += [0] * 48

            SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__				:				List[str]			=		self.hashes

            for index in range(0     , 64				):
                 if index > 15:
                      # modify the zero-ed indexes at the end of the array
                      SCREAMING_SNAKE_CASE__				:				Any			=		(
                          self.ror(words[index - 15]     , 7				)
                          ^ self.ror(words[index - 15]     , 18				)
                          ^ (words[index - 15] >> 3)
                      )
                      SCREAMING_SNAKE_CASE__				:				Optional[int]			=		(
                          self.ror(words[index - 2]     , 17				)
                          ^ self.ror(words[index - 2]     , 19				)
                          ^ (words[index - 2] >> 10)
                      )

                      SCREAMING_SNAKE_CASE__				:				Dict			=		(
                          words[index - 16] + sa + words[index - 7] + sa
                      ) % 0x1_0_0_0_0_0_0_0_0

                 # Compression
                 SCREAMING_SNAKE_CASE__				:				int			=		self.ror(_snake_case     , 6				) ^ self.ror(_snake_case     , 11				) ^ self.ror(_snake_case     , 25				)
                 SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		(e & f) ^ ((~e & 0xf_f_f_f_f_f_f_f) & g)
                 SCREAMING_SNAKE_CASE__				:				int			=		(
                     h + sa + ch + self.round_constants[index] + words[index]
                 ) % 0x1_0_0_0_0_0_0_0_0
                 SCREAMING_SNAKE_CASE__				:				List[str]			=		self.ror(_snake_case     , 2				) ^ self.ror(_snake_case     , 13				) ^ self.ror(_snake_case     , 22				)
                 SCREAMING_SNAKE_CASE__				:				Tuple			=		(a & b) ^ (a & c) ^ (b & c)
                 SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		(sa + maj) % 0x1_0_0_0_0_0_0_0_0

                 SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__			,							SCREAMING_SNAKE_CASE__				:				Any			=		(
                     g,
                     f,
                     e,
                     ((d + tempa) % 0x1_0_0_0_0_0_0_0_0),
                     c,
                     b,
                     a,
                     ((tempa + tempa) % 0x1_0_0_0_0_0_0_0_0),
                 )

            SCREAMING_SNAKE_CASE__				:				Any			=		[a, b, c, d, e, f, g, h]

            # Modify final values
            SCREAMING_SNAKE_CASE__				:				Dict			=		[
                ((element + mutated_hash_values[index]) % 0x1_0_0_0_0_0_0_0_0)
                for index, element in enumerate(self.hashes				)
            ]

       SCREAMING_SNAKE_CASE__				:				Tuple			=		''.join([hex(_snake_case				)[2:].zfill(8				) for value in self.hashes]				)




  def 	__lowercase(      self     :	Dict     , a_     :	int     , a_     :	int				)->       Union[str, Any]:




       """simple docstring"""
       return 0xf_f_f_f_f_f_f_f & (value << (32 - rotations)) | (value >> rotations)




class       snake_case					(      unittest.TestCase						):




  def 	__lowercase(      self     :	str				)->       int:




       """simple docstring"""
       import hashlib

       SCREAMING_SNAKE_CASE__				:				str			=		bytes('Test String'     , 'utf-8'				)
       self.assertEqual(SHAaaa(_snake_case				).hash     , hashlib.shaaaa(_snake_case				).hexdigest()				)







def     _a				(      ):







     '''simple docstring'''


     import doctest

     doctest.testmod()

     SCREAMING_SNAKE_CASE__				:				Any			=		argparse.ArgumentParser()
     parser.add_argument(
         '-s'     ,  '--string'     ,  dest='input_string'     ,  default='Hello World!! Welcome to Cryptography'     ,  help='Hash the string'     ,  )
     parser.add_argument(
         '-f'     ,  '--file'     ,  dest='input_file'     ,  help='Hash contents of a file' )

     SCREAMING_SNAKE_CASE__				:				str			=		parser.parse_args()

     SCREAMING_SNAKE_CASE__				:				str			=		args.input_string

     # hash input should be a bytestring
     if args.input_file:
          with open(args.input_file     ,  'rb' ) as f:
               SCREAMING_SNAKE_CASE__				:				Dict			=		f.read()
     else:
          SCREAMING_SNAKE_CASE__				:				List[Any]			=		bytes(__UpperCamelCase     ,  'utf-8' )

     print(SHAaaa(__UpperCamelCase ).hash )


if __name__ == "__main__":
      main()




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


SCREAMING_SNAKE_CASE__		:					Optional[Any]						=					random.Random()







def     _a				(      lowercase__  :			List[str]     ,  lowercase__  :			List[Any]=1.0     ,  lowercase__  :			Optional[int]=None     ,  lowercase__  :			List[str]=None ):







     '''simple docstring'''


     if rng is None:
          SCREAMING_SNAKE_CASE__				:				Optional[int]			=		global_rng

     SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		[]
     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       snake_case					(      unittest.TestCase						):




  def __init__(      self     :	List[Any]     , a_     :	Optional[Any]     , a_     :	Union[str, Any]=7     , a_     :	Any=400     , a_     :	List[Any]=2000     , a_     :	Tuple=1     , a_     :	Optional[int]=0.0     , a_     :	Optional[Any]=1_6000     , a_     :	str=True     , a_     :	Union[str, Any]=80     , a_     :	Dict=16     , a_     :	Tuple=64     , a_     :	Any="hann_window"     , a_     :	Union[str, Any]=80     , a_     :	List[Any]=7600     , a_     :	Optional[Any]=1e-1_0     , a_     :	Dict=True     , )->       Dict:




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




  def 	__lowercase(      self     :	Dict				)->       Dict:




       """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 	__lowercase(      self     :	List[Any]     , a_     :	str=False     , a_     :	List[Any]=False				)->       Optional[Any]:




       """simple docstring"""
       def _flatten(a_     :	int				):
            return list(itertools.chain(*a_				)				)

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

       return speech_inputs




  def 	__lowercase(      self     :	Any     , a_     :	int=False     , a_     :	Any=False				)->       Union[str, Any]:




       """simple docstring"""
       if equal_length:
            SCREAMING_SNAKE_CASE__				:				str			=		[floats_list((self.max_seq_length, self.num_mel_bins)				) for _ in range(self.batch_size				)]
       else:
            # make sure that inputs increase in size
            SCREAMING_SNAKE_CASE__				:				Tuple			=		[
                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:
            SCREAMING_SNAKE_CASE__				:				List[str]			=		[np.asarray(a_				) for x in speech_inputs]

       return speech_inputs




@require_torch
class       snake_case					(      UpperCamelCase_   ,						unittest.TestCase						):
  lowercase_			=     SpeechTaFeatureExtractor




  def 	__lowercase(      self     :	List[Any]				)->       List[Any]:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				Any			=		SpeechTaFeatureExtractionTester(self				)




  def 	__lowercase(      self     :	Any     , a_     :	Optional[int]				)->       List[str]:




       """simple docstring"""
       self.assertTrue(np.all(np.mean(a_     , axis=0				) < 1e-3				)				)
       self.assertTrue(np.all(np.abs(np.var(a_     , axis=0				) - 1				) < 1e-3				)				)




  def 	__lowercase(      self     :	Tuple				)->       Dict:




       """simple docstring"""
       # Tests that all call wrap to encode_plus and batch_encode_plus
       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		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__				:				Optional[int]			=		[np.asarray(a_				) for speech_input in speech_inputs]

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

       # Test batched
       SCREAMING_SNAKE_CASE__				:				List[Any]			=		feat_extract(a_     , return_tensors='np'				).input_values
       SCREAMING_SNAKE_CASE__				:				List[str]			=		feat_extract(a_     , return_tensors='np'				).input_values
       for enc_seq_a, enc_seq_a in zip(a_     , a_				):
            self.assertTrue(np.allclose(a_     , a_     , atol=1e-3				)				)




  def 	__lowercase(      self     :	List[Any]				)->       List[Any]:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				int			=		self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
       SCREAMING_SNAKE_CASE__				:				Dict			=		[floats_list((1, x)				)[0] for x in range(800     , 1400     , 200				)]

       SCREAMING_SNAKE_CASE__				:				int			=		['longest', 'max_length', 'do_not_pad']
       SCREAMING_SNAKE_CASE__				:				Tuple			=		[None, 1600, None]
       for max_length, padding in zip(a_     , a_				):
            SCREAMING_SNAKE_CASE__				:				str			=		feat_extract(a_     , padding=a_     , max_length=a_     , return_tensors='np'				)
            SCREAMING_SNAKE_CASE__				:				Optional[int]			=		processed.input_values

            self._check_zero_mean_unit_variance(input_values[0][:800]				)
            self.assertTrue(input_values[0][800:].sum() < 1e-6				)
            self._check_zero_mean_unit_variance(input_values[1][:1000]				)
            self.assertTrue(input_values[0][1000:].sum() < 1e-6				)
            self._check_zero_mean_unit_variance(input_values[2][:1200]				)




  def 	__lowercase(      self     :	List[Any]				)->       List[str]:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				int			=		self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
       SCREAMING_SNAKE_CASE__				:				List[Any]			=		range(800     , 1400     , 200				)
       SCREAMING_SNAKE_CASE__				:				int			=		[floats_list((1, x)				)[0] for x in lengths]

       SCREAMING_SNAKE_CASE__				:				int			=		['longest', 'max_length', 'do_not_pad']
       SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		[None, 1600, None]

       for max_length, padding in zip(a_     , a_				):
            SCREAMING_SNAKE_CASE__				:				List[str]			=		feat_extract(a_     , max_length=a_     , padding=a_				)
            SCREAMING_SNAKE_CASE__				:				int			=		processed.input_values

            self._check_zero_mean_unit_variance(input_values[0][:800]				)
            self._check_zero_mean_unit_variance(input_values[1][:1000]				)
            self._check_zero_mean_unit_variance(input_values[2][:1200]				)




  def 	__lowercase(      self     :	int				)->       Tuple:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				Dict			=		self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
       SCREAMING_SNAKE_CASE__				:				Tuple			=		[floats_list((1, x)				)[0] for x in range(800     , 1400     , 200				)]
       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		feat_extract(
           a_     , truncation=a_     , max_length=1000     , padding='max_length'     , return_tensors='np'				)
       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		processed.input_values

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




  def 	__lowercase(      self     :	Optional[Any]				)->       str:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				str			=		self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		[floats_list((1, x)				)[0] for x in range(800     , 1400     , 200				)]
       SCREAMING_SNAKE_CASE__				:				List[str]			=		feat_extract(
           a_     , truncation=a_     , max_length=1000     , padding='longest'     , return_tensors='np'				)
       SCREAMING_SNAKE_CASE__				:				int			=		processed.input_values

       self._check_zero_mean_unit_variance(input_values[0, :800]				)
       self._check_zero_mean_unit_variance(input_values[1, :1000]				)
       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, 1000)				)

       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		[floats_list((1, x)				)[0] for x in range(800     , 1400     , 200				)]
       SCREAMING_SNAKE_CASE__				:				str			=		feat_extract(
           a_     , truncation=a_     , max_length=2000     , padding='longest'     , return_tensors='np'				)
       SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		processed.input_values

       self._check_zero_mean_unit_variance(input_values[0, :800]				)
       self._check_zero_mean_unit_variance(input_values[1, :1000]				)
       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, 1200)				)




  def 	__lowercase(      self     :	Any				)->       str:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				List[str]			=		self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		np.random.rand(100				).astype(np.floataa				)
       SCREAMING_SNAKE_CASE__				:				int			=		np_speech_inputs.tolist()

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




  def 	__lowercase(      self     :	Any				)->       Optional[int]:




       """simple docstring"""
       # Tests that all call wrap to encode_plus and batch_encode_plus
       SCREAMING_SNAKE_CASE__				:				List[str]			=		self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
       # create three inputs of length 800, 1000, and 1200
       SCREAMING_SNAKE_CASE__				:				List[Any]			=		[floats_list((1, x)				)[0] for x in range(800     , 1400     , 200				)]
       SCREAMING_SNAKE_CASE__				:				Dict			=		[np.asarray(a_				) for speech_input in speech_inputs]

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

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

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




  def 	__lowercase(      self     :	Dict				)->       int:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				str			=		self.feat_extract_tester.prepare_inputs_for_target()
       SCREAMING_SNAKE_CASE__				:				List[Any]			=		self.feature_extraction_class(**self.feat_extract_dict				)
       SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		feat_extract.model_input_names[0]

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

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

       SCREAMING_SNAKE_CASE__				:				str			=		self.feat_extract_tester.prepare_inputs_for_target(equal_length=a_				)
       SCREAMING_SNAKE_CASE__				:				Dict			=		BatchFeature({input_name: speech_inputs}     , tensor_type='np'				)

       SCREAMING_SNAKE_CASE__				:				List[Any]			=		processed_features[input_name]

       if len(batch_features_input.shape				) < 3:
            SCREAMING_SNAKE_CASE__				:				int			=		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 	__lowercase(      self     :	List[Any]				)->       List[Any]:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		self.feat_extract_tester.prepare_inputs_for_target(equal_length=a_				)
       SCREAMING_SNAKE_CASE__				:				Dict			=		self.feature_extraction_class(**self.feat_extract_dict				)
       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		feat_extract.model_input_names[0]

       SCREAMING_SNAKE_CASE__				:				Any			=		BatchFeature({input_name: speech_inputs}     , tensor_type='pt'				)

       SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		processed_features[input_name]

       if len(batch_features_input.shape				) < 3:
            SCREAMING_SNAKE_CASE__				:				Optional[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 	__lowercase(      self     :	Tuple				)->       List[str]:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				int			=		self.feature_extraction_class(**self.feat_extract_dict				)
       SCREAMING_SNAKE_CASE__				:				Dict			=		self.feat_extract_tester.prepare_inputs_for_target()
       SCREAMING_SNAKE_CASE__				:				str			=		feat_extract.model_input_names[0]

       SCREAMING_SNAKE_CASE__				:				List[Any]			=		BatchFeature({input_name: speech_inputs}				)

       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		feat_extract.num_mel_bins  # hack!

       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		feat_extract.pad(a_     , padding='longest'     , return_tensors='np'				)[input_name]
       SCREAMING_SNAKE_CASE__				:				Any			=		feat_extract.pad(a_     , 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 	__lowercase(      self     :	Any				)->       Dict:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				List[Any]			=		self.feat_extract_dict
       SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		True
       SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		self.feature_extraction_class(**a_				)
       SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		self.feat_extract_tester.prepare_inputs_for_target()
       SCREAMING_SNAKE_CASE__				:				Any			=		[len(a_				) for x in speech_inputs]
       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		feat_extract.model_input_names[0]

       SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		BatchFeature({input_name: speech_inputs}				)

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

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




  def 	__lowercase(      self     :	str				)->       Any:




       """simple docstring"""
       SCREAMING_SNAKE_CASE__				:				Any			=		self.feat_extract_dict
       SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		True
       SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		self.feature_extraction_class(**a_				)
       SCREAMING_SNAKE_CASE__				:				Optional[int]			=		self.feat_extract_tester.prepare_inputs_for_target()
       SCREAMING_SNAKE_CASE__				:				Tuple			=		[len(a_				) for x in speech_inputs]
       SCREAMING_SNAKE_CASE__				:				Union[str, Any]			=		feat_extract.model_input_names[0]

       SCREAMING_SNAKE_CASE__				:				Dict			=		BatchFeature({input_name: speech_inputs}				)
       SCREAMING_SNAKE_CASE__				:				str			=		min(a_				)

       SCREAMING_SNAKE_CASE__				:				Any			=		feat_extract.num_mel_bins  # hack!

       SCREAMING_SNAKE_CASE__				:				int			=		feat_extract.pad(
           a_     , padding='max_length'     , max_length=a_     , truncation=a_     , return_tensors='np'				)
       self.assertIn('attention_mask'     , a_				)
       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 	__lowercase(      self     :	Optional[int]     , a_     :	List[str]				)->       Any:




       """simple docstring"""
       from datasets import load_dataset

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

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




  def 	__lowercase(      self     :	List[str]				)->       List[Any]:




       """simple docstring"""
       # fmt: off
       SCREAMING_SNAKE_CASE__				:				List[Any]			=		torch.tensor(
           [2.3_8_0_4e-0_3, 2.0_7_5_2e-0_3, 1.9_8_3_6e-0_3, 2.1_0_5_7e-0_3, 1.6_1_7_4e-0_3,
            3.0_5_1_8e-0_4, 9.1_5_5_3e-0_5, 3.3_5_6_9e-0_4, 9.7_6_5_6e-0_4, 1.8_3_1_1e-0_3,
            2.0_1_4_2e-0_3, 2.1_0_5_7e-0_3, 1.7_3_9_5e-0_3, 4.5_7_7_6e-0_4, -3.9_6_7_3e-0_4,
            4.5_7_7_6e-0_4, 1.0_0_7_1e-0_3, 9.1_5_5_3e-0_5, 4.8_8_2_8e-0_4, 1.1_5_9_7e-0_3,
            7.3_2_4_2e-0_4, 9.4_6_0_4e-0_4, 1.8_0_0_5e-0_3, 1.8_3_1_1e-0_3, 8.8_5_0_1e-0_4,
            4.2_7_2_5e-0_4, 4.8_8_2_8e-0_4, 7.3_2_4_2e-0_4, 1.0_9_8_6e-0_3, 2.1_0_5_7e-0_3]				)
       # fmt: on

       SCREAMING_SNAKE_CASE__				:				List[str]			=		self._load_datasamples(1				)
       SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		SpeechTaFeatureExtractor()
       SCREAMING_SNAKE_CASE__				:				List[str]			=		feature_extractor(a_     , return_tensors='pt'				).input_values
       self.assertEquals(input_values.shape     , (1, 9_3680)				)
       self.assertTrue(torch.allclose(input_values[0, :30]     , a_     , atol=1e-6				)				)




  def 	__lowercase(      self     :	Tuple				)->       List[Any]:




       """simple docstring"""
       # fmt: off
       SCREAMING_SNAKE_CASE__				:				Union[str, 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

       SCREAMING_SNAKE_CASE__				:				Optional[Any]			=		self._load_datasamples(1				)
       SCREAMING_SNAKE_CASE__				:				int			=		SpeechTaFeatureExtractor()
       SCREAMING_SNAKE_CASE__				:				str			=		feature_extractor(audio_target=a_     , return_tensors='pt'				).input_values
       self.assertEquals(input_values.shape     , (1, 366, 80)				)
       self.assertTrue(torch.allclose(input_values[0, 0, :30]     , a_     , atol=1e-4				)				)



