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

lowerCAmelCase_			=							random.Random()

def       __lowerCamelCase    (       SCREAMING_SNAKE_CASE,SCREAMING_SNAKE_CASE=1.0,SCREAMING_SNAKE_CASE=None,SCREAMING_SNAKE_CASE=None							)		->       Tuple:






       """simple docstring"""




       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



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






       def __init__(   self    ,  a__    ,  a__=7    ,  a__=4_00    ,  a__=20_00    ,  a__=24    ,  a__=24    ,  a__=0.0    ,  a__=1_60_00    ,  a__=True    ,  a__=True    ,  ):
              _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     =     num_mel_bins
              _UpperCAmelCase     =     padding_value
              _UpperCAmelCase     =     sampling_rate
              _UpperCAmelCase     =     return_attention_mask
              _UpperCAmelCase     =     do_normalize






       def 							__A (   self     ):
              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 							__A (   self    ,  a__=False    ,  a__=False     ):

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

              if equal_length:
                     _UpperCAmelCase     =     [floats_list((self.max_seq_length, self.feature_size)     ) for _ in range(self.batch_size     )]
              else:
                     # make sure that inputs increase in size
                     _UpperCAmelCase     =     [
                         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(a__     ) for x in speech_inputs]
              return speech_inputs



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






       def 							__A (   self     ):
              _UpperCAmelCase     =     SpeechaTextFeatureExtractionTester(self     )






       def 							__A (   self    ,  a__     ):
              self.assertTrue(np.all(np.mean(a__    ,  axis=0     ) < 1E-3     )     )
              self.assertTrue(np.all(np.abs(np.var(a__    ,  axis=0     ) - 1     ) < 1E-3     )     )






       def 							__A (   self     ):
              _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(a__     ) for speech_input in speech_inputs]

              # Test feature size
              _UpperCAmelCase     =     feature_extractor(a__    ,  padding=a__    ,  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
              _UpperCAmelCase     =     feature_extractor(speech_inputs[0]    ,  return_tensors='np'     ).input_features
              _UpperCAmelCase     =     feature_extractor(np_speech_inputs[0]    ,  return_tensors='np'     ).input_features
              self.assertTrue(np.allclose(a__    ,  a__    ,  atol=1E-3     )     )

              # Test batched
              _UpperCAmelCase     =     feature_extractor(a__    ,  return_tensors='np'     ).input_features
              _UpperCAmelCase     =     feature_extractor(a__    ,  return_tensors='np'     ).input_features
              for enc_seq_a, enc_seq_a in zip(a__    ,  a__     ):
                     self.assertTrue(np.allclose(a__    ,  a__    ,  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(a__     )
              _UpperCAmelCase     =     feature_extractor(a__    ,  return_tensors='np'     ).input_features
              _UpperCAmelCase     =     feature_extractor(a__    ,  return_tensors='np'     ).input_features
              for enc_seq_a, enc_seq_a in zip(a__    ,  a__     ):
                     self.assertTrue(np.allclose(a__    ,  a__    ,  atol=1E-3     )     )






       def 							__A (   self     ):
              _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, None]
              for max_length, padding in zip(a__    ,  a__     ):
                     _UpperCAmelCase     =     feature_extractor(
                         a__    ,  padding=a__    ,  max_length=a__    ,  return_attention_mask=a__     )
                     _UpperCAmelCase     =     inputs.input_features
                     _UpperCAmelCase     =     inputs.attention_mask
                     _UpperCAmelCase     =     [np.sum(a__     ) 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 							__A (   self     ):
              _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, None]
              for max_length, padding in zip(a__    ,  a__     ):
                     _UpperCAmelCase     =     feature_extractor(
                         a__    ,  max_length=a__    ,  padding=a__    ,  return_tensors='np'    ,  return_attention_mask=a__     )
                     _UpperCAmelCase     =     inputs.input_features
                     _UpperCAmelCase     =     inputs.attention_mask
                     _UpperCAmelCase     =     [np.sum(a__     ) 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 							__A (   self     ):
              _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     =     feature_extractor(
                  a__    ,  padding='max_length'    ,  max_length=4    ,  truncation=a__    ,  return_tensors='np'    ,  return_attention_mask=a__    ,  )
              _UpperCAmelCase     =     inputs.input_features
              _UpperCAmelCase     =     inputs.attention_mask
              _UpperCAmelCase     =     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 							__A (   self     ):
              _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     =     feature_extractor(
                  a__    ,  padding='longest'    ,  max_length=4    ,  truncation=a__    ,  return_tensors='np'    ,  return_attention_mask=a__    ,  )
              _UpperCAmelCase     =     inputs.input_features
              _UpperCAmelCase     =     inputs.attention_mask
              _UpperCAmelCase     =     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)     )

              _UpperCAmelCase     =     [floats_list((1, x)     )[0] for x in range(8_00    ,  14_00    ,  2_00     )]
              _UpperCAmelCase     =     feature_extractor(
                  a__    ,  padding='longest'    ,  max_length=16    ,  truncation=a__    ,  return_tensors='np'    ,  return_attention_mask=a__    ,  )
              _UpperCAmelCase     =     inputs.input_features
              _UpperCAmelCase     =     inputs.attention_mask
              _UpperCAmelCase     =     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 							__A (   self     ):
              import torch

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

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






       def 							__A (   self    ,  a__     ):
              from datasets import load_dataset

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

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






       def 							__A (   self     ):
              _UpperCAmelCase     =     np.array([
                  -1.5_745, -1.7_713, -1.7_020, -1.6_069, -1.2_250, -1.1_105, -0.9_072, -0.8_241,
                  -1.2_310, -0.8_098, -0.3_320, -0.4_101, -0.7_985, -0.4_996, -0.8_213, -0.9_128,
                  -1.0_420, -1.1_286, -1.0_440, -0.7_999, -0.8_405, -1.2_275, -1.5_443, -1.4_625,
              ]     )
              # fmt: on

              _UpperCAmelCase     =     self._load_datasamples(1     )
              _UpperCAmelCase     =     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()     )
              _UpperCAmelCase     =     feature_extractor(a__    ,  return_tensors='pt'     ).input_features
              self.assertEquals(input_features.shape    ,  (1, 5_84, 24)     )
              self.assertTrue(np.allclose(input_features[0, 0, :30]    ,  a__    ,  atol=1E-4     )     )













