


'''simple docstring'''



from math import ceil
from typing import List, Optional, Union

import numpy as np

from ...audio_utils import mel_filter_bank, spectrogram, window_function
from ...feature_extraction_sequence_utils import BatchFeature, SequenceFeatureExtractor
from ...utils import TensorType, logging


__UpperCAmelCase    :Dict				       =     logging.get_logger(__name__)



class 			a       (	_a ):


     """simple docstring"""






     SCREAMING_SNAKE_CASE :				Dict							     =     ["audio_values", "audio_mask"]

     def __init__(       self  :	Any							,				snake_case  :	str=2048							,				snake_case  :	Optional[int]=1							,				snake_case  :	List[Any]=[16, 16]							,				snake_case  :	List[str]=128							,				snake_case  :	Union[str, Any]=4_4100							,				snake_case  :	str=86							,				snake_case  :	Tuple=2048							,				snake_case  :	Tuple=0.0							,				**snake_case  :	Dict							,				)		->							Union[str, Any]:
          super().__init__(
              feature_size=snake_case							,				sampling_rate=snake_case							,				padding_value=snake_case							,				**snake_case							,				)

          __UpperCAmelCase			:				Union[str, Any]													=    spectrogram_length
          __UpperCAmelCase			:				List[str]													=    num_channels
          __UpperCAmelCase			:				Optional[Any]													=    patch_size
          __UpperCAmelCase			:				Union[str, Any]													=    feature_size // self.patch_size[1]
          __UpperCAmelCase			:				Optional[int]													=    n_fft
          __UpperCAmelCase			:				Optional[int]													=    sampling_rate // hop_length_to_sampling_rate
          __UpperCAmelCase			:				Dict													=    sampling_rate
          __UpperCAmelCase			:				Dict													=    padding_value
          __UpperCAmelCase			:				List[str]													=    mel_filter_bank(
              num_frequency_bins=1 + n_fft // 2							,				num_mel_filters=snake_case							,				min_frequency=0.0							,				max_frequency=22_050.0							,				sampling_rate=snake_case							,				norm='''slaney'''							,				mel_scale='''slaney'''							,				).T

     def 				lowerCamelCase__				(       self  :	List[str]							,				snake_case  :	np.array    )		->							np.ndarray:
          __UpperCAmelCase			:				int													=    spectrogram(
              snake_case							,				window_function(self.n_fft							,				'''hann'''    )							,				frame_length=self.n_fft							,				hop_length=self.hop_length							,				power=2.0							,				mel_filters=self.mel_filters.T							,				log_mel='''dB'''							,				db_range=80.0							,				)
          __UpperCAmelCase			:				Optional[Any]													=    log_spec[:, :-1]
          __UpperCAmelCase			:				Tuple													=    log_spec - 20.0
          __UpperCAmelCase			:				Optional[int]													=    np.clip(log_spec / 40.0							,				-2.0							,				0.0    ) + 1.0
          return log_spec






     def __call__(       self  :	List[str]							,				snake_case  :	Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]]							,				snake_case  :	Optional[Union[str, TensorType]] = None							,				snake_case  :	Optional[bool] = True							,				snake_case  :	Optional[int] = None							,				snake_case  :	bool = False							,				snake_case  :	bool = False							,				**snake_case  :	Any							,				)		->							BatchFeature:

          if sampling_rate is not None:
               if sampling_rate != self.sampling_rate:
                    raise ValueError(
                        '''This feature extractor is set to support sampling rate'''
                        f' of {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled'
                        f' with {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			:				Tuple													=    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}'    )
          __UpperCAmelCase			:				str													=    is_batched_numpy or (
              isinstance(snake_case							,				(list, tuple)    ) and (isinstance(raw_speech[0]							,				(np.ndarray, tuple, list)    ))
          )
          if is_batched:
               __UpperCAmelCase			:				Optional[Any]													=    [np.asarray([speech]							,				dtype=np.floataa    ).T for speech in raw_speech]
          elif not is_batched and not isinstance(snake_case							,				np.ndarray    ):
               __UpperCAmelCase			:				Tuple													=    np.asarray(snake_case							,				dtype=np.floataa    )
          elif isinstance(snake_case							,				np.ndarray    ) and raw_speech.dtype is np.dtype(np.floataa    ):
               __UpperCAmelCase			:				Optional[Any]													=    raw_speech.astype(np.floataa    )
          # always return batch
          if not is_batched:
               __UpperCAmelCase			:				Tuple													=    [np.asarray([raw_speech]    ).T]

          # Convert audio signals to log mel spectrograms, truncate by time axis
          __UpperCAmelCase			:				str													=    [
              self._np_extract_fbank_features(waveform.squeeze()    ).T[: self.spectrogram_length] for waveform in raw_speech
          ]
          if isinstance(audio_features[0]							,				snake_case    ):
               __UpperCAmelCase			:				List[str]													=    [np.asarray(snake_case							,				dtype=np.floataa    ) for feature in audio_features]

          # Create audio attention mask
          __UpperCAmelCase			:				int													=    max(
              [ceil(feature.shape[0] / self.patch_size[0]    ) * self.freq_len for feature in audio_features]    )  # The maximum number of audio patches in a batch
          if return_attention_mask:
               __UpperCAmelCase			:				Union[str, Any]													=    [
                   (ceil(feature.shape[0] / self.patch_size[0]    ) * self.freq_len) * [1]
                   + (max_patch_len - ceil(feature.shape[0] / self.patch_size[0]    ) * self.freq_len) * [0]
                   for feature in audio_features
               ]
               __UpperCAmelCase			:				Optional[Any]													=    np.array(snake_case    ).astype(np.floataa    )

          # convert into correct format for padding
          __UpperCAmelCase			:				Dict													=    max_patch_len // self.freq_len * self.patch_size[0]  # The maximum audio size in a batch
          __UpperCAmelCase			:				Tuple													=    np.ones([len(snake_case    ), 1, max_time_len, self.feature_size]    ).astype(np.floataa    )
          __UpperCAmelCase			:				List[Any]													=    padded_audio_features * self.padding_value
          for i in range(len(snake_case    )    ):
               __UpperCAmelCase			:				Any													=    audio_features[i]
               __UpperCAmelCase			:				Optional[int]													=    feature

          # return as BatchFeature
          if return_attention_mask:
               __UpperCAmelCase			:				Dict													=    {'''audio_values''': padded_audio_features, '''audio_mask''': audio_mask}
          else:
               __UpperCAmelCase			:				Any													=    {'''audio_values''': padded_audio_features}

          __UpperCAmelCase			:				Optional[Any]													=    BatchFeature(data=snake_case							,				tensor_type=snake_case    )
          return encoded_inputs



