Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
19f4a625
提交
19f4a625
authored
1月 18, 2016
作者:
Ramana.S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Made the final changes
上级
f380577a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
48 行增加
和
19 行删除
+48
-19
extending_theano.txt
doc/tutorial/extending_theano.txt
+42
-8
op.py
theano/gof/op.py
+6
-11
没有找到文件。
doc/tutorial/extending_theano.txt
浏览文件 @
19f4a625
...
...
@@ -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 DoubleOp
2
(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], DoubleOp
2
()(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
...
...
theano/gof/op.py
浏览文件 @
19f4a625
...
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论