




from typing import Dict, Optional, Tuple

import torch






def 				UpperCAmelCase__  (							_A			):






  """simple docstring"""


  a_		    =  boundaries[1] - boundaries[0]
  a_		    =  boundaries + step / 2
  a_		    =  torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1			)]      ,      dim=0			)
  return bin_centers






def 				UpperCAmelCase__  (							_A      ,      _A      ,      ):






  """simple docstring"""


  a_		    =  _calculate_bin_centers(__lowerCAmelCase			)
  return (
      torch.sum(aligned_distance_error_probs * bin_centers      ,      dim=-1			),
      bin_centers[-1],
  )






def 				UpperCAmelCase__  (							_A      ,      _A = 31      ,      _A = 64      ,      **_A      ,      ):






  """simple docstring"""


  a_		    =  torch.linspace(0      ,      __lowerCAmelCase      ,      steps=(no_bins - 1)      ,      device=logits.device			)

  a_		    =  torch.nn.functional.softmax(__lowerCAmelCase      ,      dim=-1			)
  a_		    =  _calculate_expected_aligned_error(
      alignment_confidence_breaks=__lowerCAmelCase      ,      aligned_distance_error_probs=__lowerCAmelCase      ,      )

  return {
      "aligned_confidence_probs": aligned_confidence_probs,
      "predicted_aligned_error": predicted_aligned_error,
      "max_predicted_aligned_error": max_predicted_aligned_error,
  }






def 				UpperCAmelCase__  (							_A      ,      _A = None      ,      _A = 31      ,      _A = 64      ,      _A = 1e-8      ,      **_A      ,      ):






  """simple docstring"""


  if residue_weights is None:
    a_		    =  logits.new_ones(logits.shape[-2]			)

  a_		    =  torch.linspace(0      ,      __lowerCAmelCase      ,      steps=(no_bins - 1)      ,      device=logits.device			)

  a_		    =  _calculate_bin_centers(__lowerCAmelCase			)
  torch.sum(__lowerCAmelCase			)
  a_		    =  logits.shape[-2]
  a_		    =  max(__lowerCAmelCase      ,      19			)

  a_		    =  1.24 * (clipped_n - 15) ** (1.0 / 3) - 1.8

  a_		    =  torch.nn.functional.softmax(__lowerCAmelCase      ,      dim=-1			)

  a_		    =  1.0 / (1 + (bin_centers**2) / (da**2))
  a_		    =  torch.sum(probs * tm_per_bin      ,      dim=-1			)

  a_		    =  residue_weights / (eps + residue_weights.sum())
  a_		    =  torch.sum(predicted_tm_term * normed_residue_mask      ,      dim=-1			)

  a_		    =  per_alignment * residue_weights

  a_		    =  (weighted == torch.max(__lowerCAmelCase			)).nonzero()[0]
  return per_alignment[tuple(__lowerCAmelCase			)]

from typing import TYPE_CHECKING

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


__snake_case         =     {
    '''configuration_mobilevitv2''': [
        '''MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''MobileViTV2Config''',
        '''MobileViTV2OnnxConfig''',
    ],
}


try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __snake_case         =     [
         '''MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''MobileViTV2ForImageClassification''',
         '''MobileViTV2ForSemanticSegmentation''',
         '''MobileViTV2Model''',
         '''MobileViTV2PreTrainedModel''',
     ]

if TYPE_CHECKING:
     from .configuration_mobilevitva import (
         MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
         MobileViTVaConfig,
         MobileViTVaOnnxConfig,
     )

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_mobilevitva import (
              MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST,
              MobileViTVaForImageClassification,
              MobileViTVaForSemanticSegmentation,
              MobileViTVaModel,
              MobileViTVaPreTrainedModel,
          )

else:
     import sys

     __snake_case         =     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
