Add exp and log functions from torch

This commit is contained in:
Yin Li 2020-01-31 11:11:31 -05:00
parent 698b2a8df7
commit ea61bb9b65

View File

@ -0,0 +1,26 @@
import torch
def exp(x, undo=False):
if not undo:
torch.exp(x, out=x)
else:
torch.log(x, out=x)
def log(x, eps=1e-8, undo=False):
if not undo:
torch.log(x + eps, out=x)
else:
torch.exp(x, out=x)
def expm1(x, undo=False):
if not undo:
torch.expm1(x, out=x)
else:
torch.log1p(x, out=x)
def log1p(x, eps=1e-7, undo=False):
if not undo:
torch.log1p(x + eps, out=x)
else:
torch.expm1(x, out=x)