提交 19f4a625 authored 作者: Ramana.S's avatar Ramana.S

Made the final changes

上级 f380577a
......@@ -67,8 +67,8 @@ possibilities you may encounter or need. For that refer to
#itypes and otypes attributes are
#compulsory if make_node method is not defined.
#They're the type of input and output respectively
itypes = []
otypes = []
itypes = None
otypes = None
#Compulsory if itypes and otypes are not defined
def make_node(self, *inputs):
......@@ -265,7 +265,10 @@ Op Example
import theano
class DoubleOp(theano.Op):
#Using make_node
class DoubleOp1(theano.Op):
__props__ = ()
def make_node(self, x):
......@@ -297,11 +300,10 @@ Op Example
return eval_points
return self.grad(inputs, eval_points)
.. testcode:: example (using itypes and otypes)
#Using itypes and otypes
import theano
class DoubleOp(theano.Op):
class DoubleOp2(theano.Op):
__props__ = ()
itypes = [theano.tensor.dmatrix]
......@@ -329,10 +331,41 @@ Op Example
You can try it as follows:
.. testcode:: example
.. testcode:: example(Using make_node)
x = theano.tensor.matrix()
f = theano.function([x], DoubleOp1()(x))
import numpy
inp = numpy.random.rand(5, 4)
out = f(inp)
assert numpy.allclose(inp * 2, out)
print(inp)
print(out)
.. testoutput:: example
:hide:
:options: +ELLIPSIS
...
...
.. code-block:: none
[[ 0.08257206 0.34308357 0.5288043 0.06582951]
[ 0.65977826 0.10040307 0.5402353 0.55472296]
[ 0.82358552 0.29502171 0.97387481 0.0080757 ]
[ 0.77327215 0.65401857 0.76562992 0.94145702]
[ 0.8452076 0.30500101 0.88430501 0.95818655]]
[[ 0.16514411 0.68616713 1.0576086 0.13165902]
[ 1.31955651 0.20080613 1.08047061 1.10944593]
[ 1.64717104 0.59004341 1.94774962 0.0161514 ]
[ 1.5465443 1.30803715 1.53125983 1.88291403]
[ 1.6904152 0.61000201 1.76861002 1.9163731 ]]
.. testcode:: example (Using itypes and otypes)
x = theano.tensor.matrix()
f = theano.function([x], DoubleOp()(x))
f = theano.function([x], DoubleOp2()(x))
import numpy
inp = numpy.random.rand(5, 4)
out = f(inp)
......@@ -340,6 +373,7 @@ You can try it as follows:
print(inp)
print(out)
.. testoutput:: example
:hide:
:options: +ELLIPSIS
......
......@@ -521,12 +521,6 @@ class PureOp(object):
Required: return an Apply instance representing the
application of this Op to the provided inputs.
All subclasses should over-ride this function.
Raises
------
MethodNotDefined : the subclass does not override this method.
"""
raise utils.MethodNotDefined(
"make_node", type(self), self.__class__.__name__)
......@@ -964,10 +958,12 @@ class Op(utils.object2, PureOp, CLinkerOp):
def make_node(self, *inputs):
if not hasattr(self, 'itypes'):
raise NotImplementedError("itypes not defined")
raise NotImplementedError("You can either define itypes and otypes,\
or implement make_node")
if not hasattr(self, 'otypes'):
raise NotImplementedError("otypes not defined")
raise NotImplementedError("You can either define itypes and otypes,\
or implement make_node")
if len(inputs) != len(self.itypes):
raise ValueError("We expected %d inputs but got %d." %
......@@ -1408,9 +1404,8 @@ class COp(Op):
if check_input:
# Extract the various properties of the input and output variables
variables = node.inputs + node.outputs
variable_names = (["INPUT_%i" %
i for i in range(len(node.inputs))] + ["OUTPUT_%i" %
i for i in range(len(node.inputs))])
variable_names = (["INPUT_%i" % i for i in range(len(node.inputs))] +
["OUTPUT_%i" % i for i in range(len(node.inputs))])
# Generate dtype macros
for i, v in enumerate(variables):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论