Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
928ad5c0
提交
928ad5c0
authored
1月 16, 2008
作者:
bergstrj@iro.umontreal.ca
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cleanup
上级
a7442159
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
29 行增加
和
33 行删除
+29
-33
compile.py
compile.py
+29
-33
没有找到文件。
compile.py
浏览文件 @
928ad5c0
...
@@ -10,52 +10,35 @@ import opt
...
@@ -10,52 +10,35 @@ import opt
import
core
import
core
def
to_func
(
inputs
,
outputs
):
# print gof.Env(inputs, outputs).io_toposort()
p
=
prog
(
inputs
,
outputs
)
# print p.env
def
f
(
*
args
):
for
input
,
value
in
zip
(
inputs
,
args
):
p
[
input
]
=
value
outputs
=
p
()
if
len
(
outputs
)
==
1
:
return
outputs
[
0
]
else
:
return
outputs
return
f
# def prog(inputs, outputs):
# outputs = gof.ext.mark_outputs_as_destroyed(outputs)
# program = gof.Prog(inputs, outputs, opt.optimizer, gof.link.ThunkLinker(), [gof.features.PrintListener])
# for orphan in program.env.orphans():
# if orphan.storage is core.UNCOMPUTED:
# raise Exception("Your program depends on a few uncomputed values.")
# return program
class
prog
(
gof
.
Prog
):
class
prog
(
gof
.
Prog
):
def
__init__
(
self
,
inputs
,
outputs
,
optimizer
=
opt
.
optimizer
([])):
"""Compile a subgraph.
N.B. This triggers computation of the subgraph leading to the outputs
that is not fed by the inputs (the orphans).
def
__init__
(
self
,
inputs
,
outputs
):
TODO: think about whether orphan computation should be in this function,
# core.build_mode()
or in self.__call__()
outputs
=
gof
.
ext
.
mark_outputs_as_destroyed
(
outputs
)
"""
outputs
=
gof
.
mark_outputs_as_destroyed
(
outputs
)
gof
.
Prog
.
__init__
(
self
,
gof
.
Prog
.
__init__
(
self
,
inputs
,
inputs
,
outputs
,
outputs
,
opt
.
opt
imizer
,
optimizer
,
gof
.
link
.
perform_linker
,
gof
.
link
.
perform_linker
,
[])
[])
# core.pop_mode
()
self
.
compute_orphans
()
def
__call__
(
self
,
check_uncomputed
=
True
):
def
__call__
(
self
,
check_uncomputed
=
True
):
"""Recompute the graph.
If the inputs are uncomputed (and check_uncomputed is True) then an
Exception is raised.
"""
if
check_uncomputed
:
if
check_uncomputed
:
for
input
in
self
.
env
.
inputs
:
for
input
in
self
.
env
.
inputs
:
if
input
.
data
is
core
.
UNCOMPUTED
:
if
input
.
data
is
core
.
UNCOMPUTED
:
raise
Exception
(
"You must provide a value for input
%
s!"
%
input
)
raise
Exception
(
"You must provide a value for input
%
s!"
%
input
)
self
.
compute_orphans
()
# for orphan in self.env.orphans():
# if orphan.data is core.UNCOMPUTED:
# raise Exception("Orphan %s is uncomputed but needed to calculate the function. " % orphan + \
# "Try calling prog.compute_orphans() or set it manually.")
return
gof
.
Prog
.
__call__
(
self
)
return
gof
.
Prog
.
__call__
(
self
)
def
compute_orphans
(
self
):
def
compute_orphans
(
self
):
...
@@ -67,6 +50,19 @@ class prog(gof.Prog):
...
@@ -67,6 +50,19 @@ class prog(gof.Prog):
raise
Exception
(
"Orphan
%
s is uncomputed but needed to calculate the function."
%
orphan
)
raise
Exception
(
"Orphan
%
s is uncomputed but needed to calculate the function."
%
orphan
)
def
to_func
(
inputs
,
outputs
):
# print gof.Env(inputs, outputs).io_toposort()
p
=
prog
(
inputs
,
outputs
)
print
p
.
env
def
f
(
*
args
):
for
input
,
value
in
zip
(
inputs
,
args
):
p
[
input
]
=
value
outputs
=
p
()
if
len
(
outputs
)
==
1
:
return
outputs
[
0
]
else
:
return
outputs
return
f
def
single
(
*
outputs
):
def
single
(
*
outputs
):
return
prog
(
gof
.
graph
.
inputs
(
outputs
),
outputs
)
return
prog
(
gof
.
graph
.
inputs
(
outputs
),
outputs
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论