





'''simple docstring'''


from typing import Dict, Optional, Tuple

import torch




def       A							(      _UpperCAmelCase   :				torch.Tensor					)  ->				torch.Tensor:


  '''simple docstring'''




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




def       A							(      _UpperCAmelCase   :				torch.Tensor						,_UpperCAmelCase   :				torch.Tensor						,)  ->				Tuple[torch.Tensor, torch.Tensor]:


  '''simple docstring'''




  __lowerCAmelCase		:    Optional[int]			     =  _calculate_bin_centers(UpperCamelCase_					)
  return (
      torch.sum(aligned_distance_error_probs * bin_centers						,dim=-1					),
      bin_centers[-1],
  )




def       A							(      _UpperCAmelCase   :				torch.Tensor						,_UpperCAmelCase   :				int = 3_1						,_UpperCAmelCase   :				int = 6_4						,**_UpperCAmelCase   :				List[Any]						,)  ->				Dict[str, torch.Tensor]:


  '''simple docstring'''




  __lowerCAmelCase		:    List[Any]			     =  torch.linspace(0						,UpperCamelCase_						,steps=(no_bins - 1)						,device=logits.device					)

  __lowerCAmelCase		:    List[str]			     =  torch.nn.functional.softmax(UpperCamelCase_						,dim=-1					)
  __lowerCAmelCase     ,					__lowerCAmelCase		:    Optional[Any]			     =  _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       A							(      _UpperCAmelCase   :				torch.Tensor						,_UpperCAmelCase   :				Optional[torch.Tensor] = None						,_UpperCAmelCase   :				int = 3_1						,_UpperCAmelCase   :				int = 6_4						,_UpperCAmelCase   :				float = 1e-8						,**_UpperCAmelCase   :				int						,)  ->				torch.Tensor:


  '''simple docstring'''




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

  __lowerCAmelCase		:    List[str]			     =  torch.linspace(0						,UpperCamelCase_						,steps=(no_bins - 1)						,device=logits.device					)

  __lowerCAmelCase		:    Any			     =  _calculate_bin_centers(UpperCamelCase_					)
  torch.sum(UpperCamelCase_					)
  __lowerCAmelCase		:    Any			     =  logits.shape[-2]
  __lowerCAmelCase		:    List[Any]			     =  max(UpperCamelCase_						,1_9					)

  __lowerCAmelCase		:    Any			     =  1.24 * (clipped_n - 1_5) ** (1.0 / 3) - 1.8

  __lowerCAmelCase		:    Optional[Any]			     =  torch.nn.functional.softmax(UpperCamelCase_						,dim=-1					)

  __lowerCAmelCase		:    Dict			     =  1.0 / (1 + (bin_centers**2) / (da**2))
  __lowerCAmelCase		:    str			     =  torch.sum(probs * tm_per_bin						,dim=-1					)

  __lowerCAmelCase		:    List[Any]			     =  residue_weights / (eps + residue_weights.sum())
  __lowerCAmelCase		:    int			     =  torch.sum(predicted_tm_term * normed_residue_mask						,dim=-1					)

  __lowerCAmelCase		:    str			     =  per_alignment * residue_weights

  __lowerCAmelCase		:    Union[str, Any]			     =  (weighted == torch.max(UpperCamelCase_					)).nonzero()[0]
  return per_alignment[tuple(UpperCamelCase_					)]








"""simple docstring"""





def     _A    (    UpperCamelCase_	:			str)      ->		int:
   '''simple docstring'''


   __lowercase								=		0
   for plain_chr in plain_text:
      __lowercase								=		(
          ord(UpperCamelCase_) + (hash_value << 6) + (hash_value << 16) - hash_value
      )
   return hash_value




