

"""simple docstring"""





from typing import Dict, Optional, Tuple

import torch



def        _lowerCAmelCase      (						UpperCAmelCase     :							torch.Tensor				):


					'''simple docstring'''






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



def        _lowerCAmelCase      (						UpperCAmelCase     :							torch.Tensor      ,							UpperCAmelCase     :							torch.Tensor      ,							):


					'''simple docstring'''






					UpperCamelCase__		:    List[Any]         =_calculate_bin_centers(UpperCAmelCase				)
					return (
					    torch.sum(aligned_distance_error_probs * bin_centers      ,							dim=-1				),
					    bin_centers[-1],
					)



def        _lowerCAmelCase      (						UpperCAmelCase     :							torch.Tensor      ,							UpperCAmelCase     :							int = 31      ,							UpperCAmelCase     :							int = 64      ,							**UpperCAmelCase     :							Any      ,							):


					'''simple docstring'''






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

					UpperCamelCase__		:    str         =torch.nn.functional.softmax(UpperCAmelCase      ,							dim=-1				)
					UpperCamelCase__  ,			UpperCamelCase__		:    int         =_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     :							torch.Tensor      ,							UpperCAmelCase     :							Optional[torch.Tensor] = None      ,							UpperCAmelCase     :							int = 31      ,							UpperCAmelCase     :							int = 64      ,							UpperCAmelCase     :							float = 1E-8      ,							**UpperCAmelCase     :							Optional[int]      ,							):


					'''simple docstring'''






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

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

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

					UpperCamelCase__		:    Optional[int]         =1.24 * (clipped_n - 15) ** (1.0 / 3) - 1.8

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

					UpperCamelCase__		:    Any         =1.0 / (1 + (bin_centers**2) / (da**2))
					UpperCamelCase__		:    Tuple         =torch.sum(probs * tm_per_bin      ,							dim=-1				)

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

					UpperCamelCase__		:    List[str]         =per_alignment * residue_weights

					UpperCamelCase__		:    Dict         =(weighted == torch.max(UpperCAmelCase				)).nonzero()[0]
					return per_alignment[tuple(UpperCAmelCase				)]





"""simple docstring"""





def        _lowerCAmelCase      (						UpperCAmelCase     :							list[list[int]]				):


					'''simple docstring'''






					UpperCamelCase__		:    Dict         =[list(UpperCAmelCase				) for row in matrix]
					if matrix and isinstance(UpperCAmelCase      ,							UpperCAmelCase				):
										if isinstance(matrix[0]      ,							UpperCAmelCase				):
															UpperCamelCase__		:    List[Any]         =0
															for row in matrix:
																				if prev_len == 0:
																									UpperCamelCase__		:    Optional[Any]         =len(UpperCAmelCase				)
																									UpperCamelCase__		:    Optional[int]         =True
																				else:
																									UpperCamelCase__		:    List[str]         =prev_len == len(UpperCAmelCase				)
										else:
															UpperCamelCase__		:    Tuple         =True
					else:
										UpperCamelCase__		:    Optional[Any]         =False

					return result



def        _lowerCAmelCase      (						UpperCAmelCase     :							list[list[int]]				):


					'''simple docstring'''






					if check_matrix(UpperCAmelCase				) and len(UpperCAmelCase				) > 0:
										UpperCamelCase__		:    Optional[int]         =[list(UpperCAmelCase				) for row in a]
										UpperCamelCase__		:    Any         =len(UpperCAmelCase				)
										if isinstance(a[0]      ,							UpperCAmelCase				):
															UpperCamelCase__		:    Tuple         =len(a[0]				)
										else:
															for dat in a:
																				print(UpperCAmelCase				)
															return

										# horizotal printing increasing
										for i in range(0      ,							UpperCAmelCase				):
															print(a[0][i]				)
										# vertical printing down
										for i in range(1      ,							UpperCAmelCase				):
															print(a[i][mat_col - 1]				)
										# horizotal printing decreasing
										if mat_row > 1:
															for i in range(mat_col - 2      ,							-1      ,							-1				):
																				print(a[mat_row - 1][i]				)
        # vertical printing up
										for i in range(mat_row - 2      ,							0      ,							-1				):
															print(a[i][0]				)
										UpperCamelCase__		:    Tuple         =[row[1 : mat_col - 1] for row in a[1 : mat_row - 1]]
										if len(UpperCAmelCase				) > 0:
															spiral_print_clockwise(UpperCAmelCase				)
										else:
															return
					else:
										print('''Not a valid matrix'''				)
										return



def        _lowerCAmelCase      (						UpperCAmelCase     :							list[list]				):


					'''simple docstring'''






					if matrix:
										return list(matrix.pop(0				)				) + spiral_traversal(list(zip(*UpperCAmelCase				)				)[::-1]				)
					else:
										return []


# driver code
if __name__ == "__main__":
				import doctest

				doctest.testmod()

				_SCREAMING_SNAKE_CASE       :  int        = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 1_0, 1_1, 1_2]]
				spiral_print_clockwise(a)


