

"""simple docstring"""





from typing import Dict, Optional, Tuple

import torch




def     _A    (    UpperCamelCase_	:			torch.Tensor)      ->		torch.Tensor:
   '''simple docstring'''


   __lowercase								=		boundaries[1] - boundaries[0]
   __lowercase								=		boundaries + step / 2
   __lowercase								=		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'''


   __lowercase								=		_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 = 31,     UpperCamelCase_	:			int = 64,     **UpperCamelCase_	:			List[Any],     )      ->		Dict[str, torch.Tensor]:
   '''simple docstring'''


   __lowercase								=		torch.linspace(0,     UpperCamelCase_,     steps=(no_bins - 1),     device=logits.device)

   __lowercase								=		torch.nn.functional.softmax(UpperCamelCase_,     dim=-1)
   __lowercase						,__lowercase								=		_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 = 31,     UpperCamelCase_	:			int = 64,     UpperCamelCase_	:			float = 1E-8,     **UpperCamelCase_	:			int,     )      ->		torch.Tensor:
   '''simple docstring'''


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

   __lowercase								=		torch.linspace(0,     UpperCamelCase_,     steps=(no_bins - 1),     device=logits.device)

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

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

   __lowercase								=		torch.nn.functional.softmax(UpperCamelCase_,     dim=-1)

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

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

   __lowercase								=		per_alignment * residue_weights

   __lowercase								=		(weighted == torch.max(UpperCamelCase_)).nonzero()[0]
   return per_alignment[tuple(UpperCamelCase_)]







"""simple docstring"""





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


   if (not isinstance(UpperCamelCase_,     UpperCamelCase_)) or (digit_position <= 0):
      raise ValueError("Digit position must be a positive integer")
   elif (not isinstance(UpperCamelCase_,     UpperCamelCase_)) or (precision < 0):
      raise ValueError("Precision must be a nonnegative integer")

   # compute an approximation of (16 ** (n - 1)) * pi whose fractional part is mostly
   # accurate
   __lowercase								=		(
       4 * _subsum(UpperCamelCase_,     1,     UpperCamelCase_)
       - 2 * _subsum(UpperCamelCase_,     4,     UpperCamelCase_)
       - _subsum(UpperCamelCase_,     5,     UpperCamelCase_)
       - _subsum(UpperCamelCase_,     6,     UpperCamelCase_)
   )

   # return the first hex digit of the fractional part of the result
   return hex(int((sum_result % 1) * 16))[2:]




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


   __lowercase								=		0.0
   for sum_index in range(digit_pos_to_extract + precision):
      __lowercase								=		8 * sum_index + denominator_addend
      if sum_index < digit_pos_to_extract:
         # if the exponential term is an integer and we mod it by the denominator
         # before dividing, only the integer part of the sum will change;
         # the fractional part will not
         __lowercase								=		pow(
             16,     digit_pos_to_extract - 1 - sum_index,     UpperCamelCase_)
      else:
         __lowercase								=		pow(16,     digit_pos_to_extract - 1 - sum_index)
      total += exponential_term / denominator
   return total


if __name__ == "__main__":
   import doctest

   doctest.testmod()




