Skip to content

Commit 90e78bc

Browse files
committed
Add AddConstant
1 parent 73e9467 commit 90e78bc

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

torch2c/emitters.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,28 @@ def free_tpl(self):
266266
register(Add, torch.autograd._functions.basic_ops.Add)
267267

268268

269+
class AddConstant(Emitter):
270+
271+
def __init__(self, obj, prevfns):
272+
Emitter.__init__(self, obj, prevfns)
273+
print(obj.constant)
274+
self.def_vars({'input': id(prevfns[0])})
275+
self.infer_type_var = 'input'
276+
self.def_args({'constant': obj.constant})
277+
278+
def call_tpl(self):
279+
return '''
280+
TH${T}Tensor *$id = TH${T}Tensor_new();
281+
TH${T}Tensor_add($id,$input,$constant);
282+
'''
283+
284+
def free_tpl(self):
285+
return '''
286+
TH${T}Tensor_free($id);
287+
'''
288+
289+
register(AddConstant, torch.autograd._functions.basic_ops.AddConstant)
290+
269291

270292

271293
class Softmax(Emitter):

0 commit comments

Comments
 (0)