def preProc2(x):
# Access the global variables
global P, expP, negExpP
P = P.type_as(x)
expP = expP.type_as(x)
negExpP = negExpP.type_as(x)
# Create a variable filled with -1. Second part of the condition
z = Variable(torch.zeros(x.size())).type_as(x)
absX = torch.abs(x)
cond1 = torch.gt(absX, negExpP)
cond2 = torch.le(absX, negExpP)
if (torch.sum(cond1) > 0).data.all():
x1 = torch.sign(x[cond1])
z[cond1] = x1
if (torch.sum(cond2) > 0).data.all():
x2 = x[cond2]*expP
z[cond2] = x2
return z
评论列表
文章目录