Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
64952355
提交
64952355
authored
1月 01, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
1月 01, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use direct imports from theano.gof.graph in theano.link.c.basic
上级
ebd59050
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
13 行增加
和
12 行删除
+13
-12
basic.py
theano/link/c/basic.py
+13
-12
没有找到文件。
theano/link/c/basic.py
浏览文件 @
64952355
...
...
@@ -12,9 +12,10 @@ from io import StringIO
import
numpy
as
np
from
theano.configdefaults
import
config
from
theano.gof
import
graph
from
theano.gof.callcache
import
CallCache
from
theano.gof.compilelock
import
get_lock
,
release_lock
from
theano.gof.graph
import
Constant
,
NoParams
,
io_toposort
from
theano.gof.graph
import
variables
as
get_variables
from
theano.gof.utils
import
MethodNotDefined
,
difference
,
uniq
from
theano.link.basic
import
Container
,
Linker
,
LocalLinker
,
PerformLinker
from
theano.link.c.cmodule
import
(
...
...
@@ -635,14 +636,14 @@ class CLinker(Linker):
# We need to include the unused inputs in our variables,
# otherwise we can't pass them to the module.
self
.
variables
=
[
var
for
var
in
self
.
inputs
if
not
len
(
fgraph
.
clients
[
var
])]
self
.
variables
+=
g
raph
.
variables
(
self
.
inputs
,
self
.
outputs
)
self
.
variables
+=
g
et_
variables
(
self
.
inputs
,
self
.
outputs
)
# This adds a hidden input which is the params for each node
# that needs it
self
.
node_params
=
dict
()
for
node
in
self
.
node_order
:
params
=
node
.
run_params
()
if
params
is
not
graph
.
NoParams
:
if
params
is
not
NoParams
:
# try to avoid creating more than one variable for the
# same params.
if
params
in
self
.
node_params
:
...
...
@@ -650,7 +651,7 @@ class CLinker(Linker):
assert
var
.
type
==
node
.
params_type
fgraph
.
clients
[
var
]
.
append
((
node
,
"params"
))
else
:
var
=
graph
.
Constant
(
node
.
params_type
,
params
)
var
=
Constant
(
node
.
params_type
,
params
)
fgraph
.
clients
[
var
]
=
[(
node
,
"params"
)]
self
.
node_params
[
params
]
=
var
self
.
variables
.
append
(
var
)
...
...
@@ -660,13 +661,13 @@ class CLinker(Linker):
self
.
orphans
=
list
(
r
for
r
in
self
.
variables
if
isinstance
(
r
,
graph
.
Constant
)
and
r
not
in
self
.
inputs
if
isinstance
(
r
,
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
):
if
isinstance
(
variable
,
Constant
):
try
:
variable
.
type
.
c_literal
(
variable
.
data
)
self
.
consts
.
append
(
variable
)
...
...
@@ -742,7 +743,7 @@ class CLinker(Linker):
[
get_c_declare
,
get_c_extract
,
get_c_cleanup
],
]
elif
variable
in
self
.
orphans
:
if
not
isinstance
(
variable
,
graph
.
Constant
):
if
not
isinstance
(
variable
,
Constant
):
raise
TypeError
(
"All orphans to CLinker must be Constant"
" instances."
,
variable
,
...
...
@@ -818,7 +819,7 @@ class CLinker(Linker):
sub
=
dict
(
failure_var
=
failure_var
)
params
=
node
.
run_params
()
if
params
is
not
graph
.
NoParams
:
if
params
is
not
NoParams
:
params_var
=
symbol
[
self
.
node_params
[
params
]]
# The placeholder will be replaced by a hash of the entire
...
...
@@ -833,13 +834,13 @@ class CLinker(Linker):
# Make the CodeBlock for c_code
sub
[
"id"
]
=
id
sub
[
"fail"
]
=
failure_code
(
sub
)
if
params
is
not
graph
.
NoParams
:
if
params
is
not
NoParams
:
sub
[
"params"
]
=
params_var
sub_struct
=
dict
()
sub_struct
[
"id"
]
=
id
+
1
sub_struct
[
"fail"
]
=
failure_code_init
(
sub
)
if
params
is
not
graph
.
NoParams
:
if
params
is
not
NoParams
:
# Since params inputs are always constants they are
# guaranteed to be available in the struct init code.
sub_struct
[
"params"
]
=
params_var
...
...
@@ -1399,7 +1400,7 @@ class CLinker(Linker):
# doesn't need to include information about inplace operations
# because that information will be included explicitly in
# cmodule_key_().
return
graph
.
io_toposort
(
self
.
inputs
,
self
.
outputs
)
return
io_toposort
(
self
.
inputs
,
self
.
outputs
)
fgraph
=
FakeFunctionGraph
(
inputs
,
outputs
)
return
self
.
cmodule_key_
(
...
...
@@ -1495,7 +1496,7 @@ class CLinker(Linker):
# It is important that a variable (i)
# yield a 'position' that reflects its role in code_gen()
if
isinstance
(
i
,
graph
.
Constant
):
# orphans
if
isinstance
(
i
,
Constant
):
# orphans
if
id
(
i
)
not
in
constant_ids
:
isig
=
(
i
.
signature
(),
topological_pos
,
i_idx
)
# If the Theano constant provides a strong hash
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论