





"""simple docstring"""




from typing import Dict, Optional, Tuple

import torch





def 						UpperCAmelCase__		(					_UpperCAmelCase ):






  """simple docstring"""





  A_  :	Optional[Any]    						=  boundaries[1] - boundaries[0]
  A_  :	Any    						=  boundaries + step / 2
  A_  :	Dict    						=  torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1 )]			, dim=0 )
  return bin_centers





def 						UpperCAmelCase__		(					_UpperCAmelCase			, _UpperCAmelCase			, ):






  """simple docstring"""





  A_  :	Any    						=  _calculate_bin_centers(_UpperCAmelCase )
  return (
      torch.sum(aligned_distance_error_probs * bin_centers			, dim=-1 ),
      bin_centers[-1],
  )





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






  """simple docstring"""





  A_  :	int    						=  torch.linspace(0			, _UpperCAmelCase			, steps=(no_bins - 1)			, device=logits.device )

  A_  :	List[str]    						=  torch.nn.functional.softmax(_UpperCAmelCase			, dim=-1 )
  A_						,	A_  :	Dict    						=  _calculate_expected_aligned_error(
      alignment_confidence_breaks=_UpperCAmelCase			, aligned_distance_error_probs=_UpperCAmelCase			, )

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





def 						UpperCAmelCase__		(					_UpperCAmelCase			, _UpperCAmelCase = None			, _UpperCAmelCase = 31			, _UpperCAmelCase = 64			, _UpperCAmelCase = 1E-8			, **_UpperCAmelCase			, ):






  """simple docstring"""





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

  A_  :	Optional[int]    						=  torch.linspace(0			, _UpperCAmelCase			, steps=(no_bins - 1)			, device=logits.device )

  A_  :	Dict    						=  _calculate_bin_centers(_UpperCAmelCase )
  torch.sum(_UpperCAmelCase )
  A_  :	Tuple    						=  logits.shape[-2]
  A_  :	Any    						=  max(_UpperCAmelCase			, 19 )

  A_  :	int    						=  1.24 * (clipped_n - 15) ** (1.0 / 3) - 1.8

  A_  :	Union[str, Any]    						=  torch.nn.functional.softmax(_UpperCAmelCase			, dim=-1 )

  A_  :	Tuple    						=  1.0 / (1 + (bin_centers**2) / (da**2))
  A_  :	Optional[int]    						=  torch.sum(probs * tm_per_bin			, dim=-1 )

  A_  :	str    						=  residue_weights / (eps + residue_weights.sum())
  A_  :	Union[str, Any]    						=  torch.sum(predicted_tm_term * normed_residue_mask			, dim=-1 )

  A_  :	Union[str, Any]    						=  per_alignment * residue_weights

  A_  :	Optional[int]    						=  (weighted == torch.max(_UpperCAmelCase )).nonzero()[0]
  return per_alignment[tuple(_UpperCAmelCase )]






"""simple docstring"""




# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

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


lowerCamelCase_					:						Any      = {
    'configuration_tvlt': ['TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'TvltConfig'],
    'feature_extraction_tvlt': ['TvltFeatureExtractor'],
    'processing_tvlt': ['TvltProcessor'],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCamelCase_					:						Union[str, Any]      = [
       'TVLT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'TvltModel',
       'TvltForPreTraining',
       'TvltForAudioVisualClassification',
       'TvltPreTrainedModel',
   ]

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCamelCase_					:						List[Any]      = ['TvltImageProcessor']


if TYPE_CHECKING:
   from .configuration_tvlt import TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP, TvltConfig
   from .processing_tvlt import TvltProcessor
   from .feature_extraction_tvlt import TvltFeatureExtractor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tvlt import (
          TVLT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TvltForAudioVisualClassification,
          TvltForPreTraining,
          TvltModel,
          TvltPreTrainedModel,
      )

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .image_processing_tvlt import TvltImageProcessor


else:
   import sys

   lowerCamelCase_					:						Optional[int]      = _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)