


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

import torch






def 						lowercase				(	_snake_case		: torch.Tensor	)	->torch.Tensor:
	"""simple docstring"""





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






def 						lowercase				(	_snake_case		: torch.Tensor	,  _snake_case		: torch.Tensor	,  )	->Tuple[torch.Tensor, torch.Tensor]:
	"""simple docstring"""





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






def 						lowercase				(	_snake_case		: torch.Tensor	,  _snake_case		: int = 31	,  _snake_case		: int = 64	,  **_snake_case		: Optional[Any]	,  )	->Dict[str, torch.Tensor]:
	"""simple docstring"""





	__snake_case      :		Optional[Any]         =							torch.linspace(0	,  _snake_case	,  steps=(no_bins - 1)	,  device=logits.device	)

	__snake_case      :		Optional[Any]         =							torch.nn.functional.softmax(_snake_case	,  dim=-1	)
	__snake_case      ,				__snake_case      :		List[Any]         =							_calculate_expected_aligned_error(
	    alignment_confidence_breaks=_snake_case	,  aligned_distance_error_probs=_snake_case	,  )

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






def 						lowercase				(	_snake_case		: torch.Tensor	,  _snake_case		: Optional[torch.Tensor] = None	,  _snake_case		: int = 31	,  _snake_case		: int = 64	,  _snake_case		: float = 1e-8	,  **_snake_case		: Tuple	,  )	->torch.Tensor:
	"""simple docstring"""





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

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

	__snake_case      :		Optional[Any]         =							_calculate_bin_centers(_snake_case	)
	torch.sum(_snake_case	)
	__snake_case      :		str         =							logits.shape[-2]
	__snake_case      :		Optional[Any]         =							max(_snake_case	,  19	)

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

	__snake_case      :		List[Any]         =							torch.nn.functional.softmax(_snake_case	,  dim=-1	)

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

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

	__snake_case      :		List[Any]         =							per_alignment * residue_weights

	__snake_case      :		int         =							(weighted == torch.max(_snake_case	)).nonzero()[0]
	return per_alignment[tuple(_snake_case	)]







'''simple docstring'''


__SCREAMING_SNAKE_CASE						=      {hex(i)[2:]: i for i in range(16)}  # Use [:2] to strip off the leading '0x'
def 					__magic_name__(       UpperCAmelCase__ :       str	):
						UpperCamelCase_     :	str					     =     hex_string.strip().lower()
						if not hex_string:
												raise ValueError("""Empty string was passed to the function"""	)
						UpperCamelCase_     :	Dict					     =     hex_string[0] == """-"""
						if is_negative:
												UpperCamelCase_     :	List[str]					     =     hex_string[1:]
						if not all(char in hex_table for char in hex_string	):
												raise ValueError("""Non-hexadecimal value was passed to the function"""	)
						UpperCamelCase_     :	int					     =     0
						for char in hex_string:
												UpperCamelCase_     :	Any					     =     16 * decimal_number + hex_table[char]
						return -decimal_number if is_negative else decimal_number


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

	testmod()




