






"""simple docstring"""



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


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

__A		:       List[str]  				=		{
    '''microsoft/focalnet-tiny''': '''https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json''',
}





class 					_UpperCAmelCase       ( _A   ,						_A							):
					SCREAMING_SNAKE_CASE_		:				str							    =   "focalnet"




					def __init__(				self     :						Tuple    ,						A     :						Tuple=2_24    ,						A     :						Tuple=4    ,						A     :						Union[str, Any]=3    ,						A     :						Optional[Any]=96    ,						A     :						List[Any]=False    ,						A     :						int=[1_92, 3_84, 7_68, 7_68]    ,						A     :						Tuple=[2, 2, 6, 2]    ,						A     :						Union[str, Any]=[2, 2, 2, 2]    ,						A     :						int=[3, 3, 3, 3]    ,						A     :						Optional[int]="gelu"    ,						A     :						Optional[Any]=4.0    ,						A     :						Optional[Any]=0.0    ,						A     :						Any=0.1    ,						A     :						Optional[int]=False    ,						A     :						Any=1e-4    ,						A     :						Optional[int]=False    ,						A     :						List[Any]=False    ,						A     :						Dict=False    ,						A     :						Dict=0.02    ,						A     :						Optional[Any]=1e-5    ,						A     :						Tuple=32    ,						A     :						Dict=None    ,						A     :						int=None    ,						**A     :						List[str]    ,						)  ->  Union[str, Any]:
							super().__init__(**A   )

							lowercase_ : Dict							       =   image_size
							lowercase_ : int							       =   patch_size
							lowercase_ : List[str]							       =   num_channels
							lowercase_ : Union[str, Any]							       =   embed_dim
							lowercase_ : Union[str, Any]							       =   use_conv_embed
							lowercase_ : List[Any]							       =   hidden_sizes
							lowercase_ : Union[str, Any]							       =   depths
							lowercase_ : Tuple							       =   focal_levels
							lowercase_ : List[Any]							       =   focal_windows
							lowercase_ : Optional[Any]							       =   hidden_act
							lowercase_ : List[Any]							       =   mlp_ratio
							lowercase_ : Any							       =   hidden_dropout_prob
							lowercase_ : str							       =   drop_path_rate
							lowercase_ : int							       =   use_layerscale
							lowercase_ : List[Any]							       =   layerscale_value
							lowercase_ : Optional[Any]							       =   use_post_layernorm
							lowercase_ : List[Any]							       =   use_post_layernorm_in_modulation
							lowercase_ : int							       =   normalize_modulator
							lowercase_ : Tuple							       =   initializer_range
							lowercase_ : Tuple							       =   layer_norm_eps
							lowercase_ : Tuple							       =   encoder_stride
							lowercase_ : Union[str, Any]							       =   ['''stem'''] + [F'''stage{idx}''' for idx in range(1    ,						len(self.depths   ) + 1   )]
							lowercase_       ,					lowercase_ : Optional[int]							       =   get_aligned_output_features_output_indices(
							    out_features=A    ,						out_indices=A    ,						stage_names=self.stage_names   )











"""simple docstring"""



def 						lowercase    (				__snake_case				: Optional[int]	):
		lowercase_ : int							       =   0
		lowercase_ : Optional[Any]							       =   len(__snake_case	)

		for i in range(n - 1	):
				for j in range(i + 1		,					__snake_case	):
						if arr[i] > arr[j]:
								num_inversions += 1

		return num_inversions



def 						lowercase    (				__snake_case				: str	):
		if len(__snake_case	) <= 1:
				return arr, 0
		lowercase_ : Optional[Any]							       =   len(__snake_case	) // 2
		lowercase_ : List[Any]							       =   arr[0:mid]
		lowercase_ : Union[str, Any]							       =   arr[mid:]

		lowercase_       ,					lowercase_ : Tuple							       =   count_inversions_recursive(__snake_case	)
		lowercase_       ,					lowercase_ : List[Any]							       =   count_inversions_recursive(__snake_case	)
		lowercase_       ,					lowercase_ : List[Any]							       =   _count_cross_inversions(__snake_case		,					__snake_case	)

		lowercase_ : List[Any]							       =   inversion_p + inversions_q + cross_inversions
		return c, num_inversions



def 						lowercase    (				__snake_case				: str		,					__snake_case				: Optional[int]	):
		lowercase_ : Optional[Any]							       =   []
		lowercase_ : Any							       =   0
		while i < len(__snake_case	) and j < len(__snake_case	):
				if p[i] > q[j]:
						# if P[1] > Q[j], then P[k] > Q[k] for all  i < k <= len(P)
						# These are all inversions. The claim emerges from the
						# property that P is sorted.
						num_inversion += len(__snake_case	) - i
						r.append(q[j]	)
						j += 1
				else:
						r.append(p[i]	)
						i += 1

		if i < len(__snake_case	):
				r.extend(p[i:]	)
		else:
				r.extend(q[j:]	)

		return r, num_inversion



def 						lowercase    (				):
		lowercase_ : Union[str, Any]							       =   [1_0, 2, 1, 5, 5, 2, 1_1]

		# this arr has 8 inversions:
		# (10, 2), (10, 1), (10, 5), (10, 5), (10, 2), (2, 1), (5, 2), (5, 2)

		lowercase_ : int							       =   count_inversions_bf(__snake_case	)
		lowercase_       ,					lowercase_ : Dict							       =   count_inversions_recursive(__snake_case	)

		assert num_inversions_bf == num_inversions_recursive == 8

		print('''number of inversions = '''		,					__snake_case	)

		# testing an array with zero inversion (a sorted arr_1)

		arr_a.sort()
		lowercase_ : Dict							       =   count_inversions_bf(__snake_case	)
		lowercase_       ,					lowercase_ : Dict							       =   count_inversions_recursive(__snake_case	)

		assert num_inversions_bf == num_inversions_recursive == 0
		print('''number of inversions = '''		,					__snake_case	)

		# an empty list should also have zero inversions
		lowercase_ : List[Any]							       =   []
		lowercase_ : Any							       =   count_inversions_bf(__snake_case	)
		lowercase_       ,					lowercase_ : List[str]							       =   count_inversions_recursive(__snake_case	)

		assert num_inversions_bf == num_inversions_recursive == 0
		print('''number of inversions = '''		,					__snake_case	)


if __name__ == "__main__":
						main()



