






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


lowercase_    					=					logging.get_logger(__name__)


class  snake_case		(							_lowerCAmelCase						):


   '''simple docstring'''

   A_						:     str									=			["input_values", "attention_mask"]


   def __init__(     self			:					List[str],	_lowerCamelCase			:					Union[str, Any]=1,	_lowerCamelCase			:					int=1_60_00,	_lowerCamelCase			:					Any=1_28,	_lowerCamelCase			:					Optional[Any]=10_24,	_lowerCamelCase			:					Optional[Any]=0.0,	_lowerCamelCase			:					Tuple=True,	_lowerCamelCase			:					List[str]=-4.2_67_73_93,	_lowerCamelCase			:					Any=4.5_68_99_74,	_lowerCamelCase			:					List[Any]=False,	**_lowerCamelCase			:					str,	):

     '''simple docstring'''
     super().__init__(feature_size=_lowerCamelCase,	sampling_rate=_lowerCamelCase,	padding_value=_lowerCamelCase,	**_lowerCamelCase  )
     __A						      =			num_mel_bins
     __A						      =			max_length
     __A						      =			do_normalize
     __A						      =			mean
     __A						      =			std
     __A						      =			return_attention_mask


   def     _SCREAMING_SNAKE_CASE    (     self			:					Optional[int],	_lowerCamelCase			:					np.ndarray,	_lowerCamelCase			:					int,	):

     '''simple docstring'''
     __A						      =			torch.from_numpy(_lowerCamelCase  ).unsqueeze(0  )
     __A						      =			ta_kaldi.fbank(
         _lowerCamelCase,	htk_compat=_lowerCamelCase,	sample_frequency=self.sampling_rate,	use_energy=_lowerCamelCase,	window_type='''hanning''',	num_mel_bins=self.num_mel_bins,	dither=0.0,	frame_shift=10,	)

     __A						      =			fbank.shape[0]
     __A						      =			max_length - n_frames

     # pad or truncate, depending on difference
     if difference > 0:
       __A						      =			torch.nn.ZeroPadad((0, 0, 0, difference)  )
       __A						      =			pad_module(_lowerCamelCase  )
     elif difference < 0:
       __A						      =			fbank[0:max_length, :]

     __A						      =			fbank.numpy()

     return fbank


   def     _SCREAMING_SNAKE_CASE    (     self			:					int,	_lowerCamelCase			:					np.ndarray  ):

     '''simple docstring'''
     return (input_values - (self.mean)) / (self.std * 2)






   def __call__(     self			:					Dict,	_lowerCamelCase			:					Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]],	_lowerCamelCase			:					Optional[int] = None,	_lowerCamelCase			:					Optional[Union[str, TensorType]] = 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.'''  )

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

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

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

     # extract fbank features and pad/truncate to max_length
     __A						      =			[self._extract_fbank_features(_lowerCamelCase,	max_length=self.max_length  ) for waveform in raw_speech]

     # convert into BatchFeature
     __A						      =			BatchFeature({'''input_values''': features}  )

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

     # normalization
     if self.do_normalize:
       __A						      =			[self.normalize(_lowerCamelCase  ) for feature in input_values]

     if return_tensors is not None:
       __A						      =			padded_inputs.convert_to_tensors(_lowerCamelCase  )

     return padded_inputs












"""simple docstring"""


from itertools import product



def  lowerCAmelCase    (   __UpperCamelCase = 1_5			):




  """simple docstring"""







  __A						      =			0.0
  __A						      =			42
  __A						      =			42
  __A						      =			42
  __A						      =			42
  __A						      =			42
  __A						      =			42

  for series in product(range(2			)		,	repeat=__UpperCamelCase			):
    __A						      =			series.count(1			)
    __A						      =			num_turns - num_blue
    if num_red >= num_blue:
      continue
    __A						      =			1.0
    for ind, col in enumerate(__UpperCamelCase		,	2			):
      if col == 0:
        prob *= (ind - 1) / ind
      else:
        prob *= 1 / ind

    total_prob += prob

  return int(1 / total_prob			)


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