'''simple docstring'''



from __future__ import annotations




def 			_a			(		_lowercase      :			int						):





     '''simple docstring'''






     __UpperCAmelCase			:				str													=    [True] * limit
     __UpperCAmelCase			:				Tuple													=    False
     __UpperCAmelCase			:				List[str]													=    False
     __UpperCAmelCase			:				List[Any]													=    True

     for i in range(3    ,      int(limit**0.5 + 1						)    ,      2						):
          __UpperCAmelCase			:				Dict													=    i * 2
          while index < limit:
               __UpperCAmelCase			:				Optional[int]													=    False
               __UpperCAmelCase			:				Union[str, Any]													=    index + i

     __UpperCAmelCase			:				Optional[Any]													=    [2]

     for i in range(3    ,      _lowercase    ,      2						):
          if is_prime[i]:
               primes.append(_lowercase						)

     return primes




def 			_a			(		_lowercase      :			int = 1000000						):





     '''simple docstring'''






     __UpperCAmelCase			:				List[str]													=    prime_sieve(_lowercase						)
     __UpperCAmelCase			:				Optional[Any]													=    0
     __UpperCAmelCase			:				int													=    0

     for i in range(len(_lowercase						)						):
          for j in range(i + length    ,      len(_lowercase						)						):
               __UpperCAmelCase			:				Optional[Any]													=    sum(primes[i:j]						)
               if sol >= ceiling:
                    break

               if sol in primes:
                    __UpperCAmelCase			:				Any													=    j - i
                    __UpperCAmelCase			:				List[Any]													=    sol

     return largest


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