


'''simple docstring'''






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


__UpperCAmelCase					       =							random.Random()

if is_torch_available():
		import torch


def       _snake_case     (  A				,					A=1.0				,					A=None				,					A=None )		->					Tuple:
							if rng is None:
														lowerCAmelCase__      =			global_rng

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





							'''simple docstring'''






							def __init__(	self      ,					lowerCamelCase_      ,					lowerCamelCase_=7      ,					lowerCamelCase_=4_00      ,					lowerCamelCase_=20_00      ,					lowerCamelCase_=1      ,					lowerCamelCase_=0.0      ,					lowerCamelCase_=1_60_00      ,					lowerCamelCase_=True      ,					lowerCamelCase_=True      ,					) ->							Optional[Any]:
														lowerCAmelCase__      =			parent
														lowerCAmelCase__      =			batch_size
														lowerCAmelCase__      =			min_seq_length
														lowerCAmelCase__      =			max_seq_length
														lowerCAmelCase__      =			(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
														lowerCAmelCase__      =			feature_size
														lowerCAmelCase__      =			padding_value
														lowerCAmelCase__      =			sampling_rate
														lowerCAmelCase__      =			return_attention_mask
														lowerCAmelCase__      =			do_normalize







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							int:
														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 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_=False      ,					lowerCamelCase_=False     ) ->							Optional[Any]:
														def _flatten(lowerCamelCase_     ):
																					return list(itertools.chain(*lowerCamelCase_     )     )

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

														return speech_inputs




@require_torch
@require_torchaudio
class 	a__       (							a__       ,       unittest.TestCase						):





							'''simple docstring'''






							lowercase__    :     Optional[int]					=   ASTFeatureExtractor







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Optional[int]:
														lowerCAmelCase__      =			ASTFeatureExtractionTester(self     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							str:
														# Tests that all call wrap to encode_plus and batch_encode_plus
														lowerCAmelCase__      =			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()     )
														# create three inputs of length 800, 1000, and 1200
														lowerCAmelCase__      =			[floats_list((1, x)     )[0] for x in range(8_00      ,					14_00      ,					2_00     )]
														lowerCAmelCase__      =			[np.asarray(lowerCamelCase_     ) for speech_input in speech_inputs]

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

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

														# Test 2-D numpy arrays are batched.
														lowerCAmelCase__      =			[floats_list((1, x)     )[0] for x in (8_00, 8_00, 8_00)]
														lowerCAmelCase__      =			np.asarray(lowerCamelCase_     )
														lowerCAmelCase__      =			feat_extract(lowerCamelCase_      ,					return_tensors='''np'''     ).input_values
														lowerCAmelCase__      =			feat_extract(lowerCamelCase_      ,					return_tensors='''np'''     ).input_values
														for enc_seq_a, enc_seq_a in zip(lowerCamelCase_      ,					lowerCamelCase_     ):
																					self.assertTrue(np.allclose(lowerCamelCase_      ,					lowerCamelCase_      ,					atol=1e-3     )     )







							@require_torch
							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							List[str]:
														import torch

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

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







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_     ) ->							List[Any]:
														from datasets import load_dataset

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

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







							@require_torch
							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Any:
														# fmt: off
														lowerCAmelCase__      =			torch.tensor(
														    [-0.9_894, -1.2_776, -0.9_066, -1.2_776, -0.9_349, -1.2_609, -1.0_386, -1.2_776,
														     -1.1_561, -1.2_776, -1.2_052, -1.2_723, -1.2_190, -1.2_132, -1.2_776, -1.1_133,
														     -1.1_953, -1.1_343, -1.1_584, -1.2_203, -1.1_770, -1.2_474, -1.2_381, -1.1_936,
														     -0.9_270, -0.8_317, -0.8_049, -0.7_706, -0.7_565, -0.7_869]     )
														# fmt: on

														lowerCAmelCase__      =			self._load_datasamples(1     )
														lowerCAmelCase__      =			ASTFeatureExtractor()
														lowerCAmelCase__      =			feature_extractor(lowerCamelCase_      ,					return_tensors='''pt'''     ).input_values
														self.assertEquals(input_values.shape      ,					(1, 10_24, 1_28)     )
														self.assertTrue(torch.allclose(input_values[0, 0, :30]      ,					lowerCamelCase_      ,					atol=1e-4     )     )



'''simple docstring'''






from manim import *




