






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

  """simple docstring"""






  if rng is None:
    SCREAMING_SNAKE_CASE							:   List[str]						    =     global_rng

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

  return values


class 			SCREAMING_SNAKE_CASE      (      unittest.TestCase       ):
     '''simple docstring'''


     def __init__(					self							:						str       ,			UpperCAmelCase_							:						Optional[Any]       ,			UpperCAmelCase_							:						Any=7       ,			UpperCAmelCase_							:						int=400       ,			UpperCAmelCase_							:						Optional[int]=2000       ,			UpperCAmelCase_							:						Optional[Any]=1       ,			UpperCAmelCase_							:						Tuple=0.0       ,			UpperCAmelCase_							:						Any=1_6000       ,			UpperCAmelCase_							:						Dict=True       ,			UpperCAmelCase_							:						Dict=True       ,			):
       SCREAMING_SNAKE_CASE							:   List[str]						    =     parent
       SCREAMING_SNAKE_CASE							:   Tuple						    =     batch_size
       SCREAMING_SNAKE_CASE							:   List[str]						    =     min_seq_length
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     max_seq_length
       SCREAMING_SNAKE_CASE							:   str						    =     (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
       SCREAMING_SNAKE_CASE							:   Tuple						    =     feature_size
       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     padding_value
       SCREAMING_SNAKE_CASE							:   str						    =     sampling_rate
       SCREAMING_SNAKE_CASE							:   int						    =     return_attention_mask
       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     do_normalize


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







       def _flatten(UpperCAmelCase_							:						List[str]   ):
         return list(itertools.chain(*UpperCAmelCase_   )   )

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

       return speech_inputs





class 			SCREAMING_SNAKE_CASE      (      a_   ,		unittest.TestCase       ):
     '''simple docstring'''


     UpperCamelCase_				:		Any								=						WavaVecaFeatureExtractor


     def 					_A							(					self							:						Optional[int]   ):
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     WavaVecaFeatureExtractionTester(self   )


     def 					_A							(					self							:						Dict       ,			UpperCAmelCase_							:						Union[str, Any]   ):
       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 					_A							(					self							:						Dict   ):
       SCREAMING_SNAKE_CASE							:   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							:   Union[str, Any]						    =     [floats_list((1, x)   )[0] for x in range(800       ,			1400       ,			200   )]
       SCREAMING_SNAKE_CASE							:   Tuple						    =     [np.asarray(UpperCAmelCase_   ) 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							:   Any						    =     feat_extract(np_speech_inputs[0]       ,			return_tensors="np"   ).input_values
       self.assertTrue(np.allclose(UpperCAmelCase_       ,			UpperCAmelCase_       ,			atol=1E-3   )   )

       # Test batched
       SCREAMING_SNAKE_CASE							:   Optional[int]						    =     feat_extract(UpperCAmelCase_       ,			return_tensors="np"   ).input_values
       SCREAMING_SNAKE_CASE							:   Optional[int]						    =     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   )   )

       # Test 2-D numpy arrays are batched.
       SCREAMING_SNAKE_CASE							:   Dict						    =     [floats_list((1, x)   )[0] for x in (800, 800, 800)]
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     np.asarray(UpperCAmelCase_   )
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     feat_extract(UpperCAmelCase_       ,			return_tensors="np"   ).input_values
       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     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 					_A							(					self							:						Dict   ):
       SCREAMING_SNAKE_CASE							:   int						    =     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
       SCREAMING_SNAKE_CASE							:   Any						    =     [floats_list((1, x)   )[0] for x in range(800       ,			1400       ,			200   )]

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

       SCREAMING_SNAKE_CASE							:   List[Any]						    =     ["longest", "max_length", "do_not_pad"]
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     [None, 1600, None]

       for max_length, padding in zip(UpperCAmelCase_       ,			UpperCAmelCase_   ):
         SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     feat_extract(UpperCAmelCase_       ,			max_length=UpperCAmelCase_       ,			padding=UpperCAmelCase_   )
         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][:1200]   )


     def 					_A							(					self							:						List[str]   ):
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     [floats_list((1, x)   )[0] for x in range(800       ,			1400       ,			200   )]
       SCREAMING_SNAKE_CASE							:   str						    =     feat_extract(
           UpperCAmelCase_       ,			truncation=UpperCAmelCase_       ,			max_length=1000       ,			padding="max_length"       ,			return_tensors="np"   )
       SCREAMING_SNAKE_CASE							:   str						    =     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 					_A							(					self							:						Tuple   ):
       SCREAMING_SNAKE_CASE							:   str						    =     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
       SCREAMING_SNAKE_CASE							:   Any						    =     [floats_list((1, x)   )[0] for x in range(800       ,			1400       ,			200   )]
       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     feat_extract(
           UpperCAmelCase_       ,			truncation=UpperCAmelCase_       ,			max_length=1000       ,			padding="longest"       ,			return_tensors="np"   )
       SCREAMING_SNAKE_CASE							:   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 max_length
       self.assertTrue(input_values.shape == (3, 1000)   )

       SCREAMING_SNAKE_CASE							:   Dict						    =     [floats_list((1, x)   )[0] for x in range(800       ,			1400       ,			200   )]
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     feat_extract(
           UpperCAmelCase_       ,			truncation=UpperCAmelCase_       ,			max_length=2000       ,			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 longest
       self.assertTrue(input_values.shape == (3, 1200)   )


     @require_torch
     def 					_A							(					self							:						Tuple   ):
       import torch

       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     np.random.rand(100   ).astype(np.floataa   )
       SCREAMING_SNAKE_CASE							:   List[str]						    =     np_speech_inputs.tolist()

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






     @slow
     @require_torch
     def 					_A							(					self							:						Optional[int]   ):







       for model_id in WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST:
         SCREAMING_SNAKE_CASE							:   List[str]						    =     WavaVecaConfig.from_pretrained(UpperCAmelCase_   )
         SCREAMING_SNAKE_CASE							:   int						    =     WavaVecaFeatureExtractor.from_pretrained(UpperCAmelCase_   )

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










def 	__lowerCamelCase						(							lowerCamelCase__		:						int      ):





			'''simple docstring'''




			lowerCamelCase    		=  (1 + 24 * n) ** 0.5
			return ((1 + root) / 6) % 1 == 0






def 	__lowerCamelCase						(							lowerCamelCase__		:						int = 5000      ):





			'''simple docstring'''




			lowerCamelCase    		=  [(i * (3 * i - 1)) // 2 for i in range(1  ,							lowerCamelCase__      )]
			for i, pentagonal_i in enumerate(lowerCamelCase__      ):
						for j in range(lowerCamelCase__  ,							len(lowerCamelCase__      )      ):
									lowerCamelCase    		=  pentagonal_nums[j]
									lowerCamelCase    		=  pentagonal_i + pentagonal_j
									lowerCamelCase    		=  pentagonal_j - pentagonal_i
									if is_pentagonal(lowerCamelCase__      ) and is_pentagonal(lowerCamelCase__      ):
												return b

			return -1


if __name__ == "__main__":
		print(f"""{solution() = }""")

