
"""simple docstring"""
from typing import Dict, Optional, Tuple

import torch


def     lowerCamelCase_    (	lowerCamelCase_ )     ->			torch.Tensor:


					'''simple docstring'''
					__a:						List[str]		    =					boundaries[1] - boundaries[0]
					__a:						Dict		    =					boundaries + step / 2
					__a:						Tuple		    =					torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1 )]	,				dim=0 )
					return bin_centers


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


					'''simple docstring'''
					__a:						Dict		    =					_calculate_bin_centers(lowerCamelCase_ )
					return (
					    torch.sum(aligned_distance_error_probs * bin_centers	,				dim=-1 ),
					    bin_centers[-1],
					)


def     lowerCamelCase_    (	lowerCamelCase_	,				lowerCamelCase_ = 31	,				lowerCamelCase_ = 64	,				**lowerCamelCase_	,				)     ->			Dict[str, torch.Tensor]:


					'''simple docstring'''
					__a:						str		    =					torch.linspace(0	,				lowerCamelCase_	,				steps=(no_bins - 1)	,				device=logits.device )

					__a:						Union[str, Any]		    =					torch.nn.functional.softmax(lowerCamelCase_	,				dim=-1 )
					__a    ,				__a:						str		    =					_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     lowerCamelCase_    (	lowerCamelCase_	,				lowerCamelCase_ = None	,				lowerCamelCase_ = 31	,				lowerCamelCase_ = 64	,				lowerCamelCase_ = 1e-8	,				**lowerCamelCase_	,				)     ->			torch.Tensor:


					'''simple docstring'''
					if residue_weights is None:
										__a:						str		    =					logits.new_ones(logits.shape[-2] )

					__a:						str		    =					torch.linspace(0	,				lowerCamelCase_	,				steps=(no_bins - 1)	,				device=logits.device )

					__a:						int		    =					_calculate_bin_centers(lowerCamelCase_ )
					torch.sum(lowerCamelCase_ )
					__a:						Any		    =					logits.shape[-2]
					__a:						Any		    =					max(lowerCamelCase_	,				19 )

					__a:						Tuple		    =					1.24 * (clipped_n - 15) ** (1.0 / 3) - 1.8

					__a:						str		    =					torch.nn.functional.softmax(lowerCamelCase_	,				dim=-1 )

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

					__a:						Dict		    =					residue_weights / (eps + residue_weights.sum())
					__a:						Optional[Any]		    =					torch.sum(predicted_tm_term * normed_residue_mask	,				dim=-1 )

					__a:						Optional[int]		    =					per_alignment * residue_weights

					__a:						Tuple		    =					(weighted == torch.max(lowerCamelCase_ )).nonzero()[0]
					return per_alignment[tuple(lowerCamelCase_ )]


"""simple docstring"""
lowercase		:						str =					{
    '0000': '0',
    '0001': '1',
    '0010': '2',
    '0011': '3',
    '0100': '4',
    '0101': '5',
    '0110': '6',
    '0111': '7',
    '1000': '8',
    '1001': '9',
    '1010': 'a',
    '1011': 'b',
    '1100': 'c',
    '1101': 'd',
    '1110': 'e',
    '1111': 'f',
}


def     lowerCamelCase_    (	lowerCamelCase_ )     ->			str:


					'''simple docstring'''
					__a:						Optional[int]		    =					str(lowerCamelCase_ ).strip()

					# Exceptions
					if not binary_str:
										raise ValueError("""Empty string was passed to the function""" )
					__a:						List[Any]		    =					binary_str[0] == """-"""
					__a:						List[str]		    =					binary_str[1:] if is_negative else binary_str
					if not all(char in """01""" for char in binary_str ):
										raise ValueError("""Non-binary value was passed to the function""" )

					__a:						Any		    =					(
					    """0""" * (4 * (divmod(len(lowerCamelCase_ )	,				4 )[0] + 1) - len(lowerCamelCase_ )) + binary_str
					)

					__a:						int		    =					[]
					for x in range(0	,				len(lowerCamelCase_ )	,				4 ):
										hexadecimal.append(BITS_TO_HEX[binary_str[x : x + 4]] )
					__a:						Tuple		    =					"""0x""" + """""".join(lowerCamelCase_ )

					return "-" + hexadecimal_str if is_negative else hexadecimal_str


if __name__ == "__main__":
			from doctest import testmod

			testmod()
