



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


__snake_case							:   Any      =    random.Random()


def 			_lowercase				(  __snake_case					,__snake_case=1.0					,__snake_case=None					,__snake_case=None	)						->   int:
			if rng is None:
						__lowerCAmelCase      :  Union[str, Any]												=       global_rng

			__lowerCAmelCase      :  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 			A__   (  unittest.TestCase							):




	'''simple docstring'''





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

				"""simple docstring"""

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

	def 							_SCREAMING_SNAKE_CASE   (     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 							_SCREAMING_SNAKE_CASE   (     self:		List[str]       ,			_SCREAMING_SNAKE_CASE:		Any=False       ,			_SCREAMING_SNAKE_CASE:		List[str]=False)				->       List[Any]:

				"""simple docstring"""

				def _flatten(_SCREAMING_SNAKE_CASE:		Tuple):
							return list(itertools.chain(*_SCREAMING_SNAKE_CASE))

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

				return speech_inputs







	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=False       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=False)				->       Any:

				"""simple docstring"""

				if equal_length:
							__lowerCAmelCase      :  Tuple												=       [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[Any]												=       [
							    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      :  str												=       [np.asarray(_SCREAMING_SNAKE_CASE) for x in speech_inputs]

				return speech_inputs






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




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	SpeechTaFeatureExtractor

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

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       SpeechTaFeatureExtractionTester(self)

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

				"""simple docstring"""

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

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int])				->       List[str]:

				"""simple docstring"""

				__lowerCAmelCase      :  Any												=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
				# create three inputs of length 800, 1000, and 1200
				__lowerCAmelCase      :  Optional[int]												=       [floats_list((1, x))[0] for x in range(800       ,			1400       ,			200)]
				__lowerCAmelCase      :  Any												=       [np.asarray(_SCREAMING_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      :  Dict												=       feat_extract(np_speech_inputs[0]       ,			return_tensors="np").input_values
				self.assertTrue(np.allclose(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ,			atol=1e-3))

				# Test batched
				__lowerCAmelCase      :  List[str]												=       feat_extract(_SCREAMING_SNAKE_CASE       ,			return_tensors="np").input_values
				__lowerCAmelCase      :  Optional[int]												=       feat_extract(_SCREAMING_SNAKE_CASE       ,			return_tensors="np").input_values
				for enc_seq_a, enc_seq_a in zip(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE):
							self.assertTrue(np.allclose(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ,			atol=1e-3))

	def 							_SCREAMING_SNAKE_CASE   (     self:		Dict)				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
				__lowerCAmelCase      :  Any												=       [floats_list((1, x))[0] for x in range(800       ,			1400       ,			200)]

				__lowerCAmelCase      :  str												=       ["longest", "max_length", "do_not_pad"]
				__lowerCAmelCase      :  Optional[int]												=       [None, 1600, None]
				for max_length, padding in zip(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE):
							__lowerCAmelCase      :  Any												=       feat_extract(_SCREAMING_SNAKE_CASE       ,			padding=_SCREAMING_SNAKE_CASE       ,			max_length=_SCREAMING_SNAKE_CASE       ,			return_tensors="np")
							__lowerCAmelCase      :  List[str]												=       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 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int])				->       Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  List[str]												=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
				__lowerCAmelCase      :  Optional[int]												=       range(800       ,			1400       ,			200)
				__lowerCAmelCase      :  Dict												=       [floats_list((1, x))[0] for x in lengths]

				__lowerCAmelCase      :  Any												=       ["longest", "max_length", "do_not_pad"]
				__lowerCAmelCase      :  Dict												=       [None, 1600, None]

				for max_length, padding in zip(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE):
							__lowerCAmelCase      :  List[str]												=       feat_extract(_SCREAMING_SNAKE_CASE       ,			max_length=_SCREAMING_SNAKE_CASE       ,			padding=_SCREAMING_SNAKE_CASE)
							__lowerCAmelCase      :  str												=       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 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int])				->       str:

				"""simple docstring"""

				__lowerCAmelCase      :  int												=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
				__lowerCAmelCase      :  Optional[Any]												=       [floats_list((1, x))[0] for x in range(800       ,			1400       ,			200)]
				__lowerCAmelCase      :  str												=       feat_extract(
				    _SCREAMING_SNAKE_CASE       ,			truncation=_SCREAMING_SNAKE_CASE       ,			max_length=1000       ,			padding="max_length"       ,			return_tensors="np")
				__lowerCAmelCase      :  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 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any])				->       Dict:

				"""simple docstring"""

				__lowerCAmelCase      :  int												=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
				__lowerCAmelCase      :  List[Any]												=       [floats_list((1, x))[0] for x in range(800       ,			1400       ,			200)]
				__lowerCAmelCase      :  List[Any]												=       feat_extract(
				    _SCREAMING_SNAKE_CASE       ,			truncation=_SCREAMING_SNAKE_CASE       ,			max_length=1000       ,			padding="longest"       ,			return_tensors="np")
				__lowerCAmelCase      :  Optional[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))

				__lowerCAmelCase      :  Dict												=       [floats_list((1, x))[0] for x in range(800       ,			1400       ,			200)]
				__lowerCAmelCase      :  Optional[int]												=       feat_extract(
				    _SCREAMING_SNAKE_CASE       ,			truncation=_SCREAMING_SNAKE_CASE       ,			max_length=2000       ,			padding="longest"       ,			return_tensors="np")
				__lowerCAmelCase      :  str												=       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 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       List[str]:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[Any]												=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
				__lowerCAmelCase      :  Optional[int]												=       np.random.rand(100).astype(np.floataa)
				__lowerCAmelCase      :  Any												=       np_speech_inputs.tolist()

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

	def 							_SCREAMING_SNAKE_CASE   (     self:		str)				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Any												=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
				# create three inputs of length 800, 1000, and 1200
				__lowerCAmelCase      :  Optional[int]												=       [floats_list((1, x))[0] for x in range(800       ,			1400       ,			200)]
				__lowerCAmelCase      :  Union[str, Any]												=       [np.asarray(_SCREAMING_SNAKE_CASE) for speech_input in speech_inputs]

				# Test feature size
				__lowerCAmelCase      :  List[str]												=       feature_extractor(audio_target=_SCREAMING_SNAKE_CASE       ,			padding=_SCREAMING_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      :  Any												=       feature_extractor(speech_inputs[0]       ,			return_tensors="np").input_values
				__lowerCAmelCase      :  Union[str, Any]												=       feature_extractor(np_speech_inputs[0]       ,			return_tensors="np").input_values
				self.assertTrue(np.allclose(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ,			atol=1e-3))

				# Test batched
				__lowerCAmelCase      :  List[str]												=       feature_extractor(_SCREAMING_SNAKE_CASE       ,			return_tensors="np").input_values
				__lowerCAmelCase      :  List[str]												=       feature_extractor(_SCREAMING_SNAKE_CASE       ,			return_tensors="np").input_values
				for enc_seq_a, enc_seq_a in zip(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE):
							self.assertTrue(np.allclose(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ,			atol=1e-3))

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

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

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[Any]												=       self.feat_extract_tester.prepare_inputs_for_target()
				__lowerCAmelCase      :  List[Any]												=       self.feature_extraction_class(**self.feat_extract_dict)
				__lowerCAmelCase      :  str												=       feat_extract.model_input_names[0]

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

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

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

				__lowerCAmelCase      :  List[str]												=       processed_features[input_name]

				if len(batch_features_input.shape) < 3:
							__lowerCAmelCase      :  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 							_SCREAMING_SNAKE_CASE   (     self:		List[Any])				->       Dict:

				"""simple docstring"""

				__lowerCAmelCase      :  str												=       self.feat_extract_tester.prepare_inputs_for_target(equal_length=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[Any]												=       self.feature_extraction_class(**self.feat_extract_dict)
				__lowerCAmelCase      :  int												=       feat_extract.model_input_names[0]

				__lowerCAmelCase      :  Dict												=       BatchFeature({input_name: speech_inputs}       ,			tensor_type="pt")

				__lowerCAmelCase      :  Any												=       processed_features[input_name]

				if len(batch_features_input.shape) < 3:
							__lowerCAmelCase      :  Tuple												=       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:		List[str])				->       Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase      :  int												=       self.feature_extraction_class(**self.feat_extract_dict)
				__lowerCAmelCase      :  Dict												=       self.feat_extract_tester.prepare_inputs_for_target()
				__lowerCAmelCase      :  Optional[Any]												=       feat_extract.model_input_names[0]

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

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

				__lowerCAmelCase      :  Tuple												=       feat_extract.pad(_SCREAMING_SNAKE_CASE       ,			padding="longest"       ,			return_tensors="np")[input_name]
				__lowerCAmelCase      :  List[str]												=       feat_extract.pad(_SCREAMING_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 							_SCREAMING_SNAKE_CASE   (     self:		str)				->       Tuple:

				"""simple docstring"""

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

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

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

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

	def 							_SCREAMING_SNAKE_CASE   (     self:		Dict)				->       Optional[Any]:

				"""simple docstring"""

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

				__lowerCAmelCase      :  Optional[int]												=       BatchFeature({input_name: speech_inputs})
				__lowerCAmelCase      :  List[str]												=       min(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Dict												=       feat_extract.num_mel_bins  # hack!

				__lowerCAmelCase      :  List[Any]												=       feat_extract.pad(
				    _SCREAMING_SNAKE_CASE       ,			padding="max_length"       ,			max_length=_SCREAMING_SNAKE_CASE       ,			truncation=_SCREAMING_SNAKE_CASE       ,			return_tensors="np")
				self.assertIn("attention_mask"       ,			_SCREAMING_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 							_SCREAMING_SNAKE_CASE   (     self:		Dict       ,			_SCREAMING_SNAKE_CASE:		Dict)				->       Optional[Any]:

				"""simple docstring"""

				from datasets import load_dataset

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

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

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Union[str, Any]												=       torch.tensor(
				    [2.3804e-03, 2.0752e-03, 1.9836e-03, 2.1057e-03, 1.6174e-03,
				     3.0518e-04, 9.1553e-05, 3.3569e-04, 9.7656e-04, 1.8311e-03,
				     2.0142e-03, 2.1057e-03, 1.7395e-03, 4.5776e-04, -3.9673e-04,
				     4.5776e-04, 1.0071e-03, 9.1553e-05, 4.8828e-04, 1.1597e-03,
				     7.3242e-04, 9.4604e-04, 1.8005e-03, 1.8311e-03, 8.8501e-04,
				     4.2725e-04, 4.8828e-04, 7.3242e-04, 1.0986e-03, 2.1057e-03])
				# fmt: on

				__lowerCAmelCase      :  str												=       self._load_datasamples(1)
				__lowerCAmelCase      :  Optional[int]												=       SpeechTaFeatureExtractor()
				__lowerCAmelCase      :  str												=       feature_extractor(_SCREAMING_SNAKE_CASE       ,			return_tensors="pt").input_values
				self.assertEquals(input_values.shape       ,			(1, 9_3680))
				self.assertTrue(torch.allclose(input_values[0, :30]       ,			_SCREAMING_SNAKE_CASE       ,			atol=1e-6))







	def 							_SCREAMING_SNAKE_CASE   (     self:		List[str])				->       Tuple:

				"""simple docstring"""

				__lowerCAmelCase      :  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

				__lowerCAmelCase      :  int												=       self._load_datasamples(1)
				__lowerCAmelCase      :  str												=       SpeechTaFeatureExtractor()
				__lowerCAmelCase      :  List[str]												=       feature_extractor(audio_target=_SCREAMING_SNAKE_CASE       ,			return_tensors="pt").input_values
				self.assertEquals(input_values.shape       ,			(1, 366, 80))
				self.assertTrue(torch.allclose(input_values[0, 0, :30]       ,			_SCREAMING_SNAKE_CASE       ,			atol=1e-4))




"""simple docstring"""






import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


__snake_case							:   Optional[int]      =    50_000
__snake_case							:   Dict      =    5_000

__snake_case      ,		__snake_case							:   Union[str, Any]      =    os.path.split(__file__)
__snake_case							:   Any      =    os.path.join(RESULTS_BASEPATH, 'results', RESULTS_FILENAME.replace('.py', '.json'))


@get_duration
def 			_lowercase				(  __snake_case					,__snake_case	)						->   Dict:
			for i in range(__snake_case	):
						__lowerCAmelCase      :  Union[str, Any]												=       dataset[i]


@get_duration
def 			_lowercase				(  __snake_case					,__snake_case					,__snake_case	)						->   Dict:
			for i in range(0					,len(__snake_case	)					,__snake_case	):
						__lowerCAmelCase      :  List[str]												=       dataset[i : i + batch_size]


@get_duration
def 			_lowercase				(  __snake_case					,__snake_case					,__snake_case	)						->   Dict:
			with dataset.formatted_as(type=__snake_case	):
						for i in range(__snake_case	):
									__lowerCAmelCase      :  Union[str, Any]												=       dataset[i]


@get_duration
def 			_lowercase				(  __snake_case					,__snake_case					,__snake_case					,__snake_case	)						->   str:
			with dataset.formatted_as(type=__snake_case	):
						for i in range(0					,__snake_case					,__snake_case	):
									__lowerCAmelCase      :  Optional[int]												=       dataset[i : i + batch_size]


def 			_lowercase				(  )						->   Union[str, Any]:
			__lowerCAmelCase      :  Optional[int]												=       {"num examples": SPEED_TEST_N_EXAMPLES}
			__lowerCAmelCase      :  Optional[int]												=       [
			    (read, {"length": SMALL_TEST}),
			    (read, {"length": SPEED_TEST_N_EXAMPLES}),
			    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 10}),
			    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 100}),
			    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 1_000}),
			    (read_formatted, {"type": "numpy", "length": SMALL_TEST}),
			    (read_formatted, {"type": "pandas", "length": SMALL_TEST}),
			    (read_formatted, {"type": "torch", "length": SMALL_TEST}),
			    (read_formatted, {"type": "tensorflow", "length": SMALL_TEST}),
			    (read_formatted_batch, {"type": "numpy", "length": SMALL_TEST, "batch_size": 10}),
			    (read_formatted_batch, {"type": "numpy", "length": SMALL_TEST, "batch_size": 1_000}),
			]

			__lowerCAmelCase      :  Any												=       [
			    (read, {"length": SMALL_TEST}),
			    (read, {"length": SPEED_TEST_N_EXAMPLES}),
			    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 10}),
			    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 100}),
			    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 1_000}),
			    (read_formatted, {"type": "numpy", "length": SMALL_TEST}),
			    (read_formatted_batch, {"type": "numpy", "length": SMALL_TEST, "batch_size": 10}),
			    (read_formatted_batch, {"type": "numpy", "length": SMALL_TEST, "batch_size": 1_000}),
			]
			with tempfile.TemporaryDirectory() as tmp_dir:
						print("generating dataset"	)
						__lowerCAmelCase      :  int												=       datasets.Features(
						    {"list": datasets.Sequence(datasets.Value("float32"	)	), "numbers": datasets.Value("float32"	)}	)
						__lowerCAmelCase      :  str												=       generate_example_dataset(
						    os.path.join(__snake_case					,"dataset.arrow"	)					,__snake_case					,num_examples=__snake_case					,seq_shapes={"list": (100,)}					,)
						print("first set of iterations"	)
						for func, kwargs in functions:
									print(func.__name__					,str(__snake_case	)	)
									__lowerCAmelCase      :  str												=       func(__snake_case					,**__snake_case	)

						print("shuffling dataset"	)
						__lowerCAmelCase      :  Optional[int]												=       dataset.shuffle()
						print("Second set of iterations (after shuffling"	)
						for func, kwargs in functions_shuffled:
									print("shuffled "					,func.__name__					,str(__snake_case	)	)
									__lowerCAmelCase      :  List[str]												=       func(
									    __snake_case					,**__snake_case	)

			with open(__snake_case					,"wb"	) as f:
						f.write(json.dumps(__snake_case	).encode("utf-8"	)	)


if __name__ == "__main__":  # useful to run the profiler
	benchmark_iterating()