



'''simple docstring'''

import random







def a_     (    __UpperCAmelCase					)				->					bool:





			"""simple docstring"""







			snake_case:    Dict      							=num - 1
			snake_case:    Any      							=0

			while s % 2 == 0:
						snake_case:    Any      							=s // 2
						t += 1

			for _ in range(5					):
						snake_case:    Any      							=random.randrange(2				,							num - 1					)
						snake_case:    Dict      							=pow(__UpperCAmelCase				,							__UpperCAmelCase				,							__UpperCAmelCase					)
						if v != 1:
									snake_case:    Dict      							=0
									while v != (num - 1):
												if i == t - 1:
															return False
												else:
															snake_case:    Any      							=i + 1
															snake_case:    Union[str, Any]      							=(v**2) % num
			return True







def a_     (    __UpperCAmelCase					)				->					bool:





			"""simple docstring"""







			if num < 2:
						return False

			snake_case:    Union[str, Any]      							=[
			    2,
			    3,
			    5,
			    7,
			    11,
			    13,
			    17,
			    19,
			    23,
			    29,
			    31,
			    37,
			    41,
			    43,
			    47,
			    53,
			    59,
			    61,
			    67,
			    71,
			    73,
			    79,
			    83,
			    89,
			    97,
			    1_01,
			    1_03,
			    1_07,
			    1_09,
			    1_13,
			    1_27,
			    1_31,
			    1_37,
			    1_39,
			    1_49,
			    1_51,
			    1_57,
			    1_63,
			    1_67,
			    1_73,
			    1_79,
			    1_81,
			    1_91,
			    1_93,
			    1_97,
			    1_99,
			    2_11,
			    2_23,
			    2_27,
			    2_29,
			    2_33,
			    2_39,
			    2_41,
			    2_51,
			    2_57,
			    2_63,
			    2_69,
			    2_71,
			    2_77,
			    2_81,
			    2_83,
			    2_93,
			    3_07,
			    3_11,
			    3_13,
			    3_17,
			    3_31,
			    3_37,
			    3_47,
			    3_49,
			    3_53,
			    3_59,
			    3_67,
			    3_73,
			    3_79,
			    3_83,
			    3_89,
			    3_97,
			    4_01,
			    4_09,
			    4_19,
			    4_21,
			    4_31,
			    4_33,
			    4_39,
			    4_43,
			    4_49,
			    4_57,
			    4_61,
			    4_63,
			    4_67,
			    4_79,
			    4_87,
			    4_91,
			    4_99,
			    5_03,
			    5_09,
			    5_21,
			    5_23,
			    5_41,
			    5_47,
			    5_57,
			    5_63,
			    5_69,
			    5_71,
			    5_77,
			    5_87,
			    5_93,
			    5_99,
			    6_01,
			    6_07,
			    6_13,
			    6_17,
			    6_19,
			    6_31,
			    6_41,
			    6_43,
			    6_47,
			    6_53,
			    6_59,
			    6_61,
			    6_73,
			    6_77,
			    6_83,
			    6_91,
			    7_01,
			    7_09,
			    7_19,
			    7_27,
			    7_33,
			    7_39,
			    7_43,
			    7_51,
			    7_57,
			    7_61,
			    7_69,
			    7_73,
			    7_87,
			    7_97,
			    8_09,
			    8_11,
			    8_21,
			    8_23,
			    8_27,
			    8_29,
			    8_39,
			    8_53,
			    8_57,
			    8_59,
			    8_63,
			    8_77,
			    8_81,
			    8_83,
			    8_87,
			    9_07,
			    9_11,
			    9_19,
			    9_29,
			    9_37,
			    9_41,
			    9_47,
			    9_53,
			    9_67,
			    9_71,
			    9_77,
			    9_83,
			    9_91,
			    9_97,
			]

			if num in low_primes:
						return True

			for prime in low_primes:
						if (num % prime) == 0:
									return False

			return rabin_miller(__UpperCAmelCase					)







def a_     (    __UpperCAmelCase = 10_24					)				->					int:





			"""simple docstring"""







			while True:
						snake_case:    Union[str, Any]      							=random.randrange(2 ** (keysize - 1)				,							2 ** (keysize)					)
						if is_prime_low_num(__UpperCAmelCase					):
									return num


if __name__ == "__main__":
	a							   =				generate_large_prime()
	print(('Prime number:', num))
	print(('is_prime_low_num:', is_prime_low_num(num)))









