
"""simple docstring"""


from functools import lru_cache



@lru_cache
def 					_lowerCamelCase(__UpperCamelCase )       ->				int:
	if not isinstance(__UpperCamelCase					,				__UpperCamelCase ):
		raise TypeError("""k must be an integer.""" )
	if k < 0:
		raise ValueError("""k integer must be greater or equal to zero.""" )
	if k == 0:
		return 0
	elif k == 1:
		return 1
	else:
		return fibonacci(k - 1 ) + fibonacci(k - 2 )



def 					_lowerCamelCase(__UpperCamelCase					,				__UpperCamelCase )       ->				int:
	_lowerCAmelCase			=len(__UpperCamelCase )
	# Find m such that F_m >= n where F_i is the i_th fibonacci number.
	_lowerCAmelCase			=0
	while True:
		if fibonacci(__UpperCamelCase ) >= len_list:
			_lowerCAmelCase			=i
			break
		i += 1
	_lowerCAmelCase			=0
	while fibb_k > 0:
		_lowerCAmelCase			=min(
		    offset + fibonacci(fibb_k - 1 )					,				len_list - 1 )  # Prevent out of range
		_lowerCAmelCase			=arr[index_k]
		if item_k_1 == val:
			return index_k
		elif val < item_k_1:
			fibb_k -= 1
		elif val > item_k_1:
			offset += fibonacci(fibb_k - 1 )
			fibb_k -= 2
	else:
		return -1


if __name__ == "__main__":
			import doctest

			doctest.testmod()





"""simple docstring"""


from typing import Dict, Optional, Tuple

import torch



def 					_lowerCamelCase(__UpperCamelCase )       ->				torch.Tensor:
	_lowerCAmelCase			=boundaries[1] - boundaries[0]
	_lowerCAmelCase			=boundaries + step / 2
	_lowerCAmelCase			=torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1 )]					,				dim=0 )
	return bin_centers



def 					_lowerCamelCase(__UpperCamelCase					,				__UpperCamelCase					,				)       ->				Tuple[torch.Tensor, torch.Tensor]:
	_lowerCAmelCase			=_calculate_bin_centers(__UpperCamelCase )
	return (
	    torch.sum(aligned_distance_error_probs * bin_centers					,				dim=-1 ),
	    bin_centers[-1],
	)



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

	_lowerCAmelCase			=torch.nn.functional.softmax(__UpperCamelCase					,				dim=-1 )
	_lowerCAmelCase		,							_lowerCAmelCase			=_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 					_lowerCamelCase(__UpperCamelCase					,				__UpperCamelCase = None					,				__UpperCamelCase = 31					,				__UpperCamelCase = 64					,				__UpperCamelCase = 1E-8					,				**__UpperCamelCase					,				)       ->				torch.Tensor:
	if residue_weights is None:
		_lowerCAmelCase			=logits.new_ones(logits.shape[-2] )

	_lowerCAmelCase			=torch.linspace(0					,				__UpperCamelCase					,				steps=(no_bins - 1)					,				device=logits.device )

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

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

	_lowerCAmelCase			=torch.nn.functional.softmax(__UpperCamelCase					,				dim=-1 )

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

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

	_lowerCAmelCase			=per_alignment * residue_weights

	_lowerCAmelCase			=(weighted == torch.max(__UpperCamelCase )).nonzero()[0]
	return per_alignment[tuple(__UpperCamelCase )]



