


'''simple docstring'''






from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


__UpperCAmelCase       =							logging.get_logger(__name__)

__UpperCAmelCase       =							{
    '''shi-labs/nat-mini-in1k-224''': '''https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json''',
    # See all Nat models at https://huggingface.co/models?filter=nat
}




class 		a__    (							a__    ,    a__  ):





							'''simple docstring'''






							lowercase__      :       List[Any]     						=				"nat"

							lowercase__      :       List[str]     						=				{
							    "num_attention_heads": "num_heads",
							    "num_hidden_layers": "num_layers",
							}







							def __init__(		self ,   lowerCamelCase_=4 ,   lowerCamelCase_=3 ,   lowerCamelCase_=64 ,   lowerCamelCase_=[3, 4, 6, 5] ,   lowerCamelCase_=[2, 4, 8, 16] ,   lowerCamelCase_=7 ,   lowerCamelCase_=3.0 ,   lowerCamelCase_=True ,   lowerCamelCase_=0.0 ,   lowerCamelCase_=0.0 ,   lowerCamelCase_=0.1 ,   lowerCamelCase_="gelu" ,   lowerCamelCase_=0.02 ,   lowerCamelCase_=1e-5 ,   lowerCamelCase_=0.0 ,   lowerCamelCase_=None ,   lowerCamelCase_=None ,   **lowerCamelCase_ ,   )	->							str:
														super().__init__(**lowerCamelCase_       )

														lowerCAmelCase__	       =     patch_size
														lowerCAmelCase__	       =     num_channels
														lowerCAmelCase__	       =     embed_dim
														lowerCAmelCase__	       =     depths
														lowerCAmelCase__	       =     len(lowerCamelCase_       )
														lowerCAmelCase__	       =     num_heads
														lowerCAmelCase__	       =     kernel_size
														lowerCAmelCase__	       =     mlp_ratio
														lowerCAmelCase__	       =     qkv_bias
														lowerCAmelCase__	       =     hidden_dropout_prob
														lowerCAmelCase__	       =     attention_probs_dropout_prob
														lowerCAmelCase__	       =     drop_path_rate
														lowerCAmelCase__	       =     hidden_act
														lowerCAmelCase__	       =     layer_norm_eps
														lowerCAmelCase__	       =     initializer_range
														# we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
														# this indicates the channel dimension after the last stage of the model
														lowerCAmelCase__	       =     int(embed_dim * 2 ** (len(lowerCamelCase_       ) - 1)       )
														lowerCAmelCase__	       =     layer_scale_init_value
														lowerCAmelCase__	       =     ['''stem'''] + [F"""stage{idx}""" for idx in range(1 ,   len(lowerCamelCase_       ) + 1       )]
														lowerCAmelCase__       , lowerCAmelCase__	       =     get_aligned_output_features_output_indices(
														    out_features=lowerCamelCase_ ,   out_indices=lowerCamelCase_ ,   stage_names=self.stage_names       )



'''simple docstring'''






from __future__ import annotations




class 		a__    :





							'''simple docstring'''






							def __init__(		self ,   lowerCamelCase_       )	->							None:
														lowerCAmelCase__	       =     order

														# a_{0} ... a_{k}
														lowerCAmelCase__	       =     [1.0] + [0.0] * order
														# b_{0} ... b_{k}
														lowerCAmelCase__	       =     [1.0] + [0.0] * order

														# x[n-1] ... x[n-k]
														lowerCAmelCase__	       =     [0.0] * self.order
														# y[n-1] ... y[n-k]
														lowerCAmelCase__	       =     [0.0] * self.order







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_       )	->							None:
														if len(lowerCamelCase_       ) < self.order:
																					lowerCAmelCase__	       =     [1.0, *a_coeffs]

														if len(lowerCamelCase_       ) != self.order + 1:
																					lowerCAmelCase__	       =     (
																					    F"""Expected a_coeffs to have {self.order + 1} elements """
																					    F"""for {self.order}-order filter, got {len(lowerCamelCase_       )}"""
																					)
																					raise ValueError(lowerCamelCase_       )

														if len(lowerCamelCase_       ) != self.order + 1:
																					lowerCAmelCase__	       =     (
																					    F"""Expected b_coeffs to have {self.order + 1} elements """
																					    F"""for {self.order}-order filter, got {len(lowerCamelCase_       )}"""
																					)
																					raise ValueError(lowerCamelCase_       )

														lowerCAmelCase__	       =     a_coeffs
														lowerCAmelCase__	       =     b_coeffs







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_       )	->							float:
														lowerCAmelCase__	       =     0.0

														# Start at index 1 and do index 0 at the end.
														for i in range(1 ,   self.order + 1       ):
																					result += (
																					    self.b_coeffs[i] * self.input_history[i - 1]
																					    - self.a_coeffs[i] * self.output_history[i - 1]
																					)

														lowerCAmelCase__	       =     (result + self.b_coeffs[0] * sample) / self.a_coeffs[0]

														lowerCAmelCase__	       =     self.input_history[:-1]
														lowerCAmelCase__	       =     self.output_history[:-1]

														lowerCAmelCase__	       =     sample
														lowerCAmelCase__	       =     result

														return result