


"""simple docstring"""




import itertools
import random
import unittest

import numpy as np

from transformers import WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST, WavaVecaConfig, WavaVecaFeatureExtractor
from transformers.testing_utils import require_torch, slow

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


__magic_name__						: Optional[int]    =				random.Random()





def       a_ (	lowercase__ :int,			lowercase__ :Tuple=1.0,			lowercase__ :Tuple=None,			lowercase__ :Optional[Any]=None     ):
			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 			__snake_case   (unittest.TestCase  ):




							def __init__(     self:    Optional[int]     ,							A_:    List[Any]     ,							A_:    Any=7     ,							A_:    Optional[Any]=4_00     ,							A_:    Union[str, Any]=20_00     ,							A_:    List[Any]=1     ,							A_:    Tuple=0.0     ,							A_:    str=1_60_00     ,							A_:    Any=True     ,							A_:    Tuple=True     ,							):
										__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   __a   (     self:    Any   ):
										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   __a   (     self:    Optional[int]     ,							A_:    Union[str, Any]=False     ,							A_:    Tuple=False   ):
										def _flatten(A_:    str   ):
													return list(itertools.chain(*A_   )   )

										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(A_   ) for x in speech_inputs]

										return speech_inputs




class 			__snake_case   (lowerCamelCase			,		unittest.TestCase  ):
							__a					 =       WavaVecaFeatureExtractor




							def   __a   (     self:    Tuple   ):
										__lowerCamelCase          =      WavaVecaFeatureExtractionTester(self   )




							def   __a   (     self:    Optional[Any]     ,							A_:    Optional[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   __a   (     self:    Union[str, Any]   ):
										# 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(A_   ) 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(A_     ,							A_     ,							atol=1E-3   )   )

										# Test batched
										__lowerCamelCase          =      feat_extract(A_     ,							return_tensors="""np"""   ).input_values
										__lowerCamelCase          =      feat_extract(A_     ,							return_tensors="""np"""   ).input_values
										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.
										__lowerCamelCase          =      [floats_list((1, x)   )[0] for x in (8_00, 8_00, 8_00)]
										__lowerCamelCase          =      np.asarray(A_   )
										__lowerCamelCase          =      feat_extract(A_     ,							return_tensors="""np"""   ).input_values
										__lowerCamelCase          =      feat_extract(A_     ,							return_tensors="""np"""   ).input_values
										for enc_seq_a, enc_seq_a in zip(A_     ,							A_   ):
													self.assertTrue(np.allclose(A_     ,							A_     ,							atol=1E-3   )   )




							def   __a   (     self:    Optional[int]   ):
										__lowerCamelCase          =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
										__lowerCamelCase          =      [floats_list((1, x)   )[0] for x in range(8_00     ,							14_00     ,							2_00   )]

										__lowerCamelCase          =      ["""longest""", """max_length""", """do_not_pad"""]
										__lowerCamelCase          =      [None, 16_00, None]
										for max_length, padding in zip(A_     ,							A_   ):
													__lowerCamelCase          =      feat_extract(A_     ,							padding=A_     ,							max_length=A_     ,							return_tensors="""np"""   )
													__lowerCamelCase          =      processed.input_values

													self._check_zero_mean_unit_variance(input_values[0][:8_00]   )
													self.assertTrue(input_values[0][8_00:].sum() < 1E-6   )
													self._check_zero_mean_unit_variance(input_values[1][:10_00]   )
													self.assertTrue(input_values[0][10_00:].sum() < 1E-6   )
													self._check_zero_mean_unit_variance(input_values[2][:12_00]   )




							def   __a   (     self:    Optional[Any]   ):
										__lowerCamelCase          =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
										__lowerCamelCase          =      range(8_00     ,							14_00     ,							2_00   )
										__lowerCamelCase          =      [floats_list((1, x)   )[0] for x in lengths]

										__lowerCamelCase          =      ["""longest""", """max_length""", """do_not_pad"""]
										__lowerCamelCase          =      [None, 16_00, None]

										for max_length, padding in zip(A_     ,							A_   ):
													__lowerCamelCase          =      feat_extract(A_     ,							max_length=A_     ,							padding=A_   )
													__lowerCamelCase          =      processed.input_values

													self._check_zero_mean_unit_variance(input_values[0][:8_00]   )
													self._check_zero_mean_unit_variance(input_values[1][:10_00]   )
													self._check_zero_mean_unit_variance(input_values[2][:12_00]   )




							def   __a   (     self:    Any   ):
										__lowerCamelCase          =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
										__lowerCamelCase          =      [floats_list((1, x)   )[0] for x in range(8_00     ,							14_00     ,							2_00   )]
										__lowerCamelCase          =      feat_extract(
										    A_     ,							truncation=A_     ,							max_length=10_00     ,							padding="""max_length"""     ,							return_tensors="""np"""   )
										__lowerCamelCase          =      processed.input_values

										self._check_zero_mean_unit_variance(input_values[0, :8_00]   )
										self._check_zero_mean_unit_variance(input_values[1]   )
										self._check_zero_mean_unit_variance(input_values[2]   )




							def   __a   (     self:    Any   ):
										__lowerCamelCase          =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
										__lowerCamelCase          =      [floats_list((1, x)   )[0] for x in range(8_00     ,							14_00     ,							2_00   )]
										__lowerCamelCase          =      feat_extract(
										    A_     ,							truncation=A_     ,							max_length=10_00     ,							padding="""longest"""     ,							return_tensors="""np"""   )
										__lowerCamelCase          =      processed.input_values

										self._check_zero_mean_unit_variance(input_values[0, :8_00]   )
										self._check_zero_mean_unit_variance(input_values[1, :10_00]   )
										self._check_zero_mean_unit_variance(input_values[2]   )

										# make sure that if max_length < longest -> then pad to max_length
										self.assertTrue(input_values.shape == (3, 10_00)   )

										__lowerCamelCase          =      [floats_list((1, x)   )[0] for x in range(8_00     ,							14_00     ,							2_00   )]
										__lowerCamelCase          =      feat_extract(
										    A_     ,							truncation=A_     ,							max_length=20_00     ,							padding="""longest"""     ,							return_tensors="""np"""   )
										__lowerCamelCase          =      processed.input_values

										self._check_zero_mean_unit_variance(input_values[0, :8_00]   )
										self._check_zero_mean_unit_variance(input_values[1, :10_00]   )
										self._check_zero_mean_unit_variance(input_values[2]   )

										# make sure that if max_length > longest -> then pad to longest
										self.assertTrue(input_values.shape == (3, 12_00)   )




							@require_torch
							def   __a   (     self:    Union[str, Any]   ):
										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   )




							@slow
							@require_torch
							def   __a   (     self:    int   ):
										# this test makes sure that models that are using
										# group norm don't have their feature extractor return the
										# attention_mask
										for model_id in WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST:
													__lowerCamelCase          =      WavaVecaConfig.from_pretrained(A_   )
													__lowerCamelCase          =      WavaVecaFeatureExtractor.from_pretrained(A_   )

													# only "layer" feature extraction norm should make use of
													# attention_mask
													self.assertEqual(feat_extract.return_attention_mask     ,							config.feat_extract_norm == """layer"""   )








"""simple docstring"""




from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import torch

from ...utils import BaseOutput, OptionalDependencyNotAvailable, is_torch_available, is_transformers_available




@dataclass
class 			__snake_case   (lowerCamelCase  ):
							__a					 =       42


try:
					if not (is_transformers_available() and is_torch_available()):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
					from .pipeline_text_to_video_synth import TextToVideoSDPipeline
					from .pipeline_text_to_video_synth_imgaimg import VideoToVideoSDPipeline  # noqa: F401
					from .pipeline_text_to_video_zero import TextToVideoZeroPipeline




