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


lowercase		:						Union[str, Any] =					logging.get_logger(__name__)




class    _snake_case  (						_lowercase       ):
							SCREAMING_SNAKE_CASE		     =						['''input_values''', '''attention_mask''']






							def __init__(					self						:			str						, snake_case__						:			Optional[Any]=1						, snake_case__						:			str=1_6_0_0_0						, snake_case__						:			Any=0.0						, snake_case__						:			Optional[Any]=False						, snake_case__						:			Optional[Any]=True						, **snake_case__						:			Any						, ):






												"""simple docstring"""



												super().__init__(feature_size=snake_case__						, sampling_rate=snake_case__						, padding_value=snake_case__						, **snake_case__    )
												__a:						List[str]		    =					return_attention_mask
												__a:						List[str]		    =					do_normalize






							@staticmethod
							def 							__lowercase  (					snake_case__						:			List[np.ndarray]						, snake_case__						:			List[np.ndarray]						, snake_case__						:			float = 0.0    ):






												"""simple docstring"""



												if attention_mask is not None:
																	__a:						Optional[int]		    =					np.array(snake_case__						, np.intaa    )
																	__a:						Optional[Any]		    =					[]

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

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

												return normed_input_values






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






												"""simple docstring"""



												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."""    )

												__a:						Optional[int]		    =					isinstance(snake_case__						, 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}"""    )
												__a:						str		    =					is_batched_numpy or (
												    isinstance(snake_case__						, (list, tuple)    ) and (isinstance(raw_speech[0]						, (np.ndarray, tuple, list)    ))
												)

												# always return batch
												if not is_batched:
																	__a:						Optional[Any]		    =					[raw_speech]

												# convert into correct format for padding
												__a:						Optional[int]		    =					BatchFeature({"""input_values""": raw_speech}    )

												__a:						Optional[Any]		    =					self.pad(
												    snake_case__						, padding=snake_case__						, max_length=snake_case__						, truncation=snake_case__						, pad_to_multiple_of=snake_case__						, return_attention_mask=snake_case__						, )

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

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

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

												if return_tensors is not None:
																	__a:						List[Any]		    =					padded_inputs.convert_to_tensors(snake_case__    )

												return padded_inputs


"""simple docstring"""
from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


lowercase		:						Tuple =					logging.get_logger(__name__)




