
"""simple docstring"""



import itertools
import random
import unittest

import numpy as np

from transformers import is_speech_available
from transformers.testing_utils import require_torch, require_torchaudio

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_speech_available():
 from transformers import SpeechaTextFeatureExtractor

UpperCAmelCase__          = random.Random()
def 					_UpperCAmelCase      ( __lowerCamelCase   :       List[str] ,					__lowerCamelCase   :       str=1.0 ,					__lowerCamelCase   :       Optional[Any]=None ,					__lowerCamelCase   :       Any=None		)     ->					Union[str, Any]:
  if rng is None:
    _snake_case					     =       global_rng

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

  return values

@require_torch
@require_torchaudio
class       lowerCAmelCase__				(						unittest.TestCase	):







     def __init__(							self			:			int    ,      _lowerCamelCase			:			Tuple    ,      _lowerCamelCase			:			List[str]=7    ,      _lowerCamelCase			:			Any=400    ,      _lowerCamelCase			:			List[Any]=2000    ,      _lowerCamelCase			:			Tuple=24    ,      _lowerCamelCase			:			str=24    ,      _lowerCamelCase			:			Any=0.0    ,      _lowerCamelCase			:			Any=16000    ,      _lowerCamelCase			:			Any=True    ,      _lowerCamelCase			:			str=True    ,      ):
       _snake_case					     =       parent
       _snake_case					     =       batch_size
       _snake_case					     =       min_seq_length
       _snake_case					     =       max_seq_length
       _snake_case					     =       (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
       _snake_case					     =       feature_size
       _snake_case					     =       num_mel_bins
       _snake_case					     =       padding_value
       _snake_case					     =       sampling_rate
       _snake_case					     =       return_attention_mask
       _snake_case					     =       do_normalize







     def      lowercase	(							self			:			Any			):
       return {
           "feature_size": self.feature_size,
           "num_mel_bins": self.num_mel_bins,
           "padding_value": self.padding_value,
           "sampling_rate": self.sampling_rate,
           "return_attention_mask": self.return_attention_mask,
           "do_normalize": self.do_normalize,
       }







     def      lowercase	(							self			:			Dict    ,      _lowerCamelCase			:			Any=False    ,      _lowerCamelCase			:			Any=False			):
       def _flatten(_lowerCamelCase			:			Tuple			):
         return list(itertools.chain(*_lowerCamelCase			)			)

       if equal_length:
         _snake_case					     =       [floats_list((self.max_seq_length, self.feature_size)			) for _ in range(self.batch_size			)]
       else:
         # make sure that inputs increase in size
         _snake_case					     =       [
             floats_list((x, self.feature_size)			)
             for x in range(self.min_seq_length    ,      self.max_seq_length    ,      self.seq_length_diff			)
         ]
       if numpify:
         _snake_case					     =       [np.asarray(_lowerCamelCase			) for x in speech_inputs]
       return speech_inputs






@require_torch
@require_torchaudio
class       lowerCAmelCase__				(						A_ ,	unittest.TestCase	):
     __a						=					SpeechaTextFeatureExtractor if is_speech_available() else None







     def      lowercase	(							self			:			Optional[int]			):
       _snake_case					     =       SpeechaTextFeatureExtractionTester(self			)







     def      lowercase	(							self			:			List[Any]    ,      _lowerCamelCase			:			Optional[int]			):
       self.assertTrue(np.all(np.mean(_lowerCamelCase    ,      axis=0			) < 1e-3			)			)
       self.assertTrue(np.all(np.abs(np.var(_lowerCamelCase    ,      axis=0			) - 1			) < 1e-3			)			)







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

       # Test feature size
       _snake_case					     =       feature_extractor(_lowerCamelCase    ,      padding=_lowerCamelCase    ,      return_tensors='''np'''			).input_features
       self.assertTrue(input_features.ndim == 3			)
       self.assertTrue(input_features.shape[-1] == feature_extractor.feature_size			)

       # Test not batched input
       _snake_case					     =       feature_extractor(speech_inputs[0]    ,      return_tensors='''np'''			).input_features
       _snake_case					     =       feature_extractor(np_speech_inputs[0]    ,      return_tensors='''np'''			).input_features
       self.assertTrue(np.allclose(_lowerCamelCase    ,      _lowerCamelCase    ,      atol=1e-3			)			)

       # Test batched
       _snake_case					     =       feature_extractor(_lowerCamelCase    ,      return_tensors='''np'''			).input_features
       _snake_case					     =       feature_extractor(_lowerCamelCase    ,      return_tensors='''np'''			).input_features
       for enc_seq_a, enc_seq_a in zip(_lowerCamelCase    ,      _lowerCamelCase			):
         self.assertTrue(np.allclose(_lowerCamelCase    ,      _lowerCamelCase    ,      atol=1e-3			)			)

       # Test 2-D numpy arrays are batched.
       _snake_case					     =       [floats_list((1, x)			)[0] for x in (800, 800, 800)]
       _snake_case					     =       np.asarray(_lowerCamelCase			)
       _snake_case					     =       feature_extractor(_lowerCamelCase    ,      return_tensors='''np'''			).input_features
       _snake_case					     =       feature_extractor(_lowerCamelCase    ,      return_tensors='''np'''			).input_features
       for enc_seq_a, enc_seq_a in zip(_lowerCamelCase    ,      _lowerCamelCase			):
         self.assertTrue(np.allclose(_lowerCamelCase    ,      _lowerCamelCase    ,      atol=1e-3			)			)







     def      lowercase	(							self			:			Optional[int]			):
       _snake_case					     =       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
       _snake_case					     =       [floats_list((1, x)			)[0] for x in range(800    ,      1400    ,      200			)]

       _snake_case					     =       ['''longest''', '''max_length''', '''do_not_pad''']
       _snake_case					     =       [None, 16, None]
       for max_length, padding in zip(_lowerCamelCase    ,      _lowerCamelCase			):
         _snake_case					     =       feature_extractor(
             _lowerCamelCase    ,      padding=_lowerCamelCase    ,      max_length=_lowerCamelCase    ,      return_attention_mask=_lowerCamelCase			)
         _snake_case					     =       inputs.input_features
         _snake_case					     =       inputs.attention_mask
         _snake_case					     =       [np.sum(_lowerCamelCase			) for x in attention_mask]

         self._check_zero_mean_unit_variance(input_features[0][: fbank_feat_lengths[0]]			)
         self._check_zero_mean_unit_variance(input_features[1][: fbank_feat_lengths[1]]			)
         self._check_zero_mean_unit_variance(input_features[2][: fbank_feat_lengths[2]]			)







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

       _snake_case					     =       ['''longest''', '''max_length''', '''do_not_pad''']
       _snake_case					     =       [None, 16, None]
       for max_length, padding in zip(_lowerCamelCase    ,      _lowerCamelCase			):
         _snake_case					     =       feature_extractor(
             _lowerCamelCase    ,      max_length=_lowerCamelCase    ,      padding=_lowerCamelCase    ,      return_tensors='''np'''    ,      return_attention_mask=_lowerCamelCase			)
         _snake_case					     =       inputs.input_features
         _snake_case					     =       inputs.attention_mask
         _snake_case					     =       [np.sum(_lowerCamelCase			) for x in attention_mask]

         self._check_zero_mean_unit_variance(input_features[0][: fbank_feat_lengths[0]]			)
         self.assertTrue(input_features[0][fbank_feat_lengths[0] :].sum() < 1e-6			)
         self._check_zero_mean_unit_variance(input_features[1][: fbank_feat_lengths[1]]			)
         self.assertTrue(input_features[0][fbank_feat_lengths[1] :].sum() < 1e-6			)
         self._check_zero_mean_unit_variance(input_features[2][: fbank_feat_lengths[2]]			)







     def      lowercase	(							self			:			List[str]			):
       _snake_case					     =       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
       _snake_case					     =       [floats_list((1, x)			)[0] for x in range(800    ,      1400    ,      200			)]
       _snake_case					     =       feature_extractor(
           _lowerCamelCase    ,      padding='''max_length'''    ,      max_length=4    ,      truncation=_lowerCamelCase    ,      return_tensors='''np'''    ,      return_attention_mask=_lowerCamelCase    ,      )
       _snake_case					     =       inputs.input_features
       _snake_case					     =       inputs.attention_mask
       _snake_case					     =       np.sum(attention_mask == 1    ,      axis=1			)

       self._check_zero_mean_unit_variance(input_features[0, : fbank_feat_lengths[0]]			)
       self._check_zero_mean_unit_variance(input_features[1]			)
       self._check_zero_mean_unit_variance(input_features[2]			)







     def      lowercase	(							self			:			Optional[Any]			):
       _snake_case					     =       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
       _snake_case					     =       [floats_list((1, x)			)[0] for x in range(800    ,      1400    ,      200			)]
       _snake_case					     =       feature_extractor(
           _lowerCamelCase    ,      padding='''longest'''    ,      max_length=4    ,      truncation=_lowerCamelCase    ,      return_tensors='''np'''    ,      return_attention_mask=_lowerCamelCase    ,      )
       _snake_case					     =       inputs.input_features
       _snake_case					     =       inputs.attention_mask
       _snake_case					     =       np.sum(attention_mask == 1    ,      axis=1			)

       self._check_zero_mean_unit_variance(input_features[0, : fbank_feat_lengths[0]]			)
       self._check_zero_mean_unit_variance(input_features[1, : fbank_feat_lengths[1]]			)
       self._check_zero_mean_unit_variance(input_features[2]			)

       # make sure that if max_length < longest -> then pad to max_length
       self.assertEqual(input_features.shape    ,      (3, 4, 24)			)

       _snake_case					     =       [floats_list((1, x)			)[0] for x in range(800    ,      1400    ,      200			)]
       _snake_case					     =       feature_extractor(
           _lowerCamelCase    ,      padding='''longest'''    ,      max_length=16    ,      truncation=_lowerCamelCase    ,      return_tensors='''np'''    ,      return_attention_mask=_lowerCamelCase    ,      )
       _snake_case					     =       inputs.input_features
       _snake_case					     =       inputs.attention_mask
       _snake_case					     =       np.sum(attention_mask == 1    ,      axis=1			)

       self._check_zero_mean_unit_variance(input_features[0, : fbank_feat_lengths[0]]			)
       self._check_zero_mean_unit_variance(input_features[1, : fbank_feat_lengths[1]]			)
       self._check_zero_mean_unit_variance(input_features[2]			)

       # make sure that if max_length < longest -> then pad to max_length
       self.assertEqual(input_features.shape    ,      (3, 6, 24)			)







     def      lowercase	(							self			:			int			):
       import torch

       _snake_case					     =       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
       _snake_case					     =       np.random.rand(100    ,      32			).astype(np.floataa			)
       _snake_case					     =       np_speech_inputs.tolist()

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







     def      lowercase	(							self			:			Tuple    ,      _lowerCamelCase			:			str			):
       from datasets import load_dataset

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

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







     def      lowercase	(							self			:			Any			):
       # fmt: off
       _snake_case					     =       np.array([
           -1.5_7_4_5, -1.7_7_1_3, -1.7_0_2_0, -1.6_0_6_9, -1.2_2_5_0, -1.1_1_0_5, -0.9_0_7_2, -0.8_2_4_1,
           -1.2_3_1_0, -0.8_0_9_8, -0.3_3_2_0, -0.4_1_0_1, -0.7_9_8_5, -0.4_9_9_6, -0.8_2_1_3, -0.9_1_2_8,
           -1.0_4_2_0, -1.1_2_8_6, -1.0_4_4_0, -0.7_9_9_9, -0.8_4_0_5, -1.2_2_7_5, -1.5_4_4_3, -1.4_6_2_5,
       ]			)
       # fmt: on

       _snake_case					     =       self._load_datasamples(1			)
       _snake_case					     =       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
       _snake_case					     =       feature_extractor(_lowerCamelCase    ,      return_tensors='''pt'''			).input_features
       self.assertEquals(input_features.shape    ,      (1, 584, 24)			)
       self.assertTrue(np.allclose(input_features[0, 0, :30]    ,      _lowerCamelCase    ,      atol=1e-4			)			)





"""simple docstring"""



from math import sqrt
def 					_UpperCAmelCase      ( __lowerCamelCase   :       int = 1_00_00_00		)     ->					int:
  _snake_case					     =       0
  _snake_case					     =       0
  _snake_case					     =       42

  while num_cuboids <= limit:
    max_cuboid_size += 1
    for sum_shortest_sides in range(2 ,					2 * max_cuboid_size + 1		):
      if sqrt(sum_shortest_sides**2 + max_cuboid_size**2		).is_integer():
        num_cuboids += (
            min(__lowerCamelCase ,					sum_shortest_sides // 2		)
            - max(1 ,					sum_shortest_sides - max_cuboid_size		)
            + 1
        )

  return max_cuboid_size


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



