



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

a							   =				random.Random()







def a_     (    __UpperCAmelCase				,							__UpperCAmelCase=1.0				,							__UpperCAmelCase=None				,							__UpperCAmelCase=None					)				->					Optional[Any]:





			"""simple docstring"""







			if rng is None:
						snake_case:    int      							=global_rng

			snake_case:    str      							=[]
			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 						a_		(     unittest.TestCase    ):


							def __init__(				self   :						str      ,						a_   :						List[str]      ,						a_   :						Any=7      ,						a_   :						Dict=4_0_0      ,						a_   :						Dict=2_0_0_0      ,						a_   :						Optional[int]=2_4      ,						a_   :						Dict=2_4      ,						a_   :						str=0.0      ,						a_   :						Union[str, Any]=1_6_0_0_0      ,						a_   :						Dict=True      ,						a_   :						Optional[Any]=True      ,						)			->					Dict:
										snake_case:    Union[str, Any]      							=parent
										snake_case:    List[Any]      							=batch_size
										snake_case:    Union[str, Any]      							=min_seq_length
										snake_case:    List[Any]      							=max_seq_length
										snake_case:    Optional[int]      							=(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
										snake_case:    Any      							=feature_size
										snake_case:    str      							=num_mel_bins
										snake_case:    List[Any]      							=padding_value
										snake_case:    List[str]      							=sampling_rate
										snake_case:    str      							=return_attention_mask
										snake_case:    Tuple      							=do_normalize


							def    UpperCamelCase     (				self   :						Union[str, Any]			)			->					str:
										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    UpperCamelCase     (				self   :						List[str]      ,						a_   :						Tuple=False      ,						a_   :						str=False			)			->					Dict:
										def _flatten(a_   :						Any			):
													return list(itertools.chain(*a_			)			)

										if equal_length:
													snake_case:    List[Any]      							=[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:    Tuple      							=[
													    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:    int      							=[np.asarray(a_			) for x in speech_inputs]
										return speech_inputs






@require_torch
@require_torchaudio
class 						a_		(     snake_case    ,   unittest.TestCase    ):
							UpperCAmelCase			:		Optional[Any]        =				SpeechaTextFeatureExtractor if is_speech_available() else None


							def    UpperCamelCase     (				self   :						Any			)			->					str:
										snake_case:    Optional[Any]      							=SpeechaTextFeatureExtractionTester(self			)


							def    UpperCamelCase     (				self   :						Optional[Any]      ,						a_   :						Optional[int]			)			->					List[Any]:
										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    UpperCamelCase     (				self   :						Dict			)			->					Tuple:
										# Tests that all call wrap to encode_plus and batch_encode_plus
										snake_case:    List[Any]      							=self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
										# create three inputs of length 800, 1000, and 1200
										snake_case:    Any      							=[floats_list((1, x)			)[0] for x in range(8_0_0      ,						1_4_0_0      ,						2_0_0			)]
										snake_case:    List[Any]      							=[np.asarray(a_			) for speech_input in speech_inputs]

										# Test feature size
										snake_case:    str      							=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
										snake_case:    Any      							=feature_extractor(speech_inputs[0]      ,						return_tensors='np'			).input_features
										snake_case:    List[Any]      							=feature_extractor(np_speech_inputs[0]      ,						return_tensors='np'			).input_features
										self.assertTrue(np.allclose(a_      ,						a_      ,						atol=1E-3			)			)

										# Test batched
										snake_case:    Tuple      							=feature_extractor(a_      ,						return_tensors='np'			).input_features
										snake_case:    Dict      							=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.
										snake_case:    Optional[int]      							=[floats_list((1, x)			)[0] for x in (8_0_0, 8_0_0, 8_0_0)]
										snake_case:    Union[str, Any]      							=np.asarray(a_			)
										snake_case:    int      							=feature_extractor(a_      ,						return_tensors='np'			).input_features
										snake_case:    Optional[int]      							=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    UpperCamelCase     (				self   :						List[Any]			)			->					Optional[int]:
										snake_case:    str      							=self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
										snake_case:    Tuple      							=[floats_list((1, x)			)[0] for x in range(8_0_0      ,						1_4_0_0      ,						2_0_0			)]

										snake_case:    str      							=['longest', 'max_length', 'do_not_pad']
										snake_case:    Union[str, Any]      							=[None, 1_6, None]
										for max_length, padding in zip(a_      ,						a_			):
													snake_case:    Dict      							=feature_extractor(
													    a_      ,						padding=a_      ,						max_length=a_      ,						return_attention_mask=a_			)
													snake_case:    Any      							=inputs.input_features
													snake_case:    Optional[Any]      							=inputs.attention_mask
													snake_case:    Tuple      							=[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    UpperCamelCase     (				self   :						List[Any]			)			->					Optional[int]:
										snake_case:    Any      							=self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
										snake_case:    int      							=[floats_list((1, x)			)[0] for x in range(8_0_0      ,						1_4_0_0      ,						2_0_0			)]

										snake_case:    Any      							=['longest', 'max_length', 'do_not_pad']
										snake_case:    Union[str, Any]      							=[None, 1_6, None]
										for max_length, padding in zip(a_      ,						a_			):
													snake_case:    Optional[Any]      							=feature_extractor(
													    a_      ,						max_length=a_      ,						padding=a_      ,						return_tensors='np'      ,						return_attention_mask=a_			)
													snake_case:    Optional[int]      							=inputs.input_features
													snake_case:    List[Any]      							=inputs.attention_mask
													snake_case:    Dict      							=[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    UpperCamelCase     (				self   :						Optional[int]			)			->					Optional[Any]:
										snake_case:    Dict      							=self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
										snake_case:    List[str]      							=[floats_list((1, x)			)[0] for x in range(8_0_0      ,						1_4_0_0      ,						2_0_0			)]
										snake_case:    Union[str, Any]      							=feature_extractor(
										    a_      ,						padding='max_length'      ,						max_length=4      ,						truncation=a_      ,						return_tensors='np'      ,						return_attention_mask=a_      ,						)
										snake_case:    Optional[Any]      							=inputs.input_features
										snake_case:    Dict      							=inputs.attention_mask
										snake_case:    List[Any]      							=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    UpperCamelCase     (				self   :						List[Any]			)			->					Optional[int]:
										snake_case:    Optional[Any]      							=self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
										snake_case:    Optional[int]      							=[floats_list((1, x)			)[0] for x in range(8_0_0      ,						1_4_0_0      ,						2_0_0			)]
										snake_case:    str      							=feature_extractor(
										    a_      ,						padding='longest'      ,						max_length=4      ,						truncation=a_      ,						return_tensors='np'      ,						return_attention_mask=a_      ,						)
										snake_case:    Dict      							=inputs.input_features
										snake_case:    Optional[int]      							=inputs.attention_mask
										snake_case:    Tuple      							=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, 2_4)			)

										snake_case:    List[str]      							=[floats_list((1, x)			)[0] for x in range(8_0_0      ,						1_4_0_0      ,						2_0_0			)]
										snake_case:    Optional[Any]      							=feature_extractor(
										    a_      ,						padding='longest'      ,						max_length=1_6      ,						truncation=a_      ,						return_tensors='np'      ,						return_attention_mask=a_      ,						)
										snake_case:    Tuple      							=inputs.input_features
										snake_case:    Any      							=inputs.attention_mask
										snake_case:    Union[str, Any]      							=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, 2_4)			)


							def    UpperCamelCase     (				self   :						Dict			)			->					Optional[int]:
										import torch

										snake_case:    int      							=self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
										snake_case:    Tuple      							=np.random.rand(1_0_0      ,						3_2			).astype(np.floataa			)
										snake_case:    Union[str, Any]      							=np_speech_inputs.tolist()

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


							def    UpperCamelCase     (				self   :						Union[str, Any]      ,						a_   :						str			)			->					List[Any]:
										from datasets import load_dataset

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

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




							def    UpperCamelCase     (				self   :						List[Any]			)			->					List[str]:
										# fmt: off
										snake_case:    Any      							=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:    Union[str, Any]      							=self._load_datasamples(1			)
										snake_case:    Any      							=self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
										snake_case:    Optional[Any]      							=feature_extractor(a_      ,						return_tensors='pt'			).input_features
										self.assertEquals(input_features.shape      ,						(1, 5_8_4, 2_4)			)
										self.assertTrue(np.allclose(input_features[0, 0, :3_0]      ,						a_      ,						atol=1E-4			)			)









'''simple docstring'''

from __future__ import annotations







def a_     (    __UpperCAmelCase					)				->					list[int]:





			"""simple docstring"""







			snake_case:    Tuple      							=[True] * limit
			snake_case:    Optional[int]      							=False
			snake_case:    Union[str, Any]      							=False
			snake_case:    List[Any]      							=True

			for i in range(3				,							int(limit**0.5 + 1					)				,							2					):
						snake_case:    str      							=i * 2
						while index < limit:
									snake_case:    List[Any]      							=False
									snake_case:    List[str]      							=index + i

			snake_case:    Union[str, Any]      							=[2]

			for i in range(3				,							__UpperCAmelCase				,							2					):
						if is_prime[i]:
									primes.append(__UpperCAmelCase					)

			return primes







def a_     (    __UpperCAmelCase = 1_00_00_00					)				->					int:





			"""simple docstring"""







			snake_case:    str      							=prime_sieve(__UpperCAmelCase					)
			snake_case:    str      							=0
			snake_case:    str      							=0

			for i in range(len(__UpperCAmelCase					)					):
						for j in range(i + length				,							len(__UpperCAmelCase					)					):
									snake_case:    Tuple      							=sum(primes[i:j]					)
									if sol >= ceiling:
												break

									if sol in primes:
												snake_case:    List[str]      							=j - i
												snake_case:    Optional[int]      							=sol

			return largest


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




