

from functools import partial
from typing import Any, Callable, Dict, List, Type, TypeVar, Union, overload

import torch
import torch.nn as nn
import torch.types


def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__		,       UpperCAmelCase__   ):

					"""simple docstring"""






					if not inplace:
										__lowerCAmelCase       =				ma + ma
					else:
										ma += ma

					return ma


def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__   ):

					"""simple docstring"""






					__lowerCAmelCase       =				-1 * len(__lowerCamelCase   )
					__lowerCAmelCase       =				list(range(len(tensor.shape[:zero_index]   )   )   )
					return tensor.permute(first_inds + [zero_index + i for i in inds]   )


def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__   ):

					"""simple docstring"""






					return t.reshape(t.shape[:-no_dims] + (-1,)   )


def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__		,       UpperCAmelCase__		,       UpperCAmelCase__ = 1E-4   ):

					"""simple docstring"""






					__lowerCAmelCase       =				mask.expand(*value.shape   )
					return torch.sum(mask * value		,       dim=__lowerCamelCase   ) / (eps + torch.sum(__lowerCamelCase		,       dim=__lowerCamelCase   ))


def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__ = 2.3125		,       UpperCAmelCase__ = 21.6875		,       UpperCAmelCase__ = 64   ):

					"""simple docstring"""






					__lowerCAmelCase       =				torch.linspace(__lowerCamelCase		,       __lowerCamelCase		,       no_bins - 1		,       device=pts.device   )
					__lowerCAmelCase       =				torch.sqrt(torch.sum((pts.unsqueeze(-2   ) - pts.unsqueeze(-3   )) ** 2		,       dim=-1   )   )
					return torch.bucketize(__lowerCamelCase		,       __lowerCamelCase   )


def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__   ):

					"""simple docstring"""






					__lowerCAmelCase       =				dicts[0]
					__lowerCAmelCase       =				{}
					for k, v in first.items():
										__lowerCAmelCase       =				[d[k] for d in dicts]
										if isinstance(__lowerCamelCase		,       __lowerCamelCase   ):
															__lowerCAmelCase       =				dict_multimap(__lowerCamelCase		,       __lowerCamelCase   )
										else:
															__lowerCAmelCase       =				fn(__lowerCamelCase   )

					return new_dict


def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__   ):

					"""simple docstring"""






					__lowerCAmelCase       =				v_bins.view(((1,) * len(x.shape   )) + (len(__lowerCamelCase   ),)   )
					__lowerCAmelCase       =				x[..., None] - reshaped_bins
					__lowerCAmelCase       =				torch.argmin(torch.abs(__lowerCamelCase   )		,       dim=-1   )
					return nn.functional.one_hot(__lowerCamelCase		,       num_classes=len(__lowerCamelCase   )   ).float()


def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__		,       UpperCAmelCase__ = 0		,       UpperCAmelCase__ = 0   ):

					"""simple docstring"""






					__lowerCAmelCase       =				[]
					for i, s in enumerate(data.shape[:no_batch_dims]   ):
										__lowerCAmelCase       =				torch.arange(__lowerCamelCase   )
										__lowerCAmelCase       =				r.view(*(*((1,) * i), -1, *((1,) * (len(inds.shape   ) - i - 1)))   )
										ranges.append(__lowerCamelCase   )

					__lowerCAmelCase       =				[slice(__lowerCamelCase   ) for _ in range(len(data.shape   ) - no_batch_dims   )]
					__lowerCAmelCase       =				inds
					ranges.extend(__lowerCamelCase   )
					# Matt note: Editing this to get around the behaviour of using a list as an array index changing
					# in recent Numpy versions
					return data[tuple(__lowerCamelCase   )]


lowerCamelCase   					=  TypeVar('''T''')


def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__		,       UpperCAmelCase__   ):

					"""simple docstring"""






					__lowerCAmelCase       =				{}
					for k, v in dic.items():
										if isinstance(__lowerCamelCase		,       __lowerCamelCase   ):
															__lowerCAmelCase       =				dict_map(__lowerCamelCase		,       __lowerCamelCase		,       __lowerCamelCase   )
										else:
															__lowerCAmelCase       =				tree_map(__lowerCamelCase		,       __lowerCamelCase		,       __lowerCamelCase   )

					return new_dict


@overload
def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__		,       UpperCAmelCase__   ):

					"""simple docstring"""






					...


@overload
def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__		,       UpperCAmelCase__   ):

					"""simple docstring"""






					...


@overload
def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__		,       UpperCAmelCase__   ):

					"""simple docstring"""






					...


@overload
def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__		,       UpperCAmelCase__   ):

					"""simple docstring"""






					...


def 							__lowercase     (	UpperCAmelCase__		,       UpperCAmelCase__		,       UpperCAmelCase__   ):

					"""simple docstring"""






					if isinstance(__lowerCamelCase		,       __lowerCamelCase   ):
										return dict_map(__lowerCamelCase		,       __lowerCamelCase		,       __lowerCamelCase   )
					elif isinstance(__lowerCamelCase		,       __lowerCamelCase   ):
										return [tree_map(__lowerCamelCase		,       __lowerCamelCase		,       __lowerCamelCase   ) for x in tree]
					elif isinstance(__lowerCamelCase		,       __lowerCamelCase   ):
										return tuple(tree_map(__lowerCamelCase		,       __lowerCamelCase		,       __lowerCamelCase   ) for x in tree   )
					elif isinstance(__lowerCamelCase		,       __lowerCamelCase   ):
										return fn(__lowerCamelCase   )
					else:
										print(type(__lowerCamelCase   )   )
										raise ValueError('Not supported'   )
lowerCamelCase   					=  partial(tree_map, leaf_type=torch.Tensor)











"""simple docstring"""






def 	snake_case__  (						__lowerCamelCase							:       str				,						__lowerCamelCase							:       int = 13      ):
			"""simple docstring"""
			lowerCamelCase__						:						List[str]						      =''''''
			for c in s:
						if "A" <= c <= "Z":
									out += chr(ord('''A'''      ) + (ord(__lowerCamelCase      ) - ord('''A'''      ) + n) % 26      )
						elif "a" <= c <= "z":
									out += chr(ord('''a'''      ) + (ord(__lowerCamelCase      ) - ord('''a'''      ) + n) % 26      )
						else:
									out += c
			return out






def 	snake_case__  (						):
			"""simple docstring"""
			lowerCamelCase__						:						List[str]						      =input('''Enter message: '''      )

			lowerCamelCase__						:						str						      =dencrypt(__lowerCamelCase				,						13      )
			print('''Encryption:'''				,						__lowerCamelCase      )

			lowerCamelCase__						:						Any						      =dencrypt(__lowerCamelCase				,						13      )
			print('''Decryption: '''				,						__lowerCamelCase      )


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		main()




