Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b60d4b35
提交
b60d4b35
authored
11月 28, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ENH] Do not always compile c code when doing constant_folding
上级
fb2066db
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
32 行增加
和
2 行删除
+32
-2
elemwise.py
theano/tensor/elemwise.py
+7
-0
opt.py
theano/tensor/opt.py
+14
-2
test_opt.py
theano/tensor/tests/test_opt.py
+11
-0
没有找到文件。
theano/tensor/elemwise.py
浏览文件 @
b60d4b35
...
@@ -1193,6 +1193,13 @@ class Elemwise(OpenMPOp):
...
@@ -1193,6 +1193,13 @@ class Elemwise(OpenMPOp):
else
:
else
:
return
()
return
()
def
python_constant_folding
(
self
,
node
):
"""
Return True if we do not want to compile c code
when doing constant folding of this node.
"""
return
node
.
outputs
[
0
]
.
ndim
==
0
# def elemwise_to_scal(fgraph):
# def elemwise_to_scal(fgraph):
# TODO: why is this commented out? should it be removed?
# TODO: why is this commented out? should it be removed?
# it has needed maintenance despite being commented
# it has needed maintenance despite being commented
...
...
theano/tensor/opt.py
浏览文件 @
b60d4b35
...
@@ -4508,9 +4508,21 @@ def constant_folding(node):
...
@@ -4508,9 +4508,21 @@ def constant_folding(node):
for
o
in
node
.
outputs
:
for
o
in
node
.
outputs
:
storage_map
[
o
]
=
[
None
]
storage_map
[
o
]
=
[
None
]
compute_map
[
o
]
=
[
False
]
compute_map
[
o
]
=
[
False
]
if
(
hasattr
(
node
.
op
,
'python_constant_folding'
)
and
node
.
op
.
python_constant_folding
(
node
)):
thunk
=
node
.
op
.
make_thunk
(
node
,
storage_map
,
compute_map
,
old_value
=
getattr
(
node
.
op
,
'_op_use_c_code'
,
False
)
no_recycling
=
[])
try
:
node
.
op
.
_op_use_c_code
=
False
thunk
=
node
.
op
.
make_thunk
(
node
,
storage_map
,
compute_map
,
[])
finally
:
node
.
op
.
_op_use_c_code
=
old_value
else
:
thunk
=
node
.
op
.
make_thunk
(
node
,
storage_map
,
compute_map
,
no_recycling
=
[])
required
=
thunk
()
required
=
thunk
()
assert
not
required
# a node whose inputs are all provided should always
assert
not
required
# a node whose inputs are all provided should always
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
b60d4b35
...
@@ -3671,6 +3671,17 @@ def test_constant_folding():
...
@@ -3671,6 +3671,17 @@ def test_constant_folding():
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
2
assert
len
(
topo
)
==
2
# Test that we do not crash when constant folding elemwise scalar
# as they should not generate c code.
x
=
tensor
.
constant
(
3
)
assert
x
.
ndim
==
0
mode
=
theano
.
compile
.
get_mode
(
"FAST_COMPILE"
)
.
excluding
(
"fusion"
)
f
=
theano
.
function
([],
[
x
*
2
,
x
+
x
],
mode
=
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
2
assert
all
([
isinstance
(
n
.
op
,
DeepCopyOp
)
for
n
in
topo
])
def
test_constant_get_stabilized
():
def
test_constant_get_stabilized
():
"""
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论