'''simple docstring'''

import itertools
import os
import random
import tempfile
import unittest

import numpy as np

from transformers import TvltFeatureExtractor, is_datasets_available
from transformers.testing_utils import check_json_file_has_correct_format, require_torch, require_torchaudio
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
	import torch

if is_datasets_available():
	from datasets import load_dataset

a							   =				random.Random()







def a_     (    __UpperCAmelCase				,							__UpperCAmelCase=1.0				,							__UpperCAmelCase=None				,							__UpperCAmelCase=None					)				->					List[str]:





			"""simple docstring"""







			if rng is None:
						snake_case:    Dict      							=global_rng

			snake_case:    Tuple      							=[]
			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    ):


							def __init__(				self   :						int      ,						a_   :						Any      ,						a_   :						str=7      ,						a_   :						Tuple=4_0_0      ,						a_   :						List[Any]=2_0_0_0      ,						a_   :						str=2_0_4_8      ,						a_   :						List[str]=1_2_8      ,						a_   :						int=1      ,						a_   :						Tuple=5_1_2      ,						a_   :						Dict=3_0      ,						a_   :						Optional[int]=4_4_1_0_0      ,						)			->					Union[str, Any]:
										snake_case:    Union[str, Any]      							=parent
										snake_case:    Optional[Any]      							=batch_size
										snake_case:    Union[str, Any]      							=min_seq_length
										snake_case:    List[str]      							=max_seq_length
										snake_case:    str      							=(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
										snake_case:    int      							=spectrogram_length
										snake_case:    List[str]      							=feature_size
										snake_case:    Dict      							=num_audio_channels
										snake_case:    int      							=hop_length
										snake_case:    List[Any]      							=chunk_length
										snake_case:    Optional[Any]      							=sampling_rate


							def    UpperCamelCase     (				self   :						Any			)			->					Dict:
										return {
										    "spectrogram_length": self.spectrogram_length,
										    "feature_size": self.feature_size,
										    "num_audio_channels": self.num_audio_channels,
										    "hop_length": self.hop_length,
										    "chunk_length": self.chunk_length,
										    "sampling_rate": self.sampling_rate,
										}




							def    UpperCamelCase     (				self   :						Tuple      ,						a_   :						Optional[Any]=False      ,						a_   :						Tuple=False			)			->					Optional[int]:
										def _flatten(a_   :						Dict			):
													return list(itertools.chain(*a_			)			)

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






@require_torch
@require_torchaudio
class 						a_		(     snake_case    ,   unittest.TestCase    ):
							UpperCAmelCase			:		Optional[Any]        =				TvltFeatureExtractor


							def    UpperCamelCase     (				self   :						int			)			->					int:
										snake_case:    Union[str, Any]      							=TvltFeatureExtractionTester(self			)


							def    UpperCamelCase     (				self   :						Optional[Any]			)			->					str:
										snake_case:    int      							=self.feature_extraction_class(**self.feat_extract_dict			)
										self.assertTrue(hasattr(a_      ,						'spectrogram_length'			)			)
										self.assertTrue(hasattr(a_      ,						'feature_size'			)			)
										self.assertTrue(hasattr(a_      ,						'num_audio_channels'			)			)
										self.assertTrue(hasattr(a_      ,						'hop_length'			)			)
										self.assertTrue(hasattr(a_      ,						'chunk_length'			)			)
										self.assertTrue(hasattr(a_      ,						'sampling_rate'			)			)


							def    UpperCamelCase     (				self   :						Tuple			)			->					Optional[int]:
										snake_case:    Tuple      							=self.feature_extraction_class(**self.feat_extract_dict			)

										with tempfile.TemporaryDirectory() as tmpdirname:
													snake_case:    Optional[Any]      							=feat_extract_first.save_pretrained(a_			)[0]
													check_json_file_has_correct_format(a_			)
													snake_case:    str      							=self.feature_extraction_class.from_pretrained(a_			)

										snake_case:    Optional[int]      							=feat_extract_first.to_dict()
										snake_case:    List[str]      							=feat_extract_second.to_dict()
										snake_case:    Optional[int]      							=dict_first.pop('mel_filters'			)
										snake_case:    List[Any]      							=dict_second.pop('mel_filters'			)
										self.assertTrue(np.allclose(a_      ,						a_			)			)
										self.assertEqual(a_      ,						a_			)


							def    UpperCamelCase     (				self   :						str			)			->					str:
										snake_case:    Any      							=self.feature_extraction_class(**self.feat_extract_dict			)

										with tempfile.TemporaryDirectory() as tmpdirname:
													snake_case:    int      							=os.path.join(a_      ,						'feat_extract.json'			)
													feat_extract_first.to_json_file(a_			)
													snake_case:    Union[str, Any]      							=self.feature_extraction_class.from_json_file(a_			)

										snake_case:    Optional[Any]      							=feat_extract_first.to_dict()
										snake_case:    Optional[Any]      							=feat_extract_second.to_dict()
										snake_case:    Union[str, Any]      							=dict_first.pop('mel_filters'			)
										snake_case:    Union[str, Any]      							=dict_second.pop('mel_filters'			)
										self.assertTrue(np.allclose(a_      ,						a_			)			)
										self.assertEqual(a_      ,						a_			)


							def    UpperCamelCase     (				self   :						Union[str, Any]			)			->					List[str]:
										# Initialize feature_extractor
										snake_case:    Tuple      							=self.feature_extraction_class(**self.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:    Optional[Any]      							=[np.asarray(a_			) for speech_input in speech_inputs]

										# Test not batched input
										snake_case:    List[Any]      							=feature_extractor(np_speech_inputs[0]      ,						return_tensors='np'      ,						sampling_rate=4_4_1_0_0			).audio_values

										self.assertTrue(encoded_audios.ndim == 4			)
										self.assertTrue(encoded_audios.shape[-1] == feature_extractor.feature_size			)
										self.assertTrue(encoded_audios.shape[-2] <= feature_extractor.spectrogram_length			)
										self.assertTrue(encoded_audios.shape[-3] == feature_extractor.num_channels			)

										# Test batched
										snake_case:    Any      							=feature_extractor(a_      ,						return_tensors='np'      ,						sampling_rate=4_4_1_0_0			).audio_values

										self.assertTrue(encoded_audios.ndim == 4			)
										self.assertTrue(encoded_audios.shape[-1] == feature_extractor.feature_size			)
										self.assertTrue(encoded_audios.shape[-2] <= feature_extractor.spectrogram_length			)
										self.assertTrue(encoded_audios.shape[-3] == feature_extractor.num_channels			)

										# Test audio masking
										snake_case:    Optional[Any]      							=feature_extractor(
										    a_      ,						return_tensors='np'      ,						sampling_rate=4_4_1_0_0      ,						mask_audio=a_			).audio_values

										self.assertTrue(encoded_audios.ndim == 4			)
										self.assertTrue(encoded_audios.shape[-1] == feature_extractor.feature_size			)
										self.assertTrue(encoded_audios.shape[-2] <= feature_extractor.spectrogram_length			)
										self.assertTrue(encoded_audios.shape[-3] == feature_extractor.num_channels			)

										# Test 2-D numpy arrays are batched.
										snake_case:    List[Any]      							=[floats_list((1, x)			)[0] for x in (8_0_0, 8_0_0, 8_0_0)]
										snake_case:    List[str]      							=np.asarray(a_			)
										snake_case:    str      							=feature_extractor(a_      ,						return_tensors='np'      ,						sampling_rate=4_4_1_0_0			).audio_values
										self.assertTrue(encoded_audios.ndim == 4			)
										self.assertTrue(encoded_audios.shape[-1] == feature_extractor.feature_size			)
										self.assertTrue(encoded_audios.shape[-2] <= feature_extractor.spectrogram_length			)
										self.assertTrue(encoded_audios.shape[-3] == feature_extractor.num_channels			)


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

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




							def    UpperCamelCase     (				self   :						Optional[Any]			)			->					Optional[int]:
										snake_case:    Tuple      							=self._load_datasamples(1			)
										snake_case:    Any      							=TvltFeatureExtractor()
										snake_case:    Any      							=feature_extractor(a_      ,						return_tensors='pt'			).audio_values

										self.assertEquals(audio_values.shape      ,						(1, 1, 1_9_2, 1_2_8)			)

										snake_case:    int      							=torch.tensor([[-0.3_0_3_2, -0.2_7_0_8], [-0.4_4_3_4, -0.4_0_0_7]]			)
										self.assertTrue(torch.allclose(audio_values[0, 0, :2, :2]      ,						a_      ,						atol=1E-4			)			)




