
"""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 TensorType, logging


A__   :						Tuple 							=     logging.get_logger(__name__)







class 	_lowercase    (							lowerCAmelCase_					):


     '''simple docstring'''





     _A		    =				['input_values', 'attention_mask']



     def __init__(   self			,      __UpperCamelCase=1			,      __UpperCamelCase=1_60_00			,      __UpperCamelCase=1_28			,      __UpperCamelCase=10_24			,      __UpperCamelCase=0.0			,      __UpperCamelCase=True			,      __UpperCamelCase=-4.267_7393			,      __UpperCamelCase=4.568_9974			,      __UpperCamelCase=False			,      **__UpperCamelCase			,      )->       Union[str, Any]:
          super().__init__(feature_size=__UpperCamelCase			,      sampling_rate=__UpperCamelCase			,      padding_value=__UpperCamelCase			,      **__UpperCamelCase	)
          UpperCAmelCase__				:			List[Any]							=    num_mel_bins
          UpperCAmelCase__				:			Any							=    max_length
          UpperCAmelCase__				:			Any							=    do_normalize
          UpperCAmelCase__				:			Any							=    mean
          UpperCAmelCase__				:			Union[str, Any]							=    std
          UpperCAmelCase__				:			str							=    return_attention_mask



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      )->       np.ndarray:
          UpperCAmelCase__				:			Any							=    torch.from_numpy(__UpperCamelCase	).unsqueeze(0	)
          UpperCAmelCase__				:			Optional[Any]							=    ta_kaldi.fbank(
              __UpperCamelCase			,      htk_compat=__UpperCamelCase			,      sample_frequency=self.sampling_rate			,      use_energy=__UpperCamelCase			,      window_type="hanning"			,      num_mel_bins=self.num_mel_bins			,      dither=0.0			,      frame_shift=10			,      )

          UpperCAmelCase__				:			Any							=    fbank.shape[0]
          UpperCAmelCase__				:			int							=    max_length - n_frames

          # pad or truncate, depending on difference
          if difference > 0:
               UpperCAmelCase__				:			List[str]							=    torch.nn.ZeroPadad((0, 0, 0, difference)	)
               UpperCAmelCase__				:			Any							=    pad_module(__UpperCamelCase	)
          elif difference < 0:
               UpperCAmelCase__				:			Tuple							=    fbank[0:max_length, :]

          UpperCAmelCase__				:			Optional[int]							=    fbank.numpy()

          return fbank



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase	)->       np.ndarray:
          return (input_values - (self.mean)) / (self.std * 2)



     def __call__(   self			,      __UpperCamelCase			,      __UpperCamelCase = None			,      __UpperCamelCase = None			,      **__UpperCamelCase			,      )->       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."	)

          UpperCAmelCase__				:			List[str]							=    isinstance(__UpperCamelCase			,      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__				:			str							=    is_batched_numpy or (
              isinstance(__UpperCamelCase			,      (list, tuple)	) and (isinstance(raw_speech[0]			,      (np.ndarray, tuple, list)	))
          )

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

          # always return batch
          if not is_batched:
               UpperCAmelCase__				:			List[str]							=    [raw_speech]

          # extract fbank features and pad/truncate to max_length
          UpperCAmelCase__				:			List[str]							=    [self._extract_fbank_features(__UpperCamelCase			,      max_length=self.max_length	) for waveform in raw_speech]

          # convert into BatchFeature
          UpperCAmelCase__				:			str							=    BatchFeature({"input_values": features}	)

          # make sure list is in array format
          UpperCAmelCase__				:			str							=    padded_inputs.get("input_values"	)
          if isinstance(input_values[0]			,      __UpperCamelCase	):
               UpperCAmelCase__				:			str							=    [np.asarray(__UpperCamelCase			,      dtype=np.floataa	) for feature in input_values]

          # normalization
          if self.do_normalize:
               UpperCAmelCase__				:			Dict							=    [self.normalize(__UpperCamelCase	) for feature in input_values]

          if return_tensors is not None:
               UpperCAmelCase__				:			Union[str, Any]							=    padded_inputs.convert_to_tensors(__UpperCamelCase	)

          return padded_inputs





"""simple docstring"""




def 				a__			(					lowerCAmelCase						:							int		):






     '''simple docstring'''
     if number != int(lowerCAmelCase		):
          raise ValueError("factorial() only accepts integral values"		)
     if number < 0:
          raise ValueError("factorial() not defined for negative values"		)
     UpperCAmelCase__				:			int							=    1
     for i in range(1							,     number + 1		):
          value *= i
     return value



def 				a__			(					lowerCAmelCase						:							int		):






     '''simple docstring'''
     if not isinstance(lowerCAmelCase							,     lowerCAmelCase		):
          raise ValueError("factorial() only accepts integral values"		)
     if n < 0:
          raise ValueError("factorial() not defined for negative values"		)
     return 1 if n == 0 or n == 1 else n * factorial(n - 1		)


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    A__   :						Any 							=     int(input("""Enter a positive integer: """).strip() or 0)
    print(f"""factorial{n} is {factorial(n)}""")



