



'''simple docstring'''






from functools import partial
from typing import Any, Callable, Dict, List, Type, TypeVar, Union, overload

import torch
import torch.nn as nn
import torch.types




def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_	)->	torch.Tensor:





							'''simple docstring'''


							if not inplace:
														_UpperCAmelCase						:		Any      =				ma + ma
							else:
														ma += ma

							return ma




def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_	)->	torch.Tensor:





							'''simple docstring'''


							_UpperCAmelCase						:		Union[str, Any]      =				-1 * len(lowerCAmelCase_	)
							_UpperCAmelCase						:		List[str]      =				list(range(len(tensor.shape[:zero_index]	)	)	)
							return tensor.permute(first_inds + [zero_index + i for i in inds]	)




def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_	)->	torch.Tensor:





							'''simple docstring'''


							return t.reshape(t.shape[:-no_dims] + (-1,)	)




def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_ = 1e-4	)->	torch.Tensor:





							'''simple docstring'''


							_UpperCAmelCase						:		Tuple      =				mask.expand(*value.shape	)
							return torch.sum(mask * value ,     dim=lowerCAmelCase_	) / (eps + torch.sum(lowerCAmelCase_ ,     dim=lowerCAmelCase_	))




def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_ = 2.3_1_2_5 ,     lowerCAmelCase_ = 21.6875 ,     lowerCAmelCase_ = 64	)->	torch.Tensor:





							'''simple docstring'''


							_UpperCAmelCase						:		Optional[int]      =				torch.linspace(lowerCAmelCase_ ,     lowerCAmelCase_ ,     no_bins - 1 ,     device=pts.device	)
							_UpperCAmelCase						:		str      =				torch.sqrt(torch.sum((pts.unsqueeze(-2	) - pts.unsqueeze(-3	)) ** 2 ,     dim=-1	)	)
							return torch.bucketize(lowerCAmelCase_ ,     lowerCAmelCase_	)




def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_	)->	dict:





							'''simple docstring'''


							_UpperCAmelCase						:		str      =				dicts[0]
							_UpperCAmelCase						:		List[str]      =				{}
							for k, v in first.items():
														_UpperCAmelCase						:		Optional[Any]      =				[d[k] for d in dicts]
														if isinstance(lowerCAmelCase_ ,     lowerCAmelCase_	):
																					_UpperCAmelCase						:		List[Any]      =				dict_multimap(lowerCAmelCase_ ,     lowerCAmelCase_	)
														else:
																					_UpperCAmelCase						:		Optional[Any]      =				fn(lowerCAmelCase_	)

							return new_dict




def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_	)->	torch.Tensor:





							'''simple docstring'''


							_UpperCAmelCase						:		List[Any]      =				v_bins.view(((1,) * len(x.shape	)) + (len(lowerCAmelCase_	),)	)
							_UpperCAmelCase						:		Optional[int]      =				x[..., None] - reshaped_bins
							_UpperCAmelCase						:		Tuple      =				torch.argmin(torch.abs(lowerCAmelCase_	) ,     dim=-1	)
							return nn.functional.one_hot(lowerCAmelCase_ ,     num_classes=len(lowerCAmelCase_	)	).float()




def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_ = 0 ,     lowerCAmelCase_ = 0	)->	torch.Tensor:





							'''simple docstring'''


							_UpperCAmelCase						:		List[Union[slice, torch.Tensor]]      =				[]
							for i, s in enumerate(data.shape[:no_batch_dims]	):
														_UpperCAmelCase						:		int      =				torch.arange(lowerCAmelCase_	)
														_UpperCAmelCase						:		Optional[Any]      =				r.view(*(*((1,) * i), -1, *((1,) * (len(inds.shape	) - i - 1)))	)
														ranges.append(lowerCAmelCase_	)

							_UpperCAmelCase						:		List[Union[slice, torch.Tensor]]      =				[slice(lowerCAmelCase_	) for _ in range(len(data.shape	) - no_batch_dims	)]
							_UpperCAmelCase						:		Tuple      =				inds
							ranges.extend(lowerCAmelCase_	)
							# Matt note: Editing this to get around the behaviour of using a list as an array index changing
							# in recent Numpy versions
							return data[tuple(lowerCAmelCase_	)]


A_							:				Optional[int]						=			TypeVar("""T""")




def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_	)->	Dict[Any, Union[dict, list, tuple, Any]]:





							'''simple docstring'''


							_UpperCAmelCase						:		Dict[Any, Union[dict, list, tuple, Any]]      =				{}
							for k, v in dic.items():
														if isinstance(lowerCAmelCase_ ,     lowerCAmelCase_	):
																					_UpperCAmelCase						:		int      =				dict_map(lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_	)
														else:
																					_UpperCAmelCase						:		str      =				tree_map(lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_	)

							return new_dict




@overload
def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_	)->	Any:





							'''simple docstring'''


							...




@overload
def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_	)->	dict:





							'''simple docstring'''


							...




@overload
def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_	)->	list:





							'''simple docstring'''


							...




@overload
def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_	)->	tuple:





							'''simple docstring'''


							...




def 					snake_case_      (  lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_	)->	List[Any]:





							'''simple docstring'''


							if isinstance(lowerCAmelCase_ ,     lowerCAmelCase_	):
														return dict_map(lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_	)
							elif isinstance(lowerCAmelCase_ ,     lowerCAmelCase_	):
														return [tree_map(lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_	) for x in tree]
							elif isinstance(lowerCAmelCase_ ,     lowerCAmelCase_	):
														return tuple(tree_map(lowerCAmelCase_ ,     lowerCAmelCase_ ,     lowerCAmelCase_	) for x in tree	)
							elif isinstance(lowerCAmelCase_ ,     lowerCAmelCase_	):
														return fn(lowerCAmelCase_	)
							else:
														print(type(lowerCAmelCase_	)	)
														raise ValueError("""Not supported"""	)
A_							:				List[str]						=			partial(tree_map, leaf_type=torch.Tensor)








'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


A_							:				Union[str, Any]						=			{
    """configuration_segformer""": ["""SEGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""", """SegformerConfig""", """SegformerOnnxConfig"""]
}

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_							:				Tuple						=			["""SegformerFeatureExtractor"""]
   A_							:				Tuple						=			["""SegformerImageProcessor"""]

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_							:				Dict						=			[
       """SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """SegformerDecodeHead""",
       """SegformerForImageClassification""",
       """SegformerForSemanticSegmentation""",
       """SegformerLayer""",
       """SegformerModel""",
       """SegformerPreTrainedModel""",
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_							:				List[str]						=			[
       """TF_SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """TFSegformerDecodeHead""",
       """TFSegformerForImageClassification""",
       """TFSegformerForSemanticSegmentation""",
       """TFSegformerModel""",
       """TFSegformerPreTrainedModel""",
   ]


if TYPE_CHECKING:
   from .configuration_segformer import SEGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, SegformerConfig, SegformerOnnxConfig

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .feature_extraction_segformer import SegformerFeatureExtractor
      from .image_processing_segformer import SegformerImageProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_segformer import (
          SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
          SegformerDecodeHead,
          SegformerForImageClassification,
          SegformerForSemanticSegmentation,
          SegformerLayer,
          SegformerModel,
          SegformerPreTrainedModel,
      )
   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_segformer import (
          TF_SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFSegformerDecodeHead,
          TFSegformerForImageClassification,
          TFSegformerForSemanticSegmentation,
          TFSegformerModel,
          TFSegformerPreTrainedModel,
      )

else:
   import sys

   A_							:				Optional[Any]						=			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



