


import itertools
import random
import unittest

import numpy as np

from transformers import ASTFeatureExtractor
from transformers.testing_utils import require_torch, require_torchaudio
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


lowerCAmelCase__    :List[Any]       =				random.Random()

if is_torch_available():
		import torch

def 			lowerCAmelCase__					(     a__:						int     ,    a__:						List[str]=1.0     ,    a__:						Tuple=None     ,    a__:						Tuple=None			)    ->						Dict:


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

class 						__a (							unittest.TestCase     ):
		def __init__(     self     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE=7     ,       _SCREAMING_SNAKE_CASE=400     ,       _SCREAMING_SNAKE_CASE=2000     ,       _SCREAMING_SNAKE_CASE=1     ,       _SCREAMING_SNAKE_CASE=0.0     ,       _SCREAMING_SNAKE_CASE=16000     ,       _SCREAMING_SNAKE_CASE=True     ,       _SCREAMING_SNAKE_CASE=True     ,       )					->			Union[str, Any]:




									"""simple docstring"""





									_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											=     padding_value
									_UpperCAmelCase											=     sampling_rate
									_UpperCAmelCase											=     return_attention_mask
									_UpperCAmelCase											=     do_normalize
		def       UpperCAmelCase__							(     self		)					->			Optional[Any]:




									"""simple docstring"""





									return {
									    "feature_size": self.feature_size,
									    "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     ,       _SCREAMING_SNAKE_CASE=False     ,       _SCREAMING_SNAKE_CASE=False		)					->			Optional[Any]:




									"""simple docstring"""





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

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

									return speech_inputs



@require_torch
@require_torchaudio
class 						__a (							UpperCAmelCase       , unittest.TestCase     ):
		_a      :    Dict           =      ASTFeatureExtractor
		def       UpperCAmelCase__							(     self		)					->			int:




									"""simple docstring"""





									_UpperCAmelCase											=     ASTFeatureExtractionTester(self		)
		def       UpperCAmelCase__							(     self		)					->			Union[str, Any]:




									"""simple docstring"""





									_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(800     ,       1400     ,       200		)]
									_UpperCAmelCase											=     [np.asarray(_SCREAMING_SNAKE_CASE		) for speech_input in speech_inputs]

									# Test not batched input
									_UpperCAmelCase											=     feat_extract(speech_inputs[0]     ,       return_tensors='np'		).input_values
									_UpperCAmelCase											=     feat_extract(np_speech_inputs[0]     ,       return_tensors='np'		).input_values
									self.assertTrue(np.allclose(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       atol=1e-3		)		)

									# Test batched
									_UpperCAmelCase											=     feat_extract(_SCREAMING_SNAKE_CASE     ,       padding=_SCREAMING_SNAKE_CASE     ,       return_tensors='np'		).input_values
									_UpperCAmelCase											=     feat_extract(_SCREAMING_SNAKE_CASE     ,       padding=_SCREAMING_SNAKE_CASE     ,       return_tensors='np'		).input_values
									for enc_seq_a, enc_seq_a in zip(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		):
																self.assertTrue(np.allclose(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       atol=1e-3		)		)

									# Test 2-D numpy arrays are batched.
									_UpperCAmelCase											=     [floats_list((1, x)		)[0] for x in (800, 800, 800)]
									_UpperCAmelCase											=     np.asarray(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     feat_extract(_SCREAMING_SNAKE_CASE     ,       return_tensors='np'		).input_values
									_UpperCAmelCase											=     feat_extract(_SCREAMING_SNAKE_CASE     ,       return_tensors='np'		).input_values
									for enc_seq_a, enc_seq_a in zip(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		):
																self.assertTrue(np.allclose(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       atol=1e-3		)		)
		@require_torch
		def       UpperCAmelCase__							(     self		)					->			int:




									"""simple docstring"""





									import torch

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

									for inputs in [py_speech_inputs, np_speech_inputs]:
																_UpperCAmelCase											=     feature_extractor.pad([{'input_values': inputs}]     ,       return_tensors='np'		)
																self.assertTrue(np_processed.input_values.dtype == np.floataa		)
																_UpperCAmelCase											=     feature_extractor.pad([{'input_values': inputs}]     ,       return_tensors='pt'		)
																self.assertTrue(pt_processed.input_values.dtype == torch.floataa		)
		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE		)					->			List[Any]:




									"""simple docstring"""





									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(_SCREAMING_SNAKE_CASE		)		)[:num_samples]['audio']

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






		@require_torch
		def       UpperCAmelCase__							(     self		)					->			Dict:




									"""simple docstring"""





									_UpperCAmelCase											=     torch.tensor(
									    [-0.9894, -1.2776, -0.9066, -1.2776, -0.9349, -1.2609, -1.0386, -1.2776,
									     -1.1561, -1.2776, -1.2052, -1.2723, -1.2190, -1.2132, -1.2776, -1.1133,
									     -1.1953, -1.1343, -1.1584, -1.2203, -1.1770, -1.2474, -1.2381, -1.1936,
									     -0.9270, -0.8317, -0.8049, -0.7706, -0.7565, -0.7869]		)
									# fmt: on

									_UpperCAmelCase											=     self._load_datasamples(1		)
									_UpperCAmelCase											=     ASTFeatureExtractor()
									_UpperCAmelCase											=     feature_extractor(_SCREAMING_SNAKE_CASE     ,       return_tensors='pt'		).input_values
									self.assertEquals(input_values.shape     ,       (1, 1024, 128)		)
									self.assertTrue(torch.allclose(input_values[0, 0, :30]     ,       _SCREAMING_SNAKE_CASE     ,       atol=1e-4		)		)




