


'''simple docstring'''
from __future__ import annotations



def 				lowerCAmelCase__	(       UpperCAmelCase     ):






       """simple docstring"""





       if not list_of_ints:
              return []

       if min(UpperCAmelCase     ) < 0:
              raise ValueError("""All numbers must be positive"""     )

       snake_case__					:	List[Any]          =					max(len(bin(UpperCAmelCase     )[2:]     ) for x in list_of_ints     )
       return _msd_radix_sort(UpperCAmelCase    ,       UpperCAmelCase     )



def 				lowerCAmelCase__	(       UpperCAmelCase    ,       UpperCAmelCase     ):






       """simple docstring"""





       if bit_position == 0 or len(UpperCAmelCase     ) in [0, 1]:
              return list_of_ints

       snake_case__					:	Tuple          =					[]
       snake_case__					:	Tuple          =					[]
       # Split numbers based on bit at bit_position from the right
       for number in list_of_ints:
              if (number >> (bit_position - 1)) & 1:
                     # number has a one at bit bit_position
                     ones.append(UpperCAmelCase     )
              else:
                     # number has a zero at bit bit_position
                     zeros.append(UpperCAmelCase     )

    # recursively split both lists further
       snake_case__					:	Dict          =					_msd_radix_sort(UpperCAmelCase    ,       bit_position - 1     )
       snake_case__					:	Dict          =					_msd_radix_sort(UpperCAmelCase    ,       bit_position - 1     )

       # recombine lists
       snake_case__					:	Optional[Any]          =					zeros
       res.extend(UpperCAmelCase     )

       return res



def 				lowerCAmelCase__	(       UpperCAmelCase     ):






       """simple docstring"""





       snake_case__					:	Union[str, Any]          =					len(UpperCAmelCase     )
       if not list_of_ints or length == 1:
              return

       if min(UpperCAmelCase     ) < 0:
              raise ValueError("""All numbers must be positive"""     )

       snake_case__					:	List[str]          =					max(len(bin(UpperCAmelCase     )[2:]     ) for x in list_of_ints     )
       _msd_radix_sort_inplace(UpperCAmelCase    ,       UpperCAmelCase    ,       0    ,       UpperCAmelCase     )



def 				lowerCAmelCase__	(       UpperCAmelCase    ,       UpperCAmelCase    ,       UpperCAmelCase    ,       UpperCAmelCase     ):






       """simple docstring"""





       if bit_position == 0 or end_index - begin_index <= 1:
              return

       bit_position -= 1

       snake_case__					:	Optional[int]          =					begin_index
       snake_case__					:	Tuple          =					end_index - 1
       while i <= j:
              snake_case__					:	int          =					False
              if not (list_of_ints[i] >> bit_position) & 1:
                     # found zero at the beginning
                     i += 1
                     snake_case__					:	List[Any]          =					True
              if (list_of_ints[j] >> bit_position) & 1:
                     # found one at the end
                     j -= 1
                     snake_case__					:	Dict          =					True

              if changed:
                     continue

              snake_case__       ,   snake_case__					:	List[str]          =					list_of_ints[j], list_of_ints[i]
              j -= 1
              if j != i:
                     i += 1

       _msd_radix_sort_inplace(UpperCAmelCase    ,       UpperCAmelCase    ,       UpperCAmelCase    ,       UpperCAmelCase     )
       _msd_radix_sort_inplace(UpperCAmelCase    ,       UpperCAmelCase    ,       UpperCAmelCase    ,       UpperCAmelCase     )


if __name__ == "__main__":
     import doctest

     doctest.testmod()








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

import torch



def 				lowerCAmelCase__	(       UpperCAmelCase     ):






       """simple docstring"""





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



def 				lowerCAmelCase__	(       UpperCAmelCase    ,       UpperCAmelCase    ,       ):






       """simple docstring"""





       snake_case__					:	str          =					_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    ,       ):






       """simple docstring"""





       snake_case__					:	Dict          =					torch.linspace(0    ,       UpperCAmelCase    ,       steps=(no_bins - 1)    ,       device=logits.device     )

       snake_case__					:	str          =					torch.nn.functional.softmax(UpperCAmelCase    ,       dim=-1     )
       snake_case__       ,   snake_case__					:	List[str]          =					_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    ,       ):






       """simple docstring"""





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

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

       snake_case__					:	int          =					_calculate_bin_centers(UpperCAmelCase     )
       torch.sum(UpperCAmelCase     )
       snake_case__					:	Dict          =					logits.shape[-2]
       snake_case__					:	Optional[Any]          =					max(UpperCAmelCase    ,       19     )

       snake_case__					:	Optional[int]          =					1.2_4 * (clipped_n - 15) ** (1.0 / 3) - 1.8

       snake_case__					:	Tuple          =					torch.nn.functional.softmax(UpperCAmelCase    ,       dim=-1     )

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

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

       snake_case__					:	Dict          =					per_alignment * residue_weights

       snake_case__					:	List[str]          =					(weighted == torch.max(UpperCAmelCase     )).nonzero()[0]
       return per_alignment[tuple(UpperCAmelCase     )]




