



"""simple docstring"""


import itertools
import random
import unittest

import numpy as np

from transformers import WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST, WavaVecaConfig, WavaVecaFeatureExtractor
from transformers.testing_utils import require_torch, slow

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


snake_case_    					=	random.Random()

def 			_lowerCAmelCase				(       lowercase_		,     lowercase_=1.0		,     lowercase_=None		,     lowercase_=None						):
						if rng is None:
												UpperCAmelCase					=			global_rng

						UpperCAmelCase					=			[]
						for batch_idx in range(shape[0]						):
												values.append([]						)
												for _ in range(shape[1]						):
																		values[-1].append(rng.random() * scale						)

						return values







class 				A_      (					unittest.TestCase    ):



						"""simple docstring"""






						def __init__( self			:str       ,  lowercase_			:int       ,  lowercase_			:str=7       ,  lowercase_			:Union[str, Any]=4_00       ,  lowercase_			:Any=20_00       ,  lowercase_			:Optional[int]=1       ,  lowercase_			:int=0.0       ,  lowercase_			:Optional[int]=1_60_00       ,  lowercase_			:Any=True       ,  lowercase_			:Union[str, Any]=True       ,  )    ->      Optional[int]:
												UpperCAmelCase					=			parent
												UpperCAmelCase					=			batch_size
												UpperCAmelCase					=			min_seq_length
												UpperCAmelCase					=			max_seq_length
												UpperCAmelCase					=			(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
												UpperCAmelCase					=			feature_size
												UpperCAmelCase					=			padding_value
												UpperCAmelCase					=			sampling_rate
												UpperCAmelCase					=			return_attention_mask
												UpperCAmelCase					=			do_normalize






						def      UpperCAmelCase__					( self			:Optional[int] )    ->      Tuple:
												return {
												    "feature_size": self.feature_size,
												    "padding_value": self.padding_value,
												    "sampling_rate": self.sampling_rate,
												    "return_attention_mask": self.return_attention_mask,
												    "do_normalize": self.do_normalize,
												}






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

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

												return speech_inputs







class 				A_      (					SCREAMING_SNAKE_CASE_     ,       unittest.TestCase    ):



						"""simple docstring"""
						__UpperCamelCase		    =							WavaVecaFeatureExtractor






						def      UpperCAmelCase__					( self			:Dict )    ->      Optional[Any]:
												UpperCAmelCase					=			WavaVecaFeatureExtractionTester(self )






						def      UpperCAmelCase__					( self			:Optional[int]       ,  lowercase_			:List[str] )    ->      str:
												self.assertTrue(np.all(np.mean(lowercase_       ,  axis=0 ) < 1E-3 ) )
												self.assertTrue(np.all(np.abs(np.var(lowercase_       ,  axis=0 ) - 1 ) < 1E-3 ) )






						def      UpperCAmelCase__					( self			:List[str] )    ->      Dict:
												# Tests that all call wrap to encode_plus and batch_encode_plus
												UpperCAmelCase					=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
												# create three inputs of length 800, 1000, and 1200
												UpperCAmelCase					=			[floats_list((1, x) )[0] for x in range(8_00       ,  14_00       ,  2_00 )]
												UpperCAmelCase					=			[np.asarray(lowercase_ ) for speech_input in speech_inputs]

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

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

												# Test 2-D numpy arrays are batched.
												UpperCAmelCase					=			[floats_list((1, x) )[0] for x in (8_00, 8_00, 8_00)]
												UpperCAmelCase					=			np.asarray(lowercase_ )
												UpperCAmelCase					=			feat_extract(lowercase_       ,  return_tensors='np' ).input_values
												UpperCAmelCase					=			feat_extract(lowercase_       ,  return_tensors='np' ).input_values
												for enc_seq_a, enc_seq_a in zip(lowercase_       ,  lowercase_ ):
																		self.assertTrue(np.allclose(lowercase_       ,  lowercase_       ,  atol=1E-3 ) )






						def      UpperCAmelCase__					( self			:Optional[Any] )    ->      Union[str, Any]:
												UpperCAmelCase					=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
												UpperCAmelCase					=			[floats_list((1, x) )[0] for x in range(8_00       ,  14_00       ,  2_00 )]

												UpperCAmelCase					=			['longest', 'max_length', 'do_not_pad']
												UpperCAmelCase					=			[None, 16_00, None]
												for max_length, padding in zip(lowercase_       ,  lowercase_ ):
																		UpperCAmelCase					=			feat_extract(lowercase_       ,  padding=lowercase_       ,  max_length=lowercase_       ,  return_tensors='np' )
																		UpperCAmelCase					=			processed.input_values

																		self._check_zero_mean_unit_variance(input_values[0][:8_00] )
																		self.assertTrue(input_values[0][8_00:].sum() < 1E-6 )
																		self._check_zero_mean_unit_variance(input_values[1][:10_00] )
																		self.assertTrue(input_values[0][10_00:].sum() < 1E-6 )
																		self._check_zero_mean_unit_variance(input_values[2][:12_00] )






						def      UpperCAmelCase__					( self			:List[str] )    ->      Tuple:
												UpperCAmelCase					=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
												UpperCAmelCase					=			range(8_00       ,  14_00       ,  2_00 )
												UpperCAmelCase					=			[floats_list((1, x) )[0] for x in lengths]

												UpperCAmelCase					=			['longest', 'max_length', 'do_not_pad']
												UpperCAmelCase					=			[None, 16_00, None]

												for max_length, padding in zip(lowercase_       ,  lowercase_ ):
																		UpperCAmelCase					=			feat_extract(lowercase_       ,  max_length=lowercase_       ,  padding=lowercase_ )
																		UpperCAmelCase					=			processed.input_values

																		self._check_zero_mean_unit_variance(input_values[0][:8_00] )
																		self._check_zero_mean_unit_variance(input_values[1][:10_00] )
																		self._check_zero_mean_unit_variance(input_values[2][:12_00] )






						def      UpperCAmelCase__					( self			:Optional[Any] )    ->      Any:
												UpperCAmelCase					=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
												UpperCAmelCase					=			[floats_list((1, x) )[0] for x in range(8_00       ,  14_00       ,  2_00 )]
												UpperCAmelCase					=			feat_extract(
												    lowercase_       ,  truncation=lowercase_       ,  max_length=10_00       ,  padding='max_length'       ,  return_tensors='np' )
												UpperCAmelCase					=			processed.input_values

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






						def      UpperCAmelCase__					( self			:Dict )    ->      List[Any]:
												UpperCAmelCase					=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
												UpperCAmelCase					=			[floats_list((1, x) )[0] for x in range(8_00       ,  14_00       ,  2_00 )]
												UpperCAmelCase					=			feat_extract(
												    lowercase_       ,  truncation=lowercase_       ,  max_length=10_00       ,  padding='longest'       ,  return_tensors='np' )
												UpperCAmelCase					=			processed.input_values

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

												UpperCAmelCase					=			[floats_list((1, x) )[0] for x in range(8_00       ,  14_00       ,  2_00 )]
												UpperCAmelCase					=			feat_extract(
												    lowercase_       ,  truncation=lowercase_       ,  max_length=20_00       ,  padding='longest'       ,  return_tensors='np' )
												UpperCAmelCase					=			processed.input_values

												self._check_zero_mean_unit_variance(input_values[0, :8_00] )
												self._check_zero_mean_unit_variance(input_values[1, :10_00] )
												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, 12_00) )






						@require_torch
						def      UpperCAmelCase__					( self			:List[str] )    ->      Optional[int]:
												import torch

												UpperCAmelCase					=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
												UpperCAmelCase					=			np.random.rand(1_00 ).astype(np.floataa )
												UpperCAmelCase					=			np_speech_inputs.tolist()

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






						@slow
						@require_torch
						def      UpperCAmelCase__					( self			:Optional[Any] )    ->      Union[str, Any]:
												# this test makes sure that models that are using
												# group norm don't have their feature extractor return the
												# attention_mask
												for model_id in WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST:
																		UpperCAmelCase					=			WavaVecaConfig.from_pretrained(lowercase_ )
																		UpperCAmelCase					=			WavaVecaFeatureExtractor.from_pretrained(lowercase_ )

																		# only "layer" feature extraction norm should make use of
																		# attention_mask
																		self.assertEqual(feat_extract.return_attention_mask       ,  config.feat_extract_norm == 'layer' )










"""simple docstring"""


def 			_lowerCAmelCase				(       ):
						for n in range(1		,     1000000						):
												yield n * (n + 1) // 2

def 			_lowerCAmelCase				(       lowercase_						):
						UpperCAmelCase					=			1
						UpperCAmelCase					=			2
						while i * i <= n:
												UpperCAmelCase					=			0
												while n % i == 0:
																		n //= i
																		multiplicity += 1
												divisors_count *= multiplicity + 1
												i += 1
						if n > 1:
												divisors_count *= 2
						return divisors_count

def 			_lowerCAmelCase				(       ):
						return next(i for i in triangle_number_generator() if count_divisors(lowercase_						) > 500						)


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





