


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        UpperCAmelCase_      (							__snake_case  ,		__snake_case  ,		__snake_case		)  ->    torch.Tensor:







     """simple docstring"""


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

     return ma
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case		)  ->    torch.Tensor:







     """simple docstring"""


     _lowercase							   =-1 * len(__snake_case		)
     _lowercase							   =list(range(len(tensor.shape[:zero_index]		)		)		)
     return tensor.permute(first_inds + [zero_index + i for i in inds]		)
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case		)  ->    torch.Tensor:







     """simple docstring"""


     return t.reshape(t.shape[:-no_dims] + (-1,)		)
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case  ,		__snake_case  ,		__snake_case = 1e-4		)  ->    torch.Tensor:







     """simple docstring"""


     _lowercase							   =mask.expand(*value.shape		)
     return torch.sum(mask * value  ,		dim=__snake_case		) / (eps + torch.sum(__snake_case  ,		dim=__snake_case		))
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case = 2.31_25  ,		__snake_case = 21.68_75  ,		__snake_case = 64		)  ->    torch.Tensor:







     """simple docstring"""


     _lowercase							   =torch.linspace(__snake_case  ,		__snake_case  ,		no_bins - 1  ,		device=pts.device		)
     _lowercase							   =torch.sqrt(torch.sum((pts.unsqueeze(-2		) - pts.unsqueeze(-3		)) ** 2  ,		dim=-1		)		)
     return torch.bucketize(__snake_case  ,		__snake_case		)
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case		)  ->    dict:







     """simple docstring"""


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

     return new_dict
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case		)  ->    torch.Tensor:







     """simple docstring"""


     _lowercase							   =v_bins.view(((1,) * len(x.shape		)) + (len(__snake_case		),)		)
     _lowercase							   =x[..., None] - reshaped_bins
     _lowercase							   =torch.argmin(torch.abs(__snake_case		)  ,		dim=-1		)
     return nn.functional.one_hot(__snake_case  ,		num_classes=len(__snake_case		)		).float()
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case  ,		__snake_case = 0  ,		__snake_case = 0		)  ->    torch.Tensor:







     """simple docstring"""


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

     _lowercase							   =[slice(__snake_case		) for _ in range(len(data.shape		) - no_batch_dims		)]
     _lowercase							   =inds
     ranges.extend(__snake_case		)
     # 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(__snake_case		)]


UpperCAmelCase__     			=							TypeVar('''T''')
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case  ,		__snake_case		)  ->    Dict[Any, Union[dict, list, tuple, Any]]:







     """simple docstring"""


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

     return new_dict
@overload
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case  ,		__snake_case		)  ->    Any:







     """simple docstring"""


     ...
@overload
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case  ,		__snake_case		)  ->    dict:







     """simple docstring"""


     ...
@overload
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case  ,		__snake_case		)  ->    list:







     """simple docstring"""


     ...
@overload
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case  ,		__snake_case		)  ->    tuple:







     """simple docstring"""


     ...
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case  ,		__snake_case		)  ->    Tuple:







     """simple docstring"""


     if isinstance(__snake_case  ,		__snake_case		):
          return dict_map(__snake_case  ,		__snake_case  ,		__snake_case		)
     elif isinstance(__snake_case  ,		__snake_case		):
          return [tree_map(__snake_case  ,		__snake_case  ,		__snake_case		) for x in tree]
     elif isinstance(__snake_case  ,		__snake_case		):
          return tuple(tree_map(__snake_case  ,		__snake_case  ,		__snake_case		) for x in tree		)
     elif isinstance(__snake_case  ,		__snake_case		):
          return fn(__snake_case		)
     else:
          print(type(__snake_case		)		)
          raise ValueError('''Not supported'''		)



UpperCAmelCase__     			=							partial(tree_map, leaf_type=torch.Tensor)





import requests

try:
  from django.contrib.auth import authenticate, login
  from django.shortcuts import redirect, render
except ImportError:
  UpperCAmelCase__     			=							UpperCAmelCase__     			=							UpperCAmelCase__     			=							UpperCAmelCase__     			=							print
def        UpperCAmelCase_      (							__snake_case		)  ->    List[str]:







 """simple docstring"""


 _lowercase							   ='''secretKey'''
 _lowercase							   ='''https://www.google.com/recaptcha/api/siteverify'''

 # when method is not POST, direct user to login page
 if request.method != "POST":
  return render(__snake_case  ,		'''login.html'''		)

 # from the frontend, get username, password, and client_key
 _lowercase							   =request.POST.get('''username'''		)
 _lowercase							   =request.POST.get('''password'''		)
 _lowercase							   =request.POST.get('''g-recaptcha-response'''		)

 # post recaptcha response to Google's recaptcha api
 _lowercase							   =requests.post(__snake_case  ,		data={'''secret''': secret_key, '''response''': client_key}		)
 # if the recaptcha api verified our keys
 if response.json().get('''success'''  ,		__snake_case		):
  # authenticate the user
  _lowercase							   =authenticate(__snake_case  ,		username=__snake_case  ,		password=__snake_case		)
  if user_in_database:
   login(__snake_case  ,		__snake_case		)
   return redirect('''/your-webpage'''		)
 return render(__snake_case  ,		'''login.html'''		)

