


"""simple docstring"""


from typing import Dict, Optional, Tuple

import torch






def   a__			(					__lowercase )						->						torch.Tensor:
				_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   a__			(					__lowercase  ,      __lowercase  ,      )						->						Tuple[torch.Tensor, torch.Tensor]:
				_A       	=      _calculate_bin_centers(__lowercase )
				return (
				    torch.sum(aligned_distance_error_probs * bin_centers  ,      dim=-1 ),
				    bin_centers[-1],
				)






def   a__			(					__lowercase  ,      __lowercase = 31  ,      __lowercase = 64  ,      **__lowercase  ,      )						->						Dict[str, torch.Tensor]:
				_A       	=      torch.linspace(0  ,      __lowercase  ,      steps=(no_bins - 1)  ,      device=logits.device )

				_A       	=      torch.nn.functional.softmax(__lowercase  ,      dim=-1 )
				_A	,		_A       	=      _calculate_expected_aligned_error(
				    alignment_confidence_breaks=__lowercase  ,      aligned_distance_error_probs=__lowercase  ,      )

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






def   a__			(					__lowercase  ,      __lowercase = None  ,      __lowercase = 31  ,      __lowercase = 64  ,      __lowercase = 1E-8  ,      **__lowercase  ,      )						->						torch.Tensor:
				if residue_weights is None:
								_A       	=      logits.new_ones(logits.shape[-2] )

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

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

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

				_A       	=      torch.nn.functional.softmax(__lowercase  ,      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(__lowercase )).nonzero()[0]
				return per_alignment[tuple(__lowercase )]



"""simple docstring"""


def   a__			(					__lowercase  ,      __lowercase )						->						Tuple:
				_A       	=      1
				while b > 0:
								if b & 1:
												res *= a

								a *= a
								b >>= 1

				return res






def   a__			(					__lowercase  ,      __lowercase  ,      __lowercase )						->						Optional[Any]:
				_A       	=      1
				while b > 0:
								if b & 1:
												_A       	=      ((res % c) * (a % c)) % c

								a *= a
								b >>= 1

				return res