


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 			_a (      SCREAMING_SNAKE_CASE						,				SCREAMING_SNAKE_CASE=1.0						,				SCREAMING_SNAKE_CASE=None						,				SCREAMING_SNAKE_CASE=None     ):


		"""simple docstring"""




		if rng is None:
				lowercase__            =      global_rng

		lowercase__            =      []
		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:	Any    ,						UpperCamelCase_:	int    ,						UpperCamelCase_:	Dict=7    ,						UpperCamelCase_:	List[Any]=400    ,						UpperCamelCase_:	Dict=2_000    ,						UpperCamelCase_:	Dict=24    ,						UpperCamelCase_:	Union[str, Any]=24    ,						UpperCamelCase_:	List[str]=0.0    ,						UpperCamelCase_:	Dict=16_000    ,						UpperCamelCase_:	int=True    ,						UpperCamelCase_:	Union[str, Any]=True    ,						)			->   Dict:





									"""simple docstring"""







									lowercase__            =      parent
									lowercase__            =      batch_size
									lowercase__            =      min_seq_length
									lowercase__            =      max_seq_length
									lowercase__            =      (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
									lowercase__            =      feature_size
									lowercase__            =      num_mel_bins
									lowercase__            =      padding_value
									lowercase__            =      sampling_rate
									lowercase__            =      return_attention_mask
									lowercase__            =      do_normalize

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





									"""simple docstring"""







									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       lowerCamelCase_ (							self:	Optional[int]    ,						UpperCamelCase_:	Union[str, Any]=False    ,						UpperCamelCase_:	List[Any]=False							)			->   Optional[int]:





									"""simple docstring"""







									def _flatten(UpperCamelCase_:	List[Any]							):
											return list(itertools.chain(*_a							)							)

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


@require_torch
@require_torchaudio
class        _a							(			UpperCAmelCase__     ,	unittest.TestCase			):
							_lowercase	:			str        = SpeechaTextFeatureExtractor if is_speech_available() else None

							def       lowerCamelCase_ (							self:	int							)			->   Tuple:





									"""simple docstring"""







									lowercase__            =      SpeechaTextFeatureExtractionTester(self							)

							def       lowerCamelCase_ (							self:	str    ,						UpperCamelCase_:	Dict							)			->   Any:





									"""simple docstring"""







									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       lowerCamelCase_ (							self:	List[Any]							)			->   Union[str, Any]:





									"""simple docstring"""







									lowercase__            =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
									# create three inputs of length 800, 1000, and 1200
									lowercase__            =      [floats_list((1, x)							)[0] for x in range(800    ,						1_400    ,						200							)]
									lowercase__            =      [np.asarray(_a							) for speech_input in speech_inputs]

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

									# Test batched
									lowercase__            =      feature_extractor(_a    ,						return_tensors='''np'''							).input_features
									lowercase__            =      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.
									lowercase__            =      [floats_list((1, x)							)[0] for x in (800, 800, 800)]
									lowercase__            =      np.asarray(_a							)
									lowercase__            =      feature_extractor(_a    ,						return_tensors='''np'''							).input_features
									lowercase__            =      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       lowerCamelCase_ (							self:	Dict							)			->   Optional[int]:





									"""simple docstring"""







									lowercase__            =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
									lowercase__            =      [floats_list((1, x)							)[0] for x in range(800    ,						1_400    ,						200							)]

									lowercase__            =      ['''longest''', '''max_length''', '''do_not_pad''']
									lowercase__            =      [None, 16, None]
									for max_length, padding in zip(_a    ,						_a							):
											lowercase__            =      feature_extractor(
											    _a    ,						padding=_a    ,						max_length=_a    ,						return_attention_mask=_a							)
											lowercase__            =      inputs.input_features
											lowercase__            =      inputs.attention_mask
											lowercase__            =      [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       lowerCamelCase_ (							self:	Union[str, Any]							)			->   Tuple:





									"""simple docstring"""







									lowercase__            =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
									lowercase__            =      [floats_list((1, x)							)[0] for x in range(800    ,						1_400    ,						200							)]

									lowercase__            =      ['''longest''', '''max_length''', '''do_not_pad''']
									lowercase__            =      [None, 16, None]
									for max_length, padding in zip(_a    ,						_a							):
											lowercase__            =      feature_extractor(
											    _a    ,						max_length=_a    ,						padding=_a    ,						return_tensors='''np'''    ,						return_attention_mask=_a							)
											lowercase__            =      inputs.input_features
											lowercase__            =      inputs.attention_mask
											lowercase__            =      [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       lowerCamelCase_ (							self:	int							)			->   Optional[int]:





									"""simple docstring"""







									lowercase__            =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
									lowercase__            =      [floats_list((1, x)							)[0] for x in range(800    ,						1_400    ,						200							)]
									lowercase__            =      feature_extractor(
									    _a    ,						padding='''max_length'''    ,						max_length=4    ,						truncation=_a    ,						return_tensors='''np'''    ,						return_attention_mask=_a    ,						)
									lowercase__            =      inputs.input_features
									lowercase__            =      inputs.attention_mask
									lowercase__            =      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       lowerCamelCase_ (							self:	Tuple							)			->   str:





									"""simple docstring"""







									lowercase__            =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
									lowercase__            =      [floats_list((1, x)							)[0] for x in range(800    ,						1_400    ,						200							)]
									lowercase__            =      feature_extractor(
									    _a    ,						padding='''longest'''    ,						max_length=4    ,						truncation=_a    ,						return_tensors='''np'''    ,						return_attention_mask=_a    ,						)
									lowercase__            =      inputs.input_features
									lowercase__            =      inputs.attention_mask
									lowercase__            =      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)							)

									lowercase__            =      [floats_list((1, x)							)[0] for x in range(800    ,						1_400    ,						200							)]
									lowercase__            =      feature_extractor(
									    _a    ,						padding='''longest'''    ,						max_length=16    ,						truncation=_a    ,						return_tensors='''np'''    ,						return_attention_mask=_a    ,						)
									lowercase__            =      inputs.input_features
									lowercase__            =      inputs.attention_mask
									lowercase__            =      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       lowerCamelCase_ (							self:	List[str]							)			->   Optional[Any]:





									"""simple docstring"""







									import torch

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

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

							def       lowerCamelCase_ (							self:	Optional[int]    ,						UpperCamelCase_:	Dict							)			->   Union[str, Any]:





									"""simple docstring"""







									from datasets import load_dataset

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

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


							def       lowerCamelCase_ (							self:	List[Any]							)			->   int:





									"""simple docstring"""







									lowercase__            =      np.array([
									    -1.5745, -1.7713, -1.7020, -1.6069, -1.2250, -1.1105, -0.9072, -0.8241,
									    -1.2310, -0.8098, -0.3320, -0.4101, -0.7985, -0.4996, -0.8213, -0.9128,
									    -1.0420, -1.1286, -1.0440, -0.7999, -0.8405, -1.2275, -1.5443, -1.4625,
									]							)
									# fmt: on

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








"""simple docstring"""




from __future__ import annotations



def     a__ (				snake_case__       , snake_case__				)						->					bool:
			if len(snake_case__				) == 0:
						return False
			lowerCamelCase			      =					len(snake_case__				) // 2
			if a_list[midpoint] == item:
						return True
			if item < a_list[midpoint]:
						return binary_search(a_list[:midpoint]       , snake_case__				)
			else:
						return binary_search(a_list[midpoint + 1 :]       , snake_case__				)


if __name__ == "__main__":
					lowerCAmelCase							:			List[Any]     							=							input("""Enter numbers separated by comma:\n""").strip()
					lowerCAmelCase							:			Optional[Any]     							=							[int(item.strip()) for item in user_input.split(""",""")]
					lowerCAmelCase							:			Optional[int]     							=							int(input("""Enter the number to be found in the list:\n""").strip())
					lowerCAmelCase							:			Union[str, Any]     							=							"""""" if binary_search(sequence, target) else """not """
					print(F"""{target} was {not_str}found in {sequence}""")



