



'''simple docstring'''



from typing import List, Optional, Union

import numpy as np
import torch
import torchaudio.compliance.kaldi as ta_kaldi

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


lowerCamelCase	 =       logging.get_logger(__name__)





class _UpperCamelCase		(     A		):





				'''simple docstring'''





				lowerCAmelCase__					    =    ["""input_features""", """attention_mask"""]

				def __init__(							self  :  int  ,       _lowerCAmelCase  :  List[str]=8_0  ,       _lowerCAmelCase  :  Any=1_6_0_0_0  ,       _lowerCAmelCase  :  int=8_0  ,       _lowerCAmelCase  :  Optional[int]=0.0  ,       _lowerCAmelCase  :  str=True  ,       _lowerCAmelCase  :  Optional[Any]=True  ,       _lowerCAmelCase  :  Union[str, Any]=True  ,       **_lowerCAmelCase  :  List[Any]  ,       ):







											'''simple docstring'''

											super().__init__(feature_size=_lowerCAmelCase  ,       sampling_rate=_lowerCAmelCase  ,       padding_value=_lowerCAmelCase  ,       **_lowerCAmelCase)
											__lowercase       	=num_mel_bins
											__lowercase       	=do_ceptral_normalize
											__lowercase       	=normalize_means
											__lowercase       	=normalize_vars
											__lowercase       	=True

				def 				__lowerCamelCase     (							self  :  str  ,       _lowerCAmelCase  :  np.ndarray  ,       ):







											'''simple docstring'''

											__lowercase       	=waveform * (2**1_5)  # Kaldi compliance: 16-bit signed integers
											__lowercase       	=torch.from_numpy(_lowerCAmelCase).unsqueeze(0)
											__lowercase       	=ta_kaldi.fbank(_lowerCAmelCase  ,       num_mel_bins=self.num_mel_bins  ,       sample_frequency=self.sampling_rate)
											return features.numpy()

				@staticmethod
				def 				__lowerCamelCase     (							_lowerCAmelCase  :  np.ndarray  ,       _lowerCAmelCase  :  int  ,       _lowerCAmelCase  :  Optional[bool] = True  ,       _lowerCAmelCase  :  Optional[bool] = True  ,       _lowerCAmelCase  :  float = 0.0  ,       ):







											'''simple docstring'''

											if normalize_means:
																		__lowercase       	=x[:input_length].mean(axis=0)
																		__lowercase       	=np.subtract(_lowerCAmelCase  ,       _lowerCAmelCase)
											if normalize_vars:
																		__lowercase       	=x[:input_length].std(axis=0)
																		__lowercase       	=np.divide(_lowerCAmelCase  ,       _lowerCAmelCase)

											if input_length < x.shape[0]:
																		__lowercase       	=padding_value

											# make sure array is in float32
											__lowercase       	=x.astype(np.floataa)

											return x

				def 				__lowerCamelCase     (							self  :  Dict  ,       _lowerCAmelCase  :  List[np.ndarray]  ,       _lowerCAmelCase  :  Optional[np.ndarray] = None):







											'''simple docstring'''

											__lowercase       	=attention_mask.sum(-1) if attention_mask is not None else [x.shape[0] for x in input_features]
											return [
											    self.utterance_cmvn(_lowerCAmelCase  ,       _lowerCAmelCase  ,       self.normalize_means  ,       self.normalize_vars  ,       self.padding_value)
											    for x, n in zip(_lowerCAmelCase  ,       _lowerCAmelCase)
											]

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







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

											__lowercase       	=isinstance(_lowerCAmelCase  ,       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}""")
											__lowercase       	=is_batched_numpy or (
											    isinstance(_lowerCAmelCase  ,       (list, tuple)) and (isinstance(raw_speech[0]  ,       (np.ndarray, tuple, list)))
											)

											if is_batched:
																		__lowercase       	=[np.asarray(_lowerCAmelCase  ,       dtype=np.floataa) for speech in raw_speech]
											elif not is_batched and not isinstance(_lowerCAmelCase  ,       np.ndarray):
																		__lowercase       	=np.asarray(_lowerCAmelCase  ,       dtype=np.floataa)
											elif isinstance(_lowerCAmelCase  ,       np.ndarray) and raw_speech.dtype is np.dtype(np.floataa):
																		__lowercase       	=raw_speech.astype(np.floataa)

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

											# extract fbank features
											__lowercase       	=[self._extract_fbank_features(_lowerCAmelCase) for waveform in raw_speech]

											# convert into correct format for padding
											__lowercase       	=BatchFeature({'input_features': features})

											__lowercase       	=self.pad(
											    _lowerCAmelCase  ,       padding=_lowerCAmelCase  ,       max_length=_lowerCAmelCase  ,       truncation=_lowerCAmelCase  ,       pad_to_multiple_of=_lowerCAmelCase  ,       return_attention_mask=_lowerCAmelCase  ,       **_lowerCAmelCase  ,       )

											# make sure list is in array format
											__lowercase       	=padded_inputs.get('input_features')
											if isinstance(input_features[0]  ,       _lowerCAmelCase):
																		__lowercase       	=[np.asarray(_lowerCAmelCase  ,       dtype=np.floataa) for feature in input_features]

											__lowercase       	=padded_inputs.get('attention_mask')
											if attention_mask is not None:
																		__lowercase       	=[np.asarray(_lowerCAmelCase  ,       dtype=np.intaa) for array in attention_mask]

											# Utterance-level cepstral mean and variance normalization
											if self.do_ceptral_normalize:
																		__lowercase       	=(
																		    np.array(_lowerCAmelCase  ,       dtype=np.intaa)
																		    if self._get_padding_strategies(_lowerCAmelCase  ,       max_length=_lowerCAmelCase) is not PaddingStrategy.DO_NOT_PAD
																		    else None
																		)
																		__lowercase       	=self.normalize(
																		    padded_inputs['input_features']  ,       attention_mask=_lowerCAmelCase)

											if return_tensors is not None:
																		__lowercase       	=padded_inputs.convert_to_tensors(_lowerCAmelCase)

											return padded_inputs








'''simple docstring'''



from functools import lru_cache



def   _A       (   _lowerCAmelCase					):



							"""simple docstring"""



							__lowercase       	=2
							__lowercase       	=set()
							while i * i <= n:
														if n % i:
																					i += 1
														else:
																					n //= i
																					factors.add(_lowerCAmelCase					)
							if n > 1:
														factors.add(_lowerCAmelCase					)
							return factors



@lru_cache
def   _A       (   _lowerCAmelCase					):



							"""simple docstring"""



							return len(unique_prime_factors(_lowerCAmelCase					)					)



def   _A       (   _lowerCAmelCase					):



							"""simple docstring"""



							return len(set(_lowerCAmelCase					)					) in (0, 1)



def   _A       (   _lowerCAmelCase					):



							"""simple docstring"""



							__lowercase       	=2

							while True:
														# Increment each value of a generated range
														__lowercase       	=[base + i for i in range(_lowerCAmelCase					)]

														# Run elements through out unique_prime_factors function
														# Append our target number to the end.
														__lowercase       	=[upf_len(_lowerCAmelCase					) for x in group]
														checker.append(_lowerCAmelCase					)

														# If all numbers in the list are equal, return the group variable.
														if equality(_lowerCAmelCase					):
																					return group

														# Increment our base variable by 1
														base += 1



def   _A       (   _lowerCAmelCase = 4					):



							"""simple docstring"""



							__lowercase       	=run(_lowerCAmelCase					)
							return results[0] if len(_lowerCAmelCase					) else None


if __name__ == "__main__":
		print(solution())



