提交 07b2896e authored 作者: Ramana.S's avatar Ramana.S

Compile theano function and assert

上级 1f3c1f6a
...@@ -519,13 +519,6 @@ class FromFunctionOp(gof.Op): ...@@ -519,13 +519,6 @@ class FromFunctionOp(gof.Op):
return 'FromFunctionOp{%s}' % self.__fn.__name__ return 'FromFunctionOp{%s}' % self.__fn.__name__
def make_node(self, *inputs): def make_node(self, *inputs):
if not self.itypes:
raise NotImplementedError("itypes not defined")
if not self.otypes:
raise NotImplementedError("otypes not defined")
if len(inputs) != len(self.itypes): if len(inputs) != len(self.itypes):
raise ValueError("We expected %d inputs but got %d." % raise ValueError("We expected %d inputs but got %d." %
(len(self.itypes), len(inputs))) (len(self.itypes), len(inputs)))
......
...@@ -235,26 +235,24 @@ class TestMakeThunk(unittest.TestCase): ...@@ -235,26 +235,24 @@ class TestMakeThunk(unittest.TestCase):
thunk) thunk)
def test_no_make_node(self): def test_no_make_node(self):
class IncOne(Op): class DoubleOp(Op):
"""An Op without make_node""" """An Op without make_node"""
__props__ = ()
itypes = [T.fmatrix]
otypes = [T.fmatrix]
def perform(self, node, inputs, outputs): __props__ = ()
input, = inputs
output, = outputs
output[0] = input + 1
x_input = T.fmatrix('x') itypes = [T.dmatrix]
o = IncOne()(x_input) otypes = [T.dmatrix]
# Confirming that make_node method is implemented def perform(self, node, inputs, outputs):
try: inp = inputs[0]
self.assertRaises((NotImplementedError, utils.MethodNotDefined), output = outputs[0]
o.owner.op.make_node, x_input) output[0] = inp * 2
except AssertionError:
pass x_input = T.matrix('x_input')
f = theano.function([x_input], DoubleOp()(x_input))
inp = numpy.random.rand(5, 4)
out = f(inp)
assert numpy.allclose(inp * 2, out)
def test_test_value_python_objects(): def test_test_value_python_objects():
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论