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


lowercase__ 	=     random.Random()

if is_torch_available():
 import torch







def 						__a       (     _SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE=1.0		,					_SCREAMING_SNAKE_CASE=None		,					_SCREAMING_SNAKE_CASE=None       )     ->str:
  if rng is None:
    a__:					int      							=     global_rng

  a__:					Union[str, Any]      							=     []
  for batch_idx in range(shape[0]       ):
    values.append([]       )
    for _ in range(shape[1]       ):
      values[-1].append(rng.random() * scale       )

  return values




class        __snake_case	(					unittest.TestCase    ):



      def __init__(						self   ,      lowercase   ,      lowercase=7   ,      lowercase=4_00   ,      lowercase=20_00   ,      lowercase=1   ,      lowercase=0.0   ,      lowercase=1_60_00   ,      lowercase=True   ,      lowercase=True   ,      )     ->      Any:





        '''simple docstring'''





        a__:					Tuple      							=     parent
        a__:					int      							=     batch_size
        a__:					Union[str, Any]      							=     min_seq_length
        a__:					str      							=     max_seq_length
        a__:					int      							=     (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
        a__:					Optional[int]      							=     feature_size
        a__:					Union[str, Any]      							=     padding_value
        a__:					Dict      							=     sampling_rate
        a__:					List[Any]      							=     return_attention_mask
        a__:					List[Any]      							=     do_normalize



      def   lowerCamelCase_       (						self)     ->      Optional[Any]:





        '''simple docstring'''





        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   ,      lowercase=False   ,      lowercase=False)     ->      Union[str, Any]:





        '''simple docstring'''





        def _flatten(lowercase):
          return list(itertools.chain(*lowercase))

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

        return speech_inputs







@require_torch
@require_torchaudio
class        __snake_case	(					__lowerCAmelCase	,				unittest.TestCase    ):
      a__				=		ASTFeatureExtractor



      def   lowerCamelCase_       (						self)     ->      Tuple:





        '''simple docstring'''





        a__:					str      							=     ASTFeatureExtractionTester(self)



      def   lowerCamelCase_       (						self)     ->      Dict:





        '''simple docstring'''





        a__:					List[str]      							=     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
        # create three inputs of length 800, 1000, and 1200
        a__:					Optional[int]      							=     [floats_list((1, x))[0] for x in range(8_00   ,      14_00   ,      2_00)]
        a__:					Optional[Any]      							=     [np.asarray(lowercase) for speech_input in speech_inputs]

        # Test not batched input
        a__:					Any      							=     feat_extract(speech_inputs[0]   ,      return_tensors='np').input_values
        a__:					List[str]      							=     feat_extract(np_speech_inputs[0]   ,      return_tensors='np').input_values
        self.assertTrue(np.allclose(lowercase   ,      lowercase   ,      atol=1e-3))

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





        '''simple docstring'''





        import torch

        a__:					List[str]      							=     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
        a__:					str      							=     np.random.rand(1_00).astype(np.floataa)
        a__:					Any      							=     np_speech_inputs.tolist()

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



      def   lowerCamelCase_       (						self   ,      lowercase)     ->      Tuple:





        '''simple docstring'''





        from datasets import load_dataset

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

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



      @require_torch
      def   lowerCamelCase_       (						self)     ->      str:





        '''simple docstring'''





        a__:					Optional[Any]      							=     torch.tensor(
            [-0.9894, -1.2776, -0.9066, -1.2776, -0.9349, -1.2609, -1.0386, -1.2776,
             -1.1561, -1.2776, -1.2052, -1.2723, -1.2190, -1.2132, -1.2776, -1.1133,
             -1.1953, -1.1343, -1.1584, -1.2203, -1.1770, -1.2474, -1.2381, -1.1936,
             -0.9270, -0.8317, -0.8049, -0.7706, -0.7565, -0.7869])
        # fmt: on

        a__:					Optional[Any]      							=     self._load_datasamples(1)
        a__:					Tuple      							=     ASTFeatureExtractor()
        a__:					List[Any]      							=     feature_extractor(lowercase   ,      return_tensors='pt').input_values
        self.assertEquals(input_values.shape   ,      (1, 10_24, 1_28))
        self.assertTrue(torch.allclose(input_values[0, 0, :30]   ,      lowercase   ,      atol=1e-4))



"""simple docstring"""
def 						__a       (     _SCREAMING_SNAKE_CASE = 1000000       )     ->int:
  a__:					Any      							=     limit + 1
  a__:					List[str]      							=     [0] * limit
  for first_term in range(1		,					_SCREAMING_SNAKE_CASE       ):
    for n in range(_SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       ):
      a__:					Any      							=     first_term + n / first_term
      if common_difference % 4:  # d must be divisble by 4
        continue
      else:
        common_difference /= 4
        if (
            first_term > common_difference
            and first_term < 4 * common_difference
        ):  # since x,y,z are positive integers
          frequency[n] += 1  # so z>0 and a>d ,also 4d<a

  a__:					Optional[int]      							=     sum(1 for x in frequency[1:limit] if x == 10       )

  return count


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