class 	a__       (							a__						):





							'''simple docstring'''






							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							List[str]:
														lowerCAmelCase__      =			Rectangle(height=0.5      ,					width=0.5     )
														lowerCAmelCase__      =			Rectangle(height=0.46      ,					width=0.46     ).set_stroke(width=0     )

														lowerCAmelCase__      =			[mem.copy() for i in range(6     )]
														lowerCAmelCase__      =			[mem.copy() for i in range(6     )]
														lowerCAmelCase__      =			VGroup(*lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0     )
														lowerCAmelCase__      =			VGroup(*lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0     )
														lowerCAmelCase__      =			VGroup(lowerCamelCase_      ,					lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0     )
														lowerCAmelCase__      =			Text('''CPU'''      ,					font_size=24     )
														lowerCAmelCase__      =			Group(lowerCamelCase_      ,					lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0.5      ,					aligned_edge=lowerCamelCase_     )
														cpu.move_to([-2.5, -0.5, 0]     )
														self.add(lowerCamelCase_     )

														lowerCAmelCase__      =			[mem.copy() for i in range(1     )]
														lowerCAmelCase__      =			VGroup(*lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0     )
														lowerCAmelCase__      =			Text('''GPU'''      ,					font_size=24     )
														lowerCAmelCase__      =			Group(lowerCamelCase_      ,					lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0.5      ,					aligned_edge=lowerCamelCase_     )
														gpu.align_to(lowerCamelCase_      ,					lowerCamelCase_     )
														gpu.set_x(gpu.get_x() - 1     )

														self.add(lowerCamelCase_     )

														lowerCAmelCase__      =			[mem.copy() for i in range(6     )]
														lowerCAmelCase__      =			VGroup(*lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0     )

														lowerCAmelCase__      =			Text('''Model'''      ,					font_size=24     )
														lowerCAmelCase__      =			Group(lowerCamelCase_      ,					lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0.5      ,					aligned_edge=lowerCamelCase_     )
														model.move_to([3, -1.0, 0]     )

														self.play(
														    Create(lowerCamelCase_      ,					run_time=1     )      ,					Create(lowerCamelCase_      ,					run_time=1     )      ,					Create(lowerCamelCase_      ,					run_time=1     )      ,					)

														lowerCAmelCase__      =			MarkupText(
														    F"""First, an empty model skeleton is loaded\ninto <span fgcolor='{YELLOW}'>memory</span> without using much RAM."""      ,					font_size=24      ,					)

														lowerCAmelCase__      =			Square(side_length=2.2     )
														key.move_to([-5, 2, 0]     )

														lowerCAmelCase__      =			MarkupText(
														    F"""<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model"""      ,					font_size=18      ,					)

														key_text.move_to([-5, 2.4, 0]     )

														step_a.move_to([2, 2, 0]     )
														self.play(Write(lowerCamelCase_      ,					run_time=2.5     )      ,					Write(lowerCamelCase_     )      ,					Write(lowerCamelCase_     )     )

														self.add(lowerCamelCase_     )

														lowerCAmelCase__      =			[]
														lowerCAmelCase__      =			[]
														lowerCAmelCase__      =			[]
														for i, rect in enumerate(lowerCamelCase_     ):
																					lowerCAmelCase__      =			Rectangle(height=0.46      ,					width=0.46     ).set_stroke(width=0.0     ).set_fill(lowerCamelCase_      ,					opacity=0.7     )
																					cpu_target.move_to(lowerCamelCase_     )
																					cpu_target.generate_target()
																					lowerCAmelCase__      =			0.46 / 4
																					lowerCAmelCase__      =			0.46 / 3

																					if i == 0:
																												cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT     )      ,					buff=0.02      ,					direction=lowerCamelCase_     )
																												cpu_target.target.set_x(cpu_target.target.get_x() + 0.1     )
																					elif i == 3:
																												cpu_target.target.next_to(cpu_targs[0].target      ,					direction=lowerCamelCase_      ,					buff=0.0     )
																					else:
																												cpu_target.target.next_to(cpu_targs[i - 1].target      ,					direction=lowerCamelCase_      ,					buff=0.0     )
																					cpu_targs.append(lowerCamelCase_     )

																					first_animations.append(rect.animate(run_time=0.5     ).set_stroke(lowerCamelCase_     )     )
																					second_animations.append(MoveToTarget(lowerCamelCase_      ,					run_time=1.5     )     )

														self.play(*lowerCamelCase_     )
														self.play(*lowerCamelCase_     )

														self.wait()