



'''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	:		int				=   random.Random()



def   __lowerCAmelCase					(							lowerCamelCase   :						Optional[Any]				,		lowerCamelCase   :						Optional[Any]=1.0				,		lowerCamelCase   :						Union[str, Any]=None				,		lowerCamelCase   :						Optional[Any]=None					):






	'''simple docstring'''




	if rng is None:
		__lowerCAmelCase												=  global_rng

	__lowerCAmelCase												=  []
	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			,				UpperCamelCase			,				UpperCamelCase=7			,				UpperCamelCase=400			,				UpperCamelCase=2000			,				UpperCamelCase=1			,				UpperCamelCase=0.0			,				UpperCamelCase=1_6000			,				UpperCamelCase=True			,				UpperCamelCase=80			,				UpperCamelCase=16			,				UpperCamelCase=64			,				UpperCamelCase="hann_window"			,				UpperCamelCase=80			,				UpperCamelCase=7600			,				UpperCamelCase=1E-10			,				UpperCamelCase=True			,				)     ->			Dict:
						__lowerCAmelCase												=  parent
						__lowerCAmelCase												=  batch_size
						__lowerCAmelCase												=  min_seq_length
						__lowerCAmelCase												=  max_seq_length
						__lowerCAmelCase												=  (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
						__lowerCAmelCase												=  feature_size
						__lowerCAmelCase												=  padding_value
						__lowerCAmelCase												=  sampling_rate
						__lowerCAmelCase												=  do_normalize
						__lowerCAmelCase												=  num_mel_bins
						__lowerCAmelCase												=  hop_length
						__lowerCAmelCase												=  win_length
						__lowerCAmelCase												=  win_function
						__lowerCAmelCase												=  fmin
						__lowerCAmelCase												=  fmax
						__lowerCAmelCase												=  mel_floor
						__lowerCAmelCase												=  return_attention_mask



					def        UpperCAmelCase_ (    self     )     ->			Any:
						return {
						    "feature_size": self.feature_size,
						    "padding_value": self.padding_value,
						    "sampling_rate": self.sampling_rate,
						    "do_normalize": self.do_normalize,
						    "num_mel_bins": self.num_mel_bins,
						    "hop_length": self.hop_length,
						    "win_length": self.win_length,
						    "win_function": self.win_function,
						    "fmin": self.fmin,
						    "fmax": self.fmax,
						    "mel_floor": self.mel_floor,
						    "return_attention_mask": self.return_attention_mask,
						}



					def        UpperCAmelCase_ (    self			,				UpperCamelCase=False			,				UpperCamelCase=False     )     ->			Union[str, Any]:
						def _flatten(UpperCamelCase     ):
							return list(itertools.chain(*UpperCamelCase     )     )

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

						return speech_inputs



					def        UpperCAmelCase_ (    self			,				UpperCamelCase=False			,				UpperCamelCase=False     )     ->			int:
						if equal_length:
							__lowerCAmelCase												=  [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												=  [
							    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												=  [np.asarray(UpperCamelCase     ) for x in speech_inputs]

						return speech_inputs






@require_torch
class 					UpperCAmelCase__	(		UpperCamelCase__							,       unittest.TestCase ):
					a      :     Any        =							SpeechTaFeatureExtractor



					def        UpperCAmelCase_ (    self     )     ->			Dict:
						__lowerCAmelCase												=  SpeechTaFeatureExtractionTester(self     )



					def        UpperCAmelCase_ (    self			,				UpperCamelCase     )     ->			str:
						self.assertTrue(np.all(np.mean(UpperCamelCase			,				axis=0     ) < 1E-3     )     )
						self.assertTrue(np.all(np.abs(np.var(UpperCamelCase			,				axis=0     ) - 1     ) < 1E-3     )     )



					def        UpperCAmelCase_ (    self     )     ->			str:
						# Tests that all call wrap to encode_plus and batch_encode_plus
						__lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()     )
						# create three inputs of length 800, 1000, and 1200
						__lowerCAmelCase												=  [floats_list((1, x)     )[0] for x in range(800			,				1400			,				200     )]
						__lowerCAmelCase												=  [np.asarray(UpperCamelCase     ) for speech_input in speech_inputs]

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

						# Test batched
						__lowerCAmelCase												=  feat_extract(UpperCamelCase			,				return_tensors="np"     ).input_values
						__lowerCAmelCase												=  feat_extract(UpperCamelCase			,				return_tensors="np"     ).input_values
						for enc_seq_a, enc_seq_a in zip(UpperCamelCase			,				UpperCamelCase     ):
							self.assertTrue(np.allclose(UpperCamelCase			,				UpperCamelCase			,				atol=1E-3     )     )



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

						__lowerCAmelCase												=  ["longest", "max_length", "do_not_pad"]
						__lowerCAmelCase												=  [None, 1600, None]
						for max_length, padding in zip(UpperCamelCase			,				UpperCamelCase     ):
							__lowerCAmelCase												=  feat_extract(UpperCamelCase			,				padding=UpperCamelCase			,				max_length=UpperCamelCase			,				return_tensors="np"     )
							__lowerCAmelCase												=  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        UpperCAmelCase_ (    self     )     ->			Optional[Any]:
						__lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()     )
						__lowerCAmelCase												=  range(800			,				1400			,				200     )
						__lowerCAmelCase												=  [floats_list((1, x)     )[0] for x in lengths]

						__lowerCAmelCase												=  ["longest", "max_length", "do_not_pad"]
						__lowerCAmelCase												=  [None, 1600, None]

						for max_length, padding in zip(UpperCamelCase			,				UpperCamelCase     ):
							__lowerCAmelCase												=  feat_extract(UpperCamelCase			,				max_length=UpperCamelCase			,				padding=UpperCamelCase     )
							__lowerCAmelCase												=  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        UpperCAmelCase_ (    self     )     ->			Optional[int]:
						__lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()     )
						__lowerCAmelCase												=  [floats_list((1, x)     )[0] for x in range(800			,				1400			,				200     )]
						__lowerCAmelCase												=  feat_extract(
						    UpperCamelCase			,				truncation=UpperCamelCase			,				max_length=1000			,				padding="max_length"			,				return_tensors="np"     )
						__lowerCAmelCase												=  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        UpperCAmelCase_ (    self     )     ->			Optional[Any]:
						__lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()     )
						__lowerCAmelCase												=  [floats_list((1, x)     )[0] for x in range(800			,				1400			,				200     )]
						__lowerCAmelCase												=  feat_extract(
						    UpperCamelCase			,				truncation=UpperCamelCase			,				max_length=1000			,				padding="longest"			,				return_tensors="np"     )
						__lowerCAmelCase												=  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												=  [floats_list((1, x)     )[0] for x in range(800			,				1400			,				200     )]
						__lowerCAmelCase												=  feat_extract(
						    UpperCamelCase			,				truncation=UpperCamelCase			,				max_length=2000			,				padding="longest"			,				return_tensors="np"     )
						__lowerCAmelCase												=  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        UpperCAmelCase_ (    self     )     ->			Optional[int]:
						__lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()     )
						__lowerCAmelCase												=  np.random.rand(100     ).astype(np.floataa     )
						__lowerCAmelCase												=  np_speech_inputs.tolist()

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



					def        UpperCAmelCase_ (    self     )     ->			Optional[int]:
						# Tests that all call wrap to encode_plus and batch_encode_plus
						__lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()     )
						# create three inputs of length 800, 1000, and 1200
						__lowerCAmelCase												=  [floats_list((1, x)     )[0] for x in range(800			,				1400			,				200     )]
						__lowerCAmelCase												=  [np.asarray(UpperCamelCase     ) for speech_input in speech_inputs]

						# Test feature size
						__lowerCAmelCase												=  feature_extractor(audio_target=UpperCamelCase			,				padding=UpperCamelCase			,				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												=  feature_extractor(speech_inputs[0]			,				return_tensors="np"     ).input_values
						__lowerCAmelCase												=  feature_extractor(np_speech_inputs[0]			,				return_tensors="np"     ).input_values
						self.assertTrue(np.allclose(UpperCamelCase			,				UpperCamelCase			,				atol=1E-3     )     )

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

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



					def        UpperCAmelCase_ (    self     )     ->			int:
						__lowerCAmelCase												=  self.feat_extract_tester.prepare_inputs_for_target()
						__lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_dict     )
						__lowerCAmelCase												=  feat_extract.model_input_names[0]

						__lowerCAmelCase												=  BatchFeature({input_name: speech_inputs}     )

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

						__lowerCAmelCase												=  self.feat_extract_tester.prepare_inputs_for_target(equal_length=UpperCamelCase     )
						__lowerCAmelCase												=  BatchFeature({input_name: speech_inputs}			,				tensor_type="np"     )

						__lowerCAmelCase												=  processed_features[input_name]

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

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



					@require_torch
					def        UpperCAmelCase_ (    self     )     ->			Any:
						__lowerCAmelCase												=  self.feat_extract_tester.prepare_inputs_for_target(equal_length=UpperCamelCase     )
						__lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_dict     )
						__lowerCAmelCase												=  feat_extract.model_input_names[0]

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

						__lowerCAmelCase												=  processed_features[input_name]

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

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



					@require_torch
					def        UpperCAmelCase_ (    self     )     ->			List[Any]:
						__lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_dict     )
						__lowerCAmelCase												=  self.feat_extract_tester.prepare_inputs_for_target()
						__lowerCAmelCase												=  feat_extract.model_input_names[0]

						__lowerCAmelCase												=  BatchFeature({input_name: speech_inputs}     )

						__lowerCAmelCase												=  feat_extract.num_mel_bins  # hack!

						__lowerCAmelCase												=  feat_extract.pad(UpperCamelCase			,				padding="longest"			,				return_tensors="np"     )[input_name]
						__lowerCAmelCase												=  feat_extract.pad(UpperCamelCase			,				padding="longest"			,				return_tensors="pt"     )[input_name]

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



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

						__lowerCAmelCase												=  BatchFeature({input_name: speech_inputs}     )

						__lowerCAmelCase												=  feat_extract.num_mel_bins  # hack!

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



					def        UpperCAmelCase_ (    self     )     ->			Any:
						__lowerCAmelCase												=  self.feat_extract_dict
						__lowerCAmelCase												=  True
						__lowerCAmelCase												=  self.feature_extraction_class(**UpperCamelCase     )
						__lowerCAmelCase												=  self.feat_extract_tester.prepare_inputs_for_target()
						__lowerCAmelCase												=  [len(UpperCamelCase     ) for x in speech_inputs]
						__lowerCAmelCase												=  feat_extract.model_input_names[0]

						__lowerCAmelCase												=  BatchFeature({input_name: speech_inputs}     )
						__lowerCAmelCase												=  min(UpperCamelCase     )

						__lowerCAmelCase												=  feat_extract.num_mel_bins  # hack!

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



					def        UpperCAmelCase_ (    self			,				UpperCamelCase     )     ->			Dict:
						from datasets import load_dataset

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

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



					def        UpperCAmelCase_ (    self     )     ->			Optional[Any]:
						# fmt: off
						__lowerCAmelCase												=  torch.tensor(
						    [2.3_804E-03, 2.0_752E-03, 1.9_836E-03, 2.1_057E-03, 1.6_174E-03,
						     3.0_518E-04, 9.1_553E-05, 3.3_569E-04, 9.7_656E-04, 1.8_311E-03,
						     2.0_142E-03, 2.1_057E-03, 1.7_395E-03, 4.5_776E-04, -3.9_673E-04,
						     4.5_776E-04, 1.0_071E-03, 9.1_553E-05, 4.8_828E-04, 1.1_597E-03,
						     7.3_242E-04, 9.4_604E-04, 1.8_005E-03, 1.8_311E-03, 8.8_501E-04,
						     4.2_725E-04, 4.8_828E-04, 7.3_242E-04, 1.0_986E-03, 2.1_057E-03]     )
						# fmt: on

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



					def        UpperCAmelCase_ (    self     )     ->			Any:
						# fmt: off
						__lowerCAmelCase												=  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

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




'''simple docstring'''



def   __lowerCAmelCase					(							lowerCamelCase   :						Union[str, Any]					):






	'''simple docstring'''




	__lowerCAmelCase												=  1
	__lowerCAmelCase												=  2
	while i * i <= n:
		__lowerCAmelCase												=  0
		while n % i == 0:
			n //= i
			multiplicity += 1
		n_divisors *= multiplicity + 1
		i += 1
	if n > 1:
		n_divisors *= 2
	return n_divisors



def   __lowerCAmelCase					(							):






	'''simple docstring'''




	__lowerCAmelCase												=  1
	__lowerCAmelCase												=  1

	while True:
		i += 1
		t_num += i

		if count_divisors(lowerCamelCase					) > 5_00:
			break

	return t_num


if __name__ == "__main__":
	print(solution())