import torch


def my_sample_gumbel(shape, eps=1e-20):
	"""Samples arbitrary-shaped standard gumbel variables.
	Args:
	shape: list of integers
	eps: float, for numerical stability
	Returns:
	A sample of standard Gumbel random variables
	"""
	#Sample from Gumbel(0, 1)
	U = torch.rand(shape).float()
	return -torch.log(eps - torch.log(U + eps))