



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


lowerCamelCase__			= logging.get_logger(__name__)

lowerCamelCase__			= {
    """microsoft/focalnet-tiny""": """https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json""",
}






class    SCREAMING_SNAKE_CASE			(							lowerCamelCase__			,      lowerCamelCase__					):

							'''simple docstring'''





							__lowerCamelCase	:	Any    ='focalnet'





							def __init__(   self		:		Tuple      ,				__lowercase		:		int=224      ,				__lowercase		:		Union[str, Any]=4      ,				__lowercase		:		List[str]=3      ,				__lowercase		:		Tuple=96      ,				__lowercase		:		Any=False      ,				__lowercase		:		List[str]=[192, 384, 768, 768]      ,				__lowercase		:		List[str]=[2, 2, 6, 2]      ,				__lowercase		:		List[Any]=[2, 2, 2, 2]      ,				__lowercase		:		Any=[3, 3, 3, 3]      ,				__lowercase		:		Union[str, Any]="gelu"      ,				__lowercase		:		Optional[Any]=4.0      ,				__lowercase		:		List[Any]=0.0      ,				__lowercase		:		List[str]=0.1      ,				__lowercase		:		Optional[Any]=False      ,				__lowercase		:		int=1E-4      ,				__lowercase		:		Optional[int]=False      ,				__lowercase		:		Optional[Any]=False      ,				__lowercase		:		List[str]=False      ,				__lowercase		:		Union[str, Any]=0.02      ,				__lowercase		:		int=1E-5      ,				__lowercase		:		str=32      ,				__lowercase		:		Optional[Any]=None      ,				__lowercase		:		List[str]=None      ,				**__lowercase		:		Any      ,				):

											'''simple docstring'''
											super().__init__(**__lowercase	)

											__a       =		image_size
											__a       =		patch_size
											__a       =		num_channels
											__a       =		embed_dim
											__a       =		use_conv_embed
											__a       =		hidden_sizes
											__a       =		depths
											__a       =		focal_levels
											__a       =		focal_windows
											__a       =		hidden_act
											__a       =		mlp_ratio
											__a       =		hidden_dropout_prob
											__a       =		drop_path_rate
											__a       =		use_layerscale
											__a       =		layerscale_value
											__a       =		use_post_layernorm
											__a       =		use_post_layernorm_in_modulation
											__a       =		normalize_modulator
											__a       =		initializer_range
											__a       =		layer_norm_eps
											__a       =		encoder_stride
											__a       =		["""stem"""] + [F"stage{idx}" for idx in range(1      ,				len(self.depths	) + 1	)]
											__a     ,					__a       =		get_aligned_output_features_output_indices(
											    out_features=__lowercase      ,				out_indices=__lowercase      ,				stage_names=self.stage_names	)





import itertools
import string
from collections.abc import Generator, Iterable

def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			Iterable[str]				,     _SCREAMING_SNAKE_CASE       :			int    ):
				"""simple docstring"""







				__a       =		iter(_SCREAMING_SNAKE_CASE    )
				while True:
								__a       =		tuple(itertools.islice(_SCREAMING_SNAKE_CASE				,     _SCREAMING_SNAKE_CASE    )    )
								if not chunk:
												return
								yield chunk

def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			str    ):
				"""simple docstring"""







				__a       =		"""""".join([c.upper() for c in dirty if c in string.ascii_letters]    )
				__a       =		""""""

				if len(_SCREAMING_SNAKE_CASE    ) < 2:
								return dirty

				for i in range(len(_SCREAMING_SNAKE_CASE    ) - 1    ):
								clean += dirty[i]

								if dirty[i] == dirty[i + 1]:
												clean += "X"

				clean += dirty[-1]

				if len(_SCREAMING_SNAKE_CASE    ) & 1:
								clean += "X"

				return clean

def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			str    ):
				"""simple docstring"""







				__a       =		"""ABCDEFGHIKLMNOPQRSTUVWXYZ"""
				# we're using a list instead of a '2d' array because it makes the math
				# for setting up the table and doing the actual encoding/decoding simpler
				__a       =		[]

				# copy key chars into the table if they are in `alphabet` ignoring duplicates
				for char in key.upper():
								if char not in table and char in alphabet:
												table.append(_SCREAMING_SNAKE_CASE    )

    # fill the rest of the table in with the remaining alphabet chars
				for char in alphabet:
								if char not in table:
												table.append(_SCREAMING_SNAKE_CASE    )

				return table

def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			str				,     _SCREAMING_SNAKE_CASE       :			str    ):
				"""simple docstring"""







				__a       =		generate_table(_SCREAMING_SNAKE_CASE    )
				__a       =		prepare_input(_SCREAMING_SNAKE_CASE    )
				__a       =		""""""

				# https://en.wikipedia.org/wiki/Playfair_cipher#Description
				for chara, chara in chunker(_SCREAMING_SNAKE_CASE				,     2    ):
								__a     ,					__a       =		divmod(table.index(_SCREAMING_SNAKE_CASE    )				,     5    )
								__a     ,					__a       =		divmod(table.index(_SCREAMING_SNAKE_CASE    )				,     5    )

								if rowa == rowa:
												ciphertext += table[rowa * 5 + (cola + 1) % 5]
												ciphertext += table[rowa * 5 + (cola + 1) % 5]
								elif cola == cola:
												ciphertext += table[((rowa + 1) % 5) * 5 + cola]
												ciphertext += table[((rowa + 1) % 5) * 5 + cola]
								else:  # rectangle
												ciphertext += table[rowa * 5 + cola]
												ciphertext += table[rowa * 5 + cola]

				return ciphertext

def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			str				,     _SCREAMING_SNAKE_CASE       :			str    ):
				"""simple docstring"""







				__a       =		generate_table(_SCREAMING_SNAKE_CASE    )
				__a       =		""""""

				# https://en.wikipedia.org/wiki/Playfair_cipher#Description
				for chara, chara in chunker(_SCREAMING_SNAKE_CASE				,     2    ):
								__a     ,					__a       =		divmod(table.index(_SCREAMING_SNAKE_CASE    )				,     5    )
								__a     ,					__a       =		divmod(table.index(_SCREAMING_SNAKE_CASE    )				,     5    )

								if rowa == rowa:
												plaintext += table[rowa * 5 + (cola - 1) % 5]
												plaintext += table[rowa * 5 + (cola - 1) % 5]
								elif cola == cola:
												plaintext += table[((rowa - 1) % 5) * 5 + cola]
												plaintext += table[((rowa - 1) % 5) * 5 + cola]
								else:  # rectangle
												plaintext += table[rowa * 5 + cola]
												plaintext += table[rowa * 5 + cola]

				return plaintext