import math

import qiskit

def 			lowerCAmelCase__					(     a__:						int = 1     ,    a__:						int = 1     ,    a__:						int = 1			)    ->						qiskit.result.counts.Counts:


							'''simple docstring'''





							if (
							    isinstance(a__     ,    a__			)
							    or isinstance(a__     ,    a__			)
							    or isinstance(a__     ,    a__			)
							):
														raise TypeError('inputs must be integers.'			)

							if (input_a < 0) or (input_a < 0) or (carry_in < 0):
														raise ValueError('inputs must be positive.'			)

							if (
							    (math.floor(a__			) != input_a)
							    or (math.floor(a__			) != input_a)
							    or (math.floor(a__			) != carry_in)
							):
														raise ValueError('inputs must be exact integers.'			)

							if (input_a > 2) or (input_a > 2) or (carry_in > 2):
														raise ValueError('inputs must be less or equal to 2.'			)

							# build registers
							_UpperCAmelCase											=     qiskit.QuantumRegister(4     ,    'qr'			)
							_UpperCAmelCase											=     qiskit.ClassicalRegister(2     ,    'cr'			)
							# list the entries
							_UpperCAmelCase											=     [input_a, input_a, carry_in]

							_UpperCAmelCase											=     qiskit.QuantumCircuit(a__     ,    a__			)

							for i in range(0     ,    3			):
														if entry[i] == 2:
																					quantum_circuit.h(a__			)  # for hadamard entries
														elif entry[i] == 1:
																					quantum_circuit.x(a__			)  # for 1 entries
														elif entry[i] == 0:
																					quantum_circuit.i(a__			)  # for 0 entries

    # build the circuit
							quantum_circuit.ccx(0     ,    1     ,    3			)  # ccx = toffoli gate
							quantum_circuit.cx(0     ,    1			)
							quantum_circuit.ccx(1     ,    2     ,    3			)
							quantum_circuit.cx(1     ,    2			)
							quantum_circuit.cx(0     ,    1			)

							quantum_circuit.measure([2, 3]     ,    a__			)  # measure the last two qbits

							_UpperCAmelCase											=     qiskit.Aer.get_backend('aer_simulator'			)
							_UpperCAmelCase											=     qiskit.execute(a__     ,    a__     ,    shots=1_0_0_0			)

							return job.result().get_counts(a__			)


if __name__ == "__main__":
		print(f'''Total sum count for state is: {quantum_full_adder(1, 1, 1)}''')
