


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__   	=							{
    '''microsoft/focalnet-tiny''': '''https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json''',
}







class       lowerCamelCase__   (       lowerCAmelCase   ,							lowerCAmelCase):
     SCREAMING_SNAKE_CASE__      			=			'''focalnet'''





     def __init__(self		,     UpperCAmelCase=2_2_4		,     UpperCAmelCase=4		,     UpperCAmelCase=3		,     UpperCAmelCase=9_6		,     UpperCAmelCase=False		,     UpperCAmelCase=[1_9_2, 3_8_4, 7_6_8, 7_6_8]		,     UpperCAmelCase=[2, 2, 6, 2]		,     UpperCAmelCase=[2, 2, 2, 2]		,     UpperCAmelCase=[3, 3, 3, 3]		,     UpperCAmelCase="gelu"		,     UpperCAmelCase=4.0		,     UpperCAmelCase=0.0		,     UpperCAmelCase=0.1		,     UpperCAmelCase=False		,     UpperCAmelCase=1e-4		,     UpperCAmelCase=False		,     UpperCAmelCase=False		,     UpperCAmelCase=False		,     UpperCAmelCase=0.02		,     UpperCAmelCase=1e-5		,     UpperCAmelCase=3_2		,     UpperCAmelCase=None		,     UpperCAmelCase=None		,     **UpperCAmelCase		,     )     ->   Dict:
      super().__init__(**UpperCAmelCase       )

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





import heapq as hq
import math
from collections.abc import Iterator







class       lowerCamelCase__   :





     def __init__(self		,     UpperCAmelCase       )     ->   Any:
      _lowercase							      =str(id_       )
      _lowercase							      =None
      _lowercase							      =None
      _lowercase							      =[]
      _lowercase							      ={}  # {vertex:distance}





     def __lt__(self		,     UpperCAmelCase       )     ->   List[str]:
      return self.key < other.key





     def __repr__(self       )     ->   str:
      return self.id





     def      __A					(self		,     UpperCAmelCase       )     ->   Dict:
      self.neighbors.append(UpperCAmelCase       )





     def      __A					(self		,     UpperCAmelCase		,     UpperCAmelCase       )     ->   Optional[Any]:
      _lowercase							      =weight



def 				UpperCAmelCase_					(							__snake_case     ,						__snake_case     ,						__snake_case     ,						__snake_case						)     ->			List[str]:







 """simple docstring"""


 graph[a - 1].add_neighbor(graph[b - 1]						)
 graph[b - 1].add_neighbor(graph[a - 1]						)
 # add the edges:
 graph[a - 1].add_edge(graph[b - 1]     ,						__snake_case						)
 graph[b - 1].add_edge(graph[a - 1]     ,						__snake_case						)
def 				UpperCAmelCase_					(							__snake_case     ,						__snake_case						)     ->			list:







 """simple docstring"""


 _lowercase							      =[]
 for u in graph:
  _lowercase							      =math.inf
  _lowercase							      =None
 _lowercase							      =0
 _lowercase							      =graph[:]
 while q:
  _lowercase							      =min(__snake_case						)
  q.remove(__snake_case						)
  for v in u.neighbors:
   if (v in q) and (u.edges[v.id] < v.key):
    _lowercase							      =u
    _lowercase							      =u.edges[v.id]
 for i in range(1     ,						len(__snake_case						)						):
  a.append((int(graph[i].id						) + 1, int(graph[i].pi.id						) + 1)						)
 return a
def 				UpperCAmelCase_					(							__snake_case     ,						__snake_case						)     ->			Iterator[tuple]:







 """simple docstring"""


 for u in graph:
  _lowercase							      =math.inf
  _lowercase							      =None
 _lowercase							      =0

 _lowercase							      =list(__snake_case						)
 hq.heapify(__snake_case						)

 while h:
  _lowercase							      =hq.heappop(__snake_case						)
  for v in u.neighbors:
   if (v in h) and (u.edges[v.id] < v.key):
    _lowercase							      =u
    _lowercase							      =u.edges[v.id]
    hq.heapify(__snake_case						)

 for i in range(1     ,						len(__snake_case						)						):
  yield (int(graph[i].id						) + 1, int(graph[i].pi.id						) + 1)
def 				UpperCAmelCase_					(							)     ->			None:







 """simple docstring"""




if __name__ == "__main__":
  import doctest

  doctest.testmod()

