


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


snake_case							: List[str]      =   logging.get_logger(__name__)

snake_case							: str      =   {
    '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  snake_case_     (__lowercase			,		__lowercase   ):
     UpperCAmelCase__      :					Any					   =    '''nat'''

     UpperCAmelCase__      :					List[str]					   =    {
         '''num_attention_heads''': '''num_heads''',
         '''num_hidden_layers''': '''num_layers''',
     }
     def __init__(   self     :Optional[Any]    ,__snake_case     :int=4    ,__snake_case     :Union[str, Any]=3    ,__snake_case     :Optional[int]=64    ,__snake_case     :Optional[int]=[3, 4, 6, 5]    ,__snake_case     :Optional[int]=[2, 4, 8, 16]    ,__snake_case     :Union[str, Any]=7    ,__snake_case     :Tuple=3.0    ,__snake_case     :str=True    ,__snake_case     :Tuple=0.0    ,__snake_case     :Any=0.0    ,__snake_case     :Dict=0.1    ,__snake_case     :List[Any]="gelu"    ,__snake_case     :List[Any]=0.02    ,__snake_case     :Dict=1E-5    ,__snake_case     :Union[str, Any]=0.0    ,__snake_case     :Optional[int]=None    ,__snake_case     :List[str]=None    ,**__snake_case     :Tuple    ,)      ->					List[str]:
            super().__init__(**__a   )

            a__    =  patch_size
            a__    =  num_channels
            a__    =  embed_dim
            a__    =  depths
            a__    =  len(__a   )
            a__    =  num_heads
            a__    =  kernel_size
            a__    =  mlp_ratio
            a__    =  qkv_bias
            a__    =  hidden_dropout_prob
            a__    =  attention_probs_dropout_prob
            a__    =  drop_path_rate
            a__    =  hidden_act
            a__    =  layer_norm_eps
            a__    =  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
            a__    =  int(embed_dim * 2 ** (len(__a   ) - 1)   )
            a__    =  layer_scale_init_value
            a__    =  ["""stem"""] + [F'stage{idx}' for idx in range(1    ,len(__a   ) + 1   )]
            a__    =  get_aligned_output_features_output_indices(
                out_features=__a    ,out_indices=__a    ,stage_names=self.stage_names   )








def 							__lowercase     (				__lowerCAmelCase							:       int     ):
							a__    =  generate_pascal_triangle(__lowerCAmelCase     )
							for row_idx in range(__lowerCAmelCase     ):
														# Print left spaces
														for _ in range(num_rows - row_idx - 1     ):
																					print(end=' '     )
														# Print row values
														for col_idx in range(row_idx + 1     ):
																					if col_idx != row_idx:
																												print(triangle[row_idx][col_idx]      ,					end=' '     )
																					else:
																												print(triangle[row_idx][col_idx]      ,					end=''     )
														print()






def 							__lowercase     (				__lowerCAmelCase							:       int     ):

							if not isinstance(__lowerCAmelCase      ,					__lowerCAmelCase     ):
														raise TypeError('The input value of \'num_rows\' should be \'int\''     )

							if num_rows == 0:
														return []
							elif num_rows < 0:
														raise ValueError(
														    'The input value of \'num_rows\' should be greater than or equal to 0'     )

							a__    =  []
							for current_row_idx in range(__lowerCAmelCase     ):
														a__    =  populate_current_row(__lowerCAmelCase      ,					__lowerCAmelCase     )
														triangle.append(__lowerCAmelCase     )
							return triangle






def 							__lowercase     (				__lowerCAmelCase							:       list[list[int]]      ,					__lowerCAmelCase							:       int     ):
							a__    =  [-1] * (current_row_idx + 1)
							# first and last elements of current row are equal to 1
							a__   ,      a__    =  1, 1
							for current_col_idx in range(1      ,					__lowerCAmelCase     ):
														calculate_current_element(
														    __lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase     )
							return current_row






def 							__lowercase     (				__lowerCAmelCase							:       list[list[int]]      ,					__lowerCAmelCase							:       list[int]      ,					__lowerCAmelCase							:       int      ,					__lowerCAmelCase							:       int      ,					):
							a__    =  triangle[current_row_idx - 1][current_col_idx - 1]
							a__    =  triangle[current_row_idx - 1][current_col_idx]
							a__    =  above_to_left_elt + above_to_right_elt






def 							__lowercase     (				__lowerCAmelCase							:       int     ):

							if not isinstance(__lowerCAmelCase      ,					__lowerCAmelCase     ):
														raise TypeError('The input value of \'num_rows\' should be \'int\''     )

							if num_rows == 0:
														return []
							elif num_rows < 0:
														raise ValueError(
														    'The input value of \'num_rows\' should be greater than or equal to 0'     )

							a__    =  [[1]]

							for row_index in range(1      ,					__lowerCAmelCase     ):
														a__    =  [0] + result[-1] + [0]
														a__    =  row_index + 1
														# Calculate the number of distinct elements in a row
														a__    =  sum(divmod(__lowerCAmelCase      ,					2     )     )
														a__    =  [
														    temp_row[i - 1] + temp_row[i] for i in range(1      ,					distinct_elements + 1     )
														]
														a__    =  row_first_half[: (row_index + 1) // 2]
														row_second_half.reverse()
														a__    =  row_first_half + row_second_half
														result.append(__lowerCAmelCase     )

							return result






def 							__lowercase     (				):
							from collections.abc import Callable
							from timeit import timeit

							def benchmark_a_function(__lowerCAmelCase							:       Callable      ,					__lowerCAmelCase							:       int     ) -> None:
														a__    =  F'{func.__name__}({value})'
														a__    =  timeit(F'__main__.{call}'      ,					setup='import __main__'     )
														# print(f"{call:38} = {func(value)} -- {timing:.4f} seconds")
														print(F'{call:38} -- {timing:.4f} seconds'     )

							for value in range(1_5     ):  # (1, 7, 14):
														for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
																					benchmark_a_function(__lowerCAmelCase      ,					__lowerCAmelCase     )
														print()


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						benchmark()




