

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


snake_case_   :   Optional[int]        =       logging.get_logger(__name__)







class       snake_case__  ( lowerCAmelCase_     ):
			SCREAMING_SNAKE_CASE__     				=						['''input_features''', '''attention_mask''']







			def __init__(			self			: Any			,  lowercase			: Tuple=80			,  lowercase			: Any=1_60_00			,  lowercase			: Optional[Any]=80			,  lowercase			: Optional[Any]=0.0			,  lowercase			: List[Any]=True			,  lowercase			: Optional[int]=True			,  lowercase			: Any=True			,  **lowercase			: Tuple			,  ):





								'''simple docstring'''



								super().__init__(feature_size=lowercase			,  sampling_rate=lowercase			,  padding_value=lowercase			,  **lowercase  )
								UpperCAmelCase			:   List[str]      =				num_mel_bins
								UpperCAmelCase			:   Optional[int]      =				do_ceptral_normalize
								UpperCAmelCase			:   int      =				normalize_means
								UpperCAmelCase			:   Dict      =				normalize_vars
								UpperCAmelCase			:   Union[str, Any]      =				True







			def 			__lowerCAmelCase				(			self			: int			,  lowercase			: np.ndarray			,  ):





								'''simple docstring'''



								UpperCAmelCase			:   str      =				waveform * (2**15)  # Kaldi compliance: 16-bit signed integers
								UpperCAmelCase			:   Dict      =				torch.from_numpy(lowercase  ).unsqueeze(0  )
								UpperCAmelCase			:   List[Any]      =				ta_kaldi.fbank(lowercase			,  num_mel_bins=self.num_mel_bins			,  sample_frequency=self.sampling_rate  )
								return features.numpy()







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





								'''simple docstring'''



								if normalize_means:
													UpperCAmelCase			:   List[str]      =				x[:input_length].mean(axis=0  )
													UpperCAmelCase			:   Tuple      =				np.subtract(lowercase			,  lowercase  )
								if normalize_vars:
													UpperCAmelCase			:   Optional[Any]      =				x[:input_length].std(axis=0  )
													UpperCAmelCase			:   Optional[int]      =				np.divide(lowercase			,  lowercase  )

								if input_length < x.shape[0]:
													UpperCAmelCase			:   Union[str, Any]      =				padding_value

								# make sure array is in float32
								UpperCAmelCase			:   List[str]      =				x.astype(np.floataa  )

								return x







			def 			__lowerCAmelCase				(			self			: List[Any]			,  lowercase			: List[np.ndarray]			,  lowercase			: Optional[np.ndarray] = None  ):





								'''simple docstring'''



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







			def __call__(			self			: Dict			,  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[Union[str, TensorType]] = None			,  lowercase			: Optional[int] = None			,  lowercase			: Optional[bool] = None			,  **lowercase			: 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."  )

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

								if is_batched:
													UpperCAmelCase			:   str      =				[np.asarray(lowercase			,  dtype=np.floataa  ) for speech in raw_speech]
								elif not is_batched and not isinstance(lowercase			,  np.ndarray  ):
													UpperCAmelCase			:   int      =				np.asarray(lowercase			,  dtype=np.floataa  )
								elif isinstance(lowercase			,  np.ndarray  ) and raw_speech.dtype is np.dtype(np.floataa  ):
													UpperCAmelCase			:   Tuple      =				raw_speech.astype(np.floataa  )

								# always return batch
								if not is_batched:
													UpperCAmelCase			:   Optional[int]      =				[raw_speech]

								# extract fbank features
								UpperCAmelCase			:   Tuple      =				[self._extract_fbank_features(lowercase  ) for waveform in raw_speech]

								# convert into correct format for padding
								UpperCAmelCase			:   List[str]      =				BatchFeature({"input_features": features}  )

								UpperCAmelCase			:   List[Any]      =				self.pad(
								    lowercase			,  padding=lowercase			,  max_length=lowercase			,  truncation=lowercase			,  pad_to_multiple_of=lowercase			,  return_attention_mask=lowercase			,  **lowercase			,  )

								# make sure list is in array format
								UpperCAmelCase			:   Optional[int]      =				padded_inputs.get("input_features"  )
								if isinstance(input_features[0]			,  lowercase  ):
													UpperCAmelCase			:   List[str]      =				[np.asarray(lowercase			,  dtype=np.floataa  ) for feature in input_features]

								UpperCAmelCase			:   List[Any]      =				padded_inputs.get("attention_mask"  )
								if attention_mask is not None:
													UpperCAmelCase			:   Tuple      =				[np.asarray(lowercase			,  dtype=np.intaa  ) for array in attention_mask]

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

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

								return padded_inputs





"""simple docstring"""






from functools import reduce

snake_case_   :   List[Any]        =       (
    """73167176531330624919225119674426574742355349194934"""
    """96983520312774506326239578318016984801869478851843"""
    """85861560789112949495459501737958331952853208805511"""
    """12540698747158523863050715693290963295227443043557"""
    """66896648950445244523161731856403098711121722383113"""
    """62229893423380308135336276614282806444486645238749"""
    """30358907296290491560440772390713810515859307960866"""
    """70172427121883998797908792274921901699720888093776"""
    """65727333001053367881220235421809751254540594752243"""
    """52584907711670556013604839586446706324415722155397"""
    """53697817977846174064955149290862569321978468622482"""
    """83972241375657056057490261407972968652414535100474"""
    """82166370484403199890008895243450658541227588666881"""
    """16427171479924442928230863465674813919123162824586"""
    """17866458359124566529476545682848912883142607690042"""
    """24219022671055626321111109370544217506941658960408"""
    """07198403850962455444362981230987879927244284909188"""
    """84580156166097919133875499200524063689912560717606"""
    """05886116467109405077541002256983155200055935729725"""
    """71636269561882670428252483600823257530420752963450"""
)



def   lowercase_	(    _lowercase       :		str = N	):




					'''simple docstring'''






					return max(
					    # mypy cannot properly interpret reduce
					    int(reduce(lambda _lowercase							,      _lowercase	: str(int(_lowercase	) * int(_lowercase	)	)							,      n[i : i + 13]	)	)
					    for i in range(len(_lowercase	) - 12	)	)


if __name__ == "__main__":
	print(f'''{solution() = }''')


