提交 fdc3cf54 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Add test for struct code.

上级 aba6052e
......@@ -75,6 +75,33 @@ class NoInputOp(Op):
output_storage[0][0] = 'test Op no input'
class StructOp(Op):
__props__ = ()
def do_constant_folding(self, node):
# we are not constant
return False
# The input only serves to distinguish thunks
def make_node(self, i):
return Apply(self, [i], [scalar.uint64()])
def c_support_code_struct(self, node, struct_id):
return "npy_uint64 counter%d;" % (struct_id,)
def c_init_code_struct(self, node, struct_id):
return "counter%d = 0;" % (struct_id,)
def c_code(self, node, name, input_names, outputs_names, sub):
return """
%(out)s = counter%(sid)s;
counter%(sid)s++;
""" % dict(out=outputs_names[0], sid=sub['struct_id'])
def c_code_cache_version(self):
return (0,)
class TestOp:
# Sanity tests
......@@ -102,6 +129,19 @@ class TestOp:
rval = f()
assert rval == 'test Op no input'
def test_op_struct(self):
sop = StructOp()
c = sop(theano.tensor.constant(0))
f = theano.function([], c)
rval = f()
assert rval == 0
rval = f()
assert rval == 1
c2 = sop(theano.tensor.constant(1))
f2 = theano.function([], [c, c2])
rval = f2()
assert rval == [0, 0]
class TestMakeThunk(unittest.TestCase):
def test_no_c_code(self):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论