"""simple docstring"""






import sys

lowerCAmelCase_			=							(
    '''73167176531330624919225119674426574742355349194934'''
    '''96983520312774506326239578318016984801869478851843'''
    '''85861560789112949495459501737958331952853208805511'''
    '''12540698747158523863050715693290963295227443043557'''
    '''66896648950445244523161731856403098711121722383113'''
    '''62229893423380308135336276614282806444486645238749'''
    '''30358907296290491560440772390713810515859307960866'''
    '''70172427121883998797908792274921901699720888093776'''
    '''65727333001053367881220235421809751254540594752243'''
    '''52584907711670556013604839586446706324415722155397'''
    '''53697817977846174064955149290862569321978468622482'''
    '''83972241375657056057490261407972968652414535100474'''
    '''82166370484403199890008895243450658541227588666881'''
    '''16427171479924442928230863465674813919123162824586'''
    '''17866458359124566529476545682848912883142607690042'''
    '''24219022671055626321111109370544217506941658960408'''
    '''07198403850962455444362981230987879927244284909188'''
    '''84580156166097919133875499200524063689912560717606'''
    '''05886116467109405077541002256983155200055935729725'''
    '''71636269561882670428252483600823257530420752963450'''
)

def       __lowerCamelCase    (       SCREAMING_SNAKE_CASE							)		->       int:






       """simple docstring"""




       _UpperCAmelCase     =     1
       for digit in s:
              product *= int(SCREAMING_SNAKE_CASE							)
       return product

def       __lowerCamelCase    (       SCREAMING_SNAKE_CASE = N							)		->       int:






       """simple docstring"""




       _UpperCAmelCase     =     -sys.maxsize - 1
       _UpperCAmelCase     =     n[:13]
       _UpperCAmelCase     =     13
       while cur_index < len(SCREAMING_SNAKE_CASE							) - 13:
              if int(n[cur_index]							) >= int(substr[0]							):
                     _UpperCAmelCase     =     substr[1:] + n[cur_index]
                     cur_index += 1
              else:
                     _UpperCAmelCase     =     max(SCREAMING_SNAKE_CASE,str_eval(SCREAMING_SNAKE_CASE							)							)
                     _UpperCAmelCase     =     n[cur_index : cur_index + 13]
                     cur_index += 13
       return largest_product


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