class    _snake_case  (						_lowercase       ):
							SCREAMING_SNAKE_CASE		     =						['''pixel_values''']






							def __init__(					self						:			Union[str, Any]						, snake_case__						:			bool = True						, snake_case__						:			Optional[Dict[str, int]] = None						, snake_case__						:			PILImageResampling = PILImageResampling.BILINEAR						, snake_case__						:			bool = True						, snake_case__						:			Union[int, float] = 1 / 2_5_5						, snake_case__						:			bool = True						, snake_case__						:			Optional[Union[float, List[float]]] = None						, snake_case__						:			Optional[Union[float, List[float]]] = None						, **snake_case__						:			Optional[int]						, ):






												"""simple docstring"""



												super().__init__(**snake_case__    )
												__a:						Dict		    =					size if size is not None else {"""height""": 2_2_4, """width""": 2_2_4}
												__a:						Optional[Any]		    =					get_size_dict(snake_case__    )
												__a:						Union[str, Any]		    =					do_resize
												__a:						str		    =					do_rescale
												__a:						Tuple		    =					do_normalize
												__a:						Dict		    =					size
												__a:						str		    =					resample
												__a:						Any		    =					rescale_factor
												__a:						Optional[int]		    =					image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
												__a:						int		    =					image_std if image_std is not None else IMAGENET_STANDARD_STD






							def 							__lowercase  (					self						:			Optional[Any]						, snake_case__						:			np.ndarray						, snake_case__						:			Dict[str, int]						, snake_case__						:			PILImageResampling = PILImageResampling.BILINEAR						, snake_case__						:			Optional[Union[str, ChannelDimension]] = None						, **snake_case__						:			List[str]						, ):






												"""simple docstring"""



												__a:						int		    =					get_size_dict(snake_case__    )
												if "height" not in size or "width" not in size:
																	raise ValueError(f"""The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}"""    )
												return resize(
												    snake_case__						, size=(size["""height"""], size["""width"""])						, resample=snake_case__						, data_format=snake_case__						, **snake_case__    )






							def 							__lowercase  (					self						:			List[str]						, snake_case__						:			np.ndarray						, snake_case__						:			float						, snake_case__						:			Optional[Union[str, ChannelDimension]] = None						, **snake_case__						:			Union[str, Any]    ):






												"""simple docstring"""



												return rescale(snake_case__						, scale=snake_case__						, data_format=snake_case__						, **snake_case__    )






							def 							__lowercase  (					self						:			Dict						, snake_case__						:			np.ndarray						, snake_case__						:			Union[float, List[float]]						, snake_case__						:			Union[float, List[float]]						, snake_case__						:			Optional[Union[str, ChannelDimension]] = None						, **snake_case__						:			Union[str, Any]						, ):






												"""simple docstring"""



												return normalize(snake_case__						, mean=snake_case__						, std=snake_case__						, data_format=snake_case__						, **snake_case__    )






							def 							__lowercase  (					self						:			Optional[int]						, snake_case__						:			ImageInput						, snake_case__						:			Optional[bool] = None						, snake_case__						:			Dict[str, int] = None						, snake_case__						:			PILImageResampling = None						, snake_case__						:			Optional[bool] = None						, snake_case__						:			Optional[float] = None						, snake_case__						:			Optional[bool] = None						, snake_case__						:			Optional[Union[float, List[float]]] = None						, snake_case__						:			Optional[Union[float, List[float]]] = None						, snake_case__						:			Optional[Union[str, TensorType]] = None						, snake_case__						:			Union[str, ChannelDimension] = ChannelDimension.FIRST						, **snake_case__						:			List[str]						, ):






												"""simple docstring"""



												__a:						Any		    =					do_resize if do_resize is not None else self.do_resize
												__a:						Any		    =					do_rescale if do_rescale is not None else self.do_rescale
												__a:						int		    =					do_normalize if do_normalize is not None else self.do_normalize
												__a:						Any		    =					resample if resample is not None else self.resample
												__a:						Any		    =					rescale_factor if rescale_factor is not None else self.rescale_factor
												__a:						Dict		    =					image_mean if image_mean is not None else self.image_mean
												__a:						List[str]		    =					image_std if image_std is not None else self.image_std

												__a:						int		    =					size if size is not None else self.size
												__a:						Any		    =					get_size_dict(snake_case__    )

												__a:						List[str]		    =					make_list_of_images(snake_case__    )

												if not valid_images(snake_case__    ):
																	raise ValueError(
																	    """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
																	    """torch.Tensor, tf.Tensor or jax.ndarray."""    )

												if do_resize and size is None:
																	raise ValueError("""Size must be specified if do_resize is True."""    )

												if do_rescale and rescale_factor is None:
																	raise ValueError("""Rescale factor must be specified if do_rescale is True."""    )

												# All transformations expect numpy arrays.
												__a:						str		    =					[to_numpy_array(snake_case__    ) for image in images]

												if do_resize:
																	__a:						Dict		    =					[self.resize(image=snake_case__						, size=snake_case__						, resample=snake_case__    ) for image in images]

												if do_rescale:
																	__a:						str		    =					[self.rescale(image=snake_case__						, scale=snake_case__    ) for image in images]

												if do_normalize:
																	__a:						Dict		    =					[self.normalize(image=snake_case__						, mean=snake_case__						, std=snake_case__    ) for image in images]

												__a:						int		    =					[to_channel_dimension_format(snake_case__						, snake_case__    ) for image in images]

												__a:						str		    =					{"""pixel_values""": images}
												return BatchFeature(data=snake_case__						, tensor_type=snake_case__    )
