




"""simple docstring"""




import math
from typing import Optional

import numpy as np

from ...configuration_utils import PretrainedConfig
from ...utils import logging


a_	   =    logging.get_logger(__name__)

a_	   =    {
    '''facebook/encodec_24khz''': '''https://huggingface.co/facebook/encodec_24khz/resolve/main/config.json''',
    '''facebook/encodec_48khz''': '''https://huggingface.co/facebook/encodec_48khz/resolve/main/config.json''',
}

class    UpperCAmelCase_  (       _lowercase						):
		UpperCamelCase						 ="encodec"
		def __init__(		self							,		UpperCamelCase_=[1.5, 3.0, 6.0, 1_2.0, 2_4.0]							,		UpperCamelCase_=2_40_00							,		UpperCamelCase_=1							,		UpperCamelCase_=False							,		UpperCamelCase_=None							,		UpperCamelCase_=None							,		UpperCamelCase_=1_28							,		UpperCamelCase_=32							,		UpperCamelCase_=1							,		UpperCamelCase_=[8, 5, 4, 2]							,		UpperCamelCase_="weight_norm"							,		UpperCamelCase_=7							,		UpperCamelCase_=7							,		UpperCamelCase_=3							,		UpperCamelCase_=2							,		UpperCamelCase_=True							,		UpperCamelCase_="reflect"							,		UpperCamelCase_=2							,		UpperCamelCase_=2							,		UpperCamelCase_=1.0							,		UpperCamelCase_=10_24							,		UpperCamelCase_=None							,		UpperCamelCase_=True							,		**UpperCamelCase_							,		)		->    List[Any]:
					__lowercase       :   Any        =    target_bandwidths
					__lowercase       :   List[Any]        =    sampling_rate
					__lowercase       :   Union[str, Any]        =    audio_channels
					__lowercase       :   Optional[int]        =    normalize
					__lowercase       :   Tuple        =    chunk_length_s
					__lowercase       :   List[Any]        =    overlap
					__lowercase       :   Optional[Any]        =    hidden_size
					__lowercase       :   Union[str, Any]        =    num_filters
					__lowercase       :   Optional[Any]        =    num_residual_layers
					__lowercase       :   Dict        =    upsampling_ratios
					__lowercase       :   List[Any]        =    norm_type
					__lowercase       :   Union[str, Any]        =    kernel_size
					__lowercase       :   List[Any]        =    last_kernel_size
					__lowercase       :   str        =    residual_kernel_size
					__lowercase       :   List[Any]        =    dilation_growth_rate
					__lowercase       :   Dict        =    use_causal_conv
					__lowercase       :   List[str]        =    pad_mode
					__lowercase       :   int        =    compress
					__lowercase       :   List[str]        =    num_lstm_layers
					__lowercase       :   List[str]        =    trim_right_ratio
					__lowercase       :   List[Any]        =    codebook_size
					__lowercase       :   List[Any]        =    codebook_dim if codebook_dim is not None else hidden_size
					__lowercase       :   Any        =    use_conv_shortcut

					if self.norm_type not in ["weight_norm", "time_group_norm"]:
								raise ValueError(
								    F"""self.norm_type must be one of `\"weight_norm\"`, `\"time_group_norm\"`), got {self.norm_type}"""    )

					super().__init__(**UpperCamelCase__    )
		@property
		def      _lowerCamelCase				(		self    )		->    int:
					if self.chunk_length_s is None:
								return None
					else:
								return int(self.chunk_length_s * self.sampling_rate    )
		@property
		def      _lowerCamelCase				(		self    )		->    Any:
					if self.chunk_length_s is None or self.overlap is None:
								return None
					else:
								return max(1							,		int((1.0 - self.overlap) * self.chunk_length    )    )
		@property
		def      _lowerCamelCase				(		self    )		->    Any:
					__lowercase       :   Union[str, Any]        =    np.prod(self.upsampling_ratios    )
					return math.ceil(self.sampling_rate / hop_length    )
		@property
		def      _lowerCamelCase				(		self    )		->    List[str]:
					return int(10_00 * self.target_bandwidths[-1] // (self.frame_rate * 10)    )











'''simple docstring'''







class _lowercase	:




							def __init__(							self:				Tuple			,							UpperCamelCase__:				list[int]     ):
														lowerCamelCase__					:	Union[str, Any]         =       len(UpperCamelCase__     )
														lowerCamelCase__					:	Union[str, Any]         =       [0] * len_array

														if len_array > 0:
																					lowerCamelCase__					:	Union[str, Any]         =       array[0]

														for i in range(1			,							UpperCamelCase__     ):
																					lowerCamelCase__					:	Tuple         =       self.prefix_sum[i - 1] + array[i]




							def 		lowerCamelCase_				(							self:				Tuple			,							UpperCamelCase__:				int			,							UpperCamelCase__:				int     ):
														if start == 0:
																					return self.prefix_sum[end]

														return self.prefix_sum[end] - self.prefix_sum[start - 1]




							def 		lowerCamelCase_				(							self:				Optional[int]			,							UpperCamelCase__:				int     ):
														lowerCamelCase__					:	Dict         =       {0}
														for sum_item in self.prefix_sum:
																					if sum_item - target_sum in sums:
																												return True

																					sums.add(UpperCamelCase__     )

														return False


if __name__ == "__main__":
			import doctest

			doctest.testmod()

