


'''simple docstring'''







def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     int  )  ->      str:
       if not isinstance(_UpperCAmelCase   ,_UpperCAmelCase  ):
              _a   :			Dict					 =(
                  """operation can not be conducted on a object of type """
                  F"{type(_UpperCAmelCase  ).__name__}"
              )
              raise TypeError(_UpperCAmelCase  )
       _a   :			int					 =""""""
       for _ in range(0   ,32  ):
              bit_string += str(number % 2  )
              _a   :			List[str]					 =number >> 1
       return bit_string


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     int  )  ->      str:
       if number < 0:
              raise ValueError("""the value of input must be positive"""  )
       elif isinstance(_UpperCAmelCase   ,_UpperCAmelCase  ):
              raise TypeError("""Input value must be a 'int' type"""  )
       elif isinstance(_UpperCAmelCase   ,_UpperCAmelCase  ):
              raise TypeError("""'<' not supported between instances of 'str' and 'int'"""  )
       _a   :			Tuple					 =0
       # iterator over [1 to 32],since we are dealing with 32 bit integer
       for _ in range(1   ,33  ):
              # left shift the bits by unity
              _a   :			List[Any]					 =result << 1
              # get the end bit
              _a   :			Optional[int]					 =number % 2
              # right shift the bits by unity
              _a   :			Tuple					 =number >> 1
              # add that bit to our ans
              _a   :			Any					 =result | end_bit
       return get_reverse_bit_string(_UpperCAmelCase  )


if __name__ == "__main__":
   import doctest

   doctest.testmod()






'''simple docstring'''







from typing import Dict, Optional, Tuple

import torch


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     torch.Tensor  )  ->      torch.Tensor:
       _a   :			Tuple					 =boundaries[1] - boundaries[0]
       _a   :			Dict					 =boundaries + step / 2
       _a   :			List[Any]					 =torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1  )]   ,dim=0  )
       return bin_centers


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     torch.Tensor   ,_UpperCAmelCase     :     torch.Tensor   ,)  ->      Tuple[torch.Tensor, torch.Tensor]:
       _a   :			Any					 =_calculate_bin_centers(_UpperCAmelCase  )
       return (
           torch.sum(aligned_distance_error_probs * bin_centers   ,dim=-1  ),
           bin_centers[-1],
       )


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     torch.Tensor   ,_UpperCAmelCase     :     int = 31   ,_UpperCAmelCase     :     int = 64   ,**_UpperCAmelCase     :     Dict   ,)  ->      Dict[str, torch.Tensor]:
       _a   :			Dict					 =torch.linspace(0   ,_UpperCAmelCase   ,steps=(no_bins - 1)   ,device=logits.device  )

       _a   :			int					 =torch.nn.functional.softmax(_UpperCAmelCase   ,dim=-1  )
       _a ,   _a   :			List[Any]					 =_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      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     torch.Tensor   ,_UpperCAmelCase     :     Optional[torch.Tensor] = None   ,_UpperCAmelCase     :     int = 31   ,_UpperCAmelCase     :     int = 64   ,_UpperCAmelCase     :     float = 1e-8   ,**_UpperCAmelCase     :     Optional[Any]   ,)  ->      torch.Tensor:
       if residue_weights is None:
              _a   :			Dict					 =logits.new_ones(logits.shape[-2]  )

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

       _a   :			Optional[int]					 =_calculate_bin_centers(_UpperCAmelCase  )
       torch.sum(_UpperCAmelCase  )
       _a   :			List[str]					 =logits.shape[-2]
       _a   :			List[Any]					 =max(_UpperCAmelCase   ,19  )

       _a   :			Union[str, Any]					 =1.2_4 * (clipped_n - 15) ** (1.0 / 3) - 1.8

       _a   :			Tuple					 =torch.nn.functional.softmax(_UpperCAmelCase   ,dim=-1  )

       _a   :			Dict					 =1.0 / (1 + (bin_centers**2) / (da**2))
       _a   :			int					 =torch.sum(probs * tm_per_bin   ,dim=-1  )

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

       _a   :			int					 =per_alignment * residue_weights

       _a   :			List[Any]					 =(weighted == torch.max(_UpperCAmelCase  )).nonzero()[0]
       return per_alignment[tuple(_UpperCAmelCase  )]


