Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
20ae6a78
提交
20ae6a78
authored
11月 26, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix Theano cache/compilation interaction with c literal. We need to
always consider them, not just when we generate the c code. fix gh-3693
上级
c54d3d47
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
48 行增加
和
21 行删除
+48
-21
cc.py
theano/gof/cc.py
+19
-21
test_cc.py
theano/gof/tests/test_cc.py
+29
-0
没有找到文件。
theano/gof/cc.py
浏览文件 @
20ae6a78
...
...
@@ -510,7 +510,8 @@ def struct_variable_codeblocks(variable, policies, id, symbol_table, sub):
"""
name
=
"V
%
i"
%
id
symbol_table
[
variable
]
=
name
if
variable
not
in
symbol_table
:
symbol_table
[
variable
]
=
name
sub
=
dict
(
sub
)
# sub['name'] = name
sub
[
'id'
]
=
id
...
...
@@ -608,9 +609,20 @@ class CLinker(link.Linker):
self
.
orphans
=
list
(
r
for
r
in
self
.
variables
if
isinstance
(
r
,
graph
.
Constant
)
and
r
not
in
self
.
inputs
)
# C type constants (theano.scalar.Scalar). They don't request an object
self
.
consts
=
[]
# Move c type from orphans (theano.scalar.Scalar) to self.consts
for
variable
in
self
.
orphans
:
if
isinstance
(
variable
,
graph
.
Constant
):
try
:
variable
.
type
.
c_literal
(
variable
.
data
)
self
.
consts
.
append
(
variable
)
self
.
orphans
.
remove
(
variable
)
except
(
utils
.
MethodNotDefined
,
NotImplementedError
):
pass
self
.
temps
=
list
(
set
(
self
.
variables
)
.
difference
(
self
.
inputs
)
.
difference
(
self
.
outputs
)
.
difference
(
self
.
orphans
))
self
.
consts
=
[]
def
code_gen
(
self
):
"""
...
...
@@ -634,8 +646,6 @@ class CLinker(link.Linker):
no_recycling
=
self
.
no_recycling
self
.
consts
=
[]
c_support_code_apply
=
[]
c_init_code_apply
=
[]
...
...
@@ -664,7 +674,11 @@ class CLinker(link.Linker):
# [what to declare in each run,
# what to do at the beginning of each run,
# what to do at the end of each run]]
if
variable
in
self
.
inputs
:
if
variable
in
self
.
consts
:
symbol
[
variable
]
=
(
"("
+
variable
.
type
.
c_literal
(
variable
.
data
)
+
")"
)
continue
elif
variable
in
self
.
inputs
:
# We need to extract the new inputs at each run
# they do not need to be relayed to Python, so we don't sync.
# If the variable is both an input and an output, there is
...
...
@@ -675,15 +689,6 @@ class CLinker(link.Linker):
if
not
isinstance
(
variable
,
graph
.
Constant
):
raise
TypeError
(
"All orphans to CLinker must be Constant"
" instances."
,
variable
)
if
isinstance
(
variable
,
graph
.
Constant
):
try
:
symbol
[
variable
]
=
(
"("
+
variable
.
type
.
c_literal
(
variable
.
data
)
+
")"
)
self
.
consts
.
append
(
variable
)
self
.
orphans
.
remove
(
variable
)
continue
except
(
utils
.
MethodNotDefined
,
NotImplementedError
):
pass
# orphans are not inputs so we'll just get fetch them
# when we initialize the struct and assume they stay
# the same
...
...
@@ -1159,13 +1164,6 @@ class CLinker(link.Linker):
for
v
in
self
.
variables
:
if
v
in
self
.
consts
:
continue
if
v
in
self
.
orphans
and
isinstance
(
v
,
graph
.
Constant
):
try
:
# constant will be inlined, no need to get
v
.
type
.
c_literal
(
v
.
data
)
continue
except
(
utils
.
MethodNotDefined
,
NotImplementedError
):
pass
init_tasks
.
append
((
v
,
'init'
,
id
))
tasks
.
append
((
v
,
'get'
,
id
+
1
))
id
+=
2
...
...
theano/gof/tests/test_cc.py
浏览文件 @
20ae6a78
...
...
@@ -201,6 +201,35 @@ def test_clinker_literal_inlining():
assert
"4.12345678"
in
code
# we expect the number to be inlined
def
test_clinker_literal_cache
():
# This caused bugs in the past related to the cache.
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
mode
=
theano
.
Mode
(
linker
=
'c'
)
A
=
theano
.
tensor
.
matrix
()
input1
=
theano
.
tensor
.
vector
()
normal_svd
=
numpy
.
array
([[
5.936276e+01
,
-
4.664007e-07
,
-
2.56265e-06
],
[
-
4.664007e-07
,
9.468691e-01
,
-
3.18862e-02
],
[
-
2.562651e-06
,
-
3.188625e-02
,
1.05226e+00
]],
dtype
=
theano
.
config
.
floatX
)
orientationi
=
numpy
.
array
([
59.36276866
,
1.06116353
,
0.93797339
],
dtype
=
theano
.
config
.
floatX
)
for
out1
in
[
A
-
input1
[
0
]
*
numpy
.
identity
(
3
),
input1
[
0
]
*
numpy
.
identity
(
3
)]:
benchmark
=
theano
.
function
(
inputs
=
[
A
,
input1
],
outputs
=
[
out1
],
on_unused_input
=
'ignore'
,
mode
=
mode
)
out1
=
benchmark
(
normal_svd
,
orientationi
)
def
test_clinker_single_node
():
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论