Skip to content

Commit 8762129

Browse files
committed
Add Sigmoid
1 parent 71f25ba commit 8762129

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

test/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ def base_test():
2626

2727
model_1 = lambda x: F.softmax(F.elu(fc3(x)))
2828
model_2 = lambda x: F.softmax(F.tanh(fc3(x)))
29+
model_3 = lambda x: F.softmax(F.sigmoid(fc3(x)))
2930

3031
data = Variable(torch.rand(10,10))
3132

32-
out = model_0(data) + model_1(data) - model_2(data) + 1 - 2
33+
out = model_0(data) + model_1(data) - model_2(data) + model_3(data) + 1 - 2
3334

3435
out_path = 'out'
3536
if not os.path.isdir(out_path):

torch2c/emitters.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,29 @@ def free_tpl(self):
452452
register(Tanh, torch.autograd._functions.pointwise.Tanh)
453453

454454

455+
class Sigmoid(Emitter):
456+
457+
def __init__(self, obj, prevfns):
458+
Emitter.__init__(self, obj, prevfns)
459+
self.def_vars({
460+
'input': id(prevfns[0]),
461+
})
462+
self.infer_type_var = 'input'
463+
464+
def call_tpl(self):
465+
return '''
466+
TH${T}Tensor *$id = TH${T}Tensor_new();
467+
THNN_${T}Sigmoid_updateOutput(NULL,$input,$id);
468+
'''
469+
470+
def free_tpl(self):
471+
return '''
472+
TH${T}Tensor_free($id);
473+
'''
474+
475+
register(Sigmoid, torch.autograd._functions.pointwise.Sigmoid)
476+
477+
455478
class Noop(Emitter):
456479

457480
def __init__(self, obj, prevfns):

0 commit comments

Comments
 (0)