






'''simple docstring'''



import itertools
import random
import unittest

import numpy as np

from transformers import ASTFeatureExtractor
from transformers.testing_utils import require_torch, require_torchaudio
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


__UpperCAmelCase      :int			    =       random.Random()

if is_torch_available():
      import torch




def      _a     (						_lowercase :     Union[str, Any]      , _lowercase :     List[Any]=1.0      , _lowercase :     int=None      , _lowercase :     List[str]=None  ):





     '''simple docstring'''






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

     __UpperCAmelCase     :			Any  							=      []
     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					:		Optional[Any]							,			snake_case					:		Any							,			snake_case					:		List[str]=7							,			snake_case					:		Tuple=400							,			snake_case					:		Union[str, Any]=2000							,			snake_case					:		List[str]=1							,			snake_case					:		Tuple=0.0							,			snake_case					:		Optional[int]=1_6000							,			snake_case					:		List[str]=True							,			snake_case					:		Optional[int]=True							,			)						->							List[str]:
          __UpperCAmelCase     :			Tuple  							=      parent
          __UpperCAmelCase     :			List[str]  							=      batch_size
          __UpperCAmelCase     :			int  							=      min_seq_length
          __UpperCAmelCase     :			Dict  							=      max_seq_length
          __UpperCAmelCase     :			Union[str, Any]  							=      (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
          __UpperCAmelCase     :			Optional[int]  							=      feature_size
          __UpperCAmelCase     :			List[Any]  							=      padding_value
          __UpperCAmelCase     :			int  							=      sampling_rate
          __UpperCAmelCase     :			List[str]  							=      return_attention_mask
          __UpperCAmelCase     :			Optional[int]  							=      do_normalize

     def 			lowerCamelCase__			(    self					:		Any      )						->							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 			lowerCamelCase__			(    self					:		Optional[int]							,			snake_case					:		int=False							,			snake_case					:		Dict=False      )						->							Dict:
          def _flatten(snake_case					:		str      ):
               return list(itertools.chain(*lowercase__      )      )

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

          return speech_inputs



@require_torch
@require_torchaudio
class      a    (		lowerCamelCase__     ,  unittest.TestCase	):


     """simple docstring"""






     SCREAMING_SNAKE_CASE	:			Any							       =       ASTFeatureExtractor

     def 			lowerCamelCase__			(    self					:		Tuple      )						->							Optional[Any]:
          __UpperCAmelCase     :			Any  							=      ASTFeatureExtractionTester(self      )

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

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

          # Test batched
          __UpperCAmelCase     :			Union[str, Any]  							=      feat_extract(lowercase__							,			padding=lowercase__							,			return_tensors='''np'''      ).input_values
          __UpperCAmelCase     :			Optional[Any]  							=      feat_extract(lowercase__							,			padding=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     :			Optional[Any]  							=      [floats_list((1, x)      )[0] for x in (800, 800, 800)]
          __UpperCAmelCase     :			List[Any]  							=      np.asarray(lowercase__      )
          __UpperCAmelCase     :			List[Any]  							=      feat_extract(lowercase__							,			return_tensors='''np'''      ).input_values
          __UpperCAmelCase     :			Dict  							=      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      )      )

     @require_torch
     def 			lowerCamelCase__			(    self					:		List[Any]      )						->							Optional[Any]:
          import torch

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

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

     def 			lowerCamelCase__			(    self					:		str							,			snake_case					:		Union[str, Any]      )						->							str:
          from datasets import load_dataset

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

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






     @require_torch
     def 			lowerCamelCase__			(    self					:		Tuple      )						->							Any:
          # fmt: off
          __UpperCAmelCase     :			Tuple  							=      torch.tensor(
              [-0.9_894, -1.2_776, -0.9_066, -1.2_776, -0.9_349, -1.2_609, -1.0_386, -1.2_776,
               -1.1_561, -1.2_776, -1.2_052, -1.2_723, -1.2_190, -1.2_132, -1.2_776, -1.1_133,
               -1.1_953, -1.1_343, -1.1_584, -1.2_203, -1.1_770, -1.2_474, -1.2_381, -1.1_936,
               -0.9_270, -0.8_317, -0.8_049, -0.7_706, -0.7_565, -0.7_869]      )
          # fmt: on

          __UpperCAmelCase     :			List[Any]  							=      self._load_datasamples(1      )
          __UpperCAmelCase     :			List[str]  							=      ASTFeatureExtractor()
          __UpperCAmelCase     :			List[Any]  							=      feature_extractor(lowercase__							,			return_tensors='''pt'''      ).input_values
          self.assertEquals(input_values.shape							,			(1, 1024, 128)      )
          self.assertTrue(torch.allclose(input_values[0, 0, :30]							,			lowercase__							,			atol=1E-4      )      )



'''simple docstring'''



def      _a     (						_lowercase :     List[str]  ):





     '''simple docstring'''






     __UpperCAmelCase     :			str  							=      1
     __UpperCAmelCase     :			List[str]  							=      2
     while i * i <= n:
          __UpperCAmelCase     :			Optional[Any]  							=      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      _a     (						):





     '''simple docstring'''






     __UpperCAmelCase     :			Optional[Any]  							=      1
     __UpperCAmelCase     :			List[Any]  							=      1

     while True:
          i += 1
          t_num += i

          if count_divisors(_lowercase  ) > 500:
               break

     return t_num


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