




"""simple docstring"""

from typing import List, Optional, Union

import numpy as np

from ...feature_extraction_sequence_utils import SequenceFeatureExtractor
from ...feature_extraction_utils import BatchFeature
from ...utils import PaddingStrategy, TensorType, logging


UpperCamelCase__			:     Tuple			       =				logging.get_logger(__name__)
class      A__   (   lowercase_  ):
	A_				:					str      =   ["""input_values""", """attention_mask"""]




	def __init__( self	:						int   ,     lowercase	:						Any=1   ,     lowercase	:						Union[str, Any]=16_000   ,     lowercase	:						Dict=0.0   ,     lowercase	:						int=False   ,     lowercase	:						Optional[int]=True   ,     **lowercase	:						Tuple   ,     )       ->			Dict:
						super().__init__(feature_size=lowercase   ,     sampling_rate=lowercase   ,     padding_value=lowercase   ,     **lowercase						)
						__snake_case        =						return_attention_mask
						__snake_case        =						do_normalize




	@staticmethod
	def 				a_		( lowercase	:						List[np.ndarray]   ,     lowercase	:						List[np.ndarray]   ,     lowercase	:						float = 0.0						)       ->			List[np.ndarray]:
						if attention_mask is not None:
											__snake_case        =						np.array(lowercase   ,     np.intaa						)
											__snake_case        =						[]

											for vector, length in zip(lowercase   ,     attention_mask.sum(-1						)						):
																__snake_case        =						(vector - vector[:length].mean()) / np.sqrt(vector[:length].var() + 1e-7						)
																if length < normed_slice.shape[0]:
																					__snake_case        =						padding_value

																normed_input_values.append(lowercase						)
						else:
											__snake_case        =						[(x - x.mean()) / np.sqrt(x.var() + 1e-7						) for x in input_values]

						return normed_input_values




	def __call__( self	:						Optional[Any]   ,     lowercase	:						Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]]   ,     lowercase	:						Union[bool, str, PaddingStrategy] = False   ,     lowercase	:						Optional[int] = None   ,     lowercase	:						bool = False   ,     lowercase	:						Optional[int] = None   ,     lowercase	:						Optional[bool] = None   ,     lowercase	:						Optional[Union[str, TensorType]] = None   ,     lowercase	:						Optional[int] = None   ,     **lowercase	:						Optional[int]   ,     )       ->			BatchFeature:

						if sampling_rate is not None:
											if sampling_rate != self.sampling_rate:
																raise ValueError(
																    f'''The model corresponding to this feature extractor: {self} was trained using a sampling rate of'''
																    f''' {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled with'''
																    f''' {self.sampling_rate} and not {sampling_rate}.'''						)
						else:
											logger.warning(
											    """It is strongly recommended to pass the ``sampling_rate`` argument to this function. """
											    """Failing to do so can result in silent errors that might be hard to debug."""						)

						__snake_case        =						isinstance(lowercase   ,     np.ndarray						) and len(raw_speech.shape						) > 1
						if is_batched_numpy and len(raw_speech.shape						) > 2:
											raise ValueError(f'''Only mono-channel audio is supported for input to {self}'''						)
						__snake_case        =						is_batched_numpy or (
						    isinstance(lowercase   ,     (list, tuple)						) and (isinstance(raw_speech[0]   ,     (np.ndarray, tuple, list)						))
						)

						# always return batch
						if not is_batched:
											__snake_case        =						[raw_speech]

						# convert into correct format for padding
						__snake_case        =						BatchFeature({"""input_values""": raw_speech}						)

						__snake_case        =						self.pad(
						    lowercase   ,     padding=lowercase   ,     max_length=lowercase   ,     truncation=lowercase   ,     pad_to_multiple_of=lowercase   ,     return_attention_mask=lowercase   ,     )

						# convert input values to correct format
						__snake_case        =						padded_inputs["""input_values"""]
						if not isinstance(input_values[0]   ,     np.ndarray						):
											__snake_case        =						[np.asarray(lowercase   ,     dtype=np.floataa						) for array in input_values]
						elif (
						    not isinstance(lowercase   ,     np.ndarray						)
						    and isinstance(input_values[0]   ,     np.ndarray						)
						    and input_values[0].dtype is np.dtype(np.floataa						)
						):
											__snake_case        =						[array.astype(np.floataa						) for array in input_values]
						elif isinstance(lowercase   ,     np.ndarray						) and input_values.dtype is np.dtype(np.floataa						):
											__snake_case        =						input_values.astype(np.floataa						)

						# convert attention_mask to correct format
						__snake_case        =						padded_inputs.get("""attention_mask"""						)
						if attention_mask is not None:
											__snake_case        =						[np.asarray(lowercase   ,     dtype=np.intaa						) for array in attention_mask]

						# zero-mean and unit-variance normalization
						if self.do_normalize:
											__snake_case        =						(
											    attention_mask
											    if self._get_padding_strategies(lowercase   ,     max_length=lowercase						) is not PaddingStrategy.DO_NOT_PAD
											    else None
											)
											__snake_case        =						self.zero_mean_unit_var_norm(
											    padded_inputs["""input_values"""]   ,     attention_mask=lowercase   ,     padding_value=self.padding_value						)

						if return_tensors is not None:
											__snake_case        =						padded_inputs.convert_to_tensors(lowercase						)

						return padded_inputs








"""simple docstring"""

import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig
from ..clip.configuration_clip import CLIPVisionConfig


UpperCamelCase__			:     Optional[Any]			       =				logging.get_logger(__name__)
class      A__   (   lowercase_  ):
	A_				:					List[str]      =   """vision-text-dual-encoder"""
	A_				:					Tuple      =   True




	def __init__( self	:						Tuple   ,     lowercase	:						List[Any]=512   ,     lowercase	:						Any=2.65_92   ,     **lowercase	:						int						)       ->			int:
						super().__init__(**lowercase						)

						if "vision_config" not in kwargs:
											raise ValueError("""`vision_config` can not be `None`."""						)

						if "text_config" not in kwargs:
											raise ValueError("""`text_config` can not be `None`."""						)

						__snake_case        =						kwargs.pop("""vision_config"""						)
						__snake_case        =						kwargs.pop("""text_config"""						)

						__snake_case        =						vision_config.pop("""model_type"""						)
						__snake_case        =						text_config.pop("""model_type"""						)

						if vision_model_type == "clip":
											__snake_case        =						AutoConfig.for_model(lowercase   ,     **lowercase						).vision_config
						elif vision_model_type == "clip_vision_model":
											__snake_case        =						CLIPVisionConfig(**lowercase						)
						else:
											__snake_case        =						AutoConfig.for_model(lowercase   ,     **lowercase						)

						__snake_case        =						AutoConfig.for_model(lowercase   ,     **lowercase						)

						__snake_case        =						projection_dim
						__snake_case        =						logit_scale_init_value




	@classmethod
	def 				a_		( cls	:						Union[str, Any]   ,     lowercase	:						PretrainedConfig   ,     lowercase	:						PretrainedConfig   ,     **lowercase	:						Optional[int]						)       ->			Dict:
						return cls(vision_config=vision_config.to_dict()   ,     text_config=text_config.to_dict()   ,     **lowercase						)




	def 				a_		( self	:						Dict						)       ->			Dict:
						__snake_case        =						copy.deepcopy(self.__dict__						)
						__snake_case        =						self.vision_config.to_dict()
						__snake_case        =						self.text_config.to_dict()
						__snake_case        =						self.__class__.model_type
						return output


