Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b8839686
提交
b8839686
authored
1月 08, 2008
作者:
olivier@olivier-desktop
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
woo
上级
14753530
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
106 行增加
和
19 行删除
+106
-19
.hgignore
.hgignore
+7
-0
compile.py
compile.py
+65
-0
core.py
core.py
+0
-0
opt.py
opt.py
+34
-19
没有找到文件。
.hgignore
0 → 100644
浏览文件 @
b8839686
syntax: glob
*.pyc
*.o
*.so
*~
\#*\#
compile.py
0 → 100644
浏览文件 @
b8839686
import
gof
import
opt
#prog(inputs, outputs)
#single(*outputs)
#multi(*output_lists)
import
core
def
to_func
(
inputs
,
outputs
):
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
):
def
__init__
(
self
,
inputs
,
outputs
):
# core.build_mode()
outputs
=
gof
.
ext
.
mark_outputs_as_destroyed
(
outputs
)
gof
.
Prog
.
__init__
(
self
,
inputs
,
outputs
,
opt
.
optimizer
,
gof
.
link
.
thunk_linker
,
[])
# core.pop_mode()
def
__call__
(
self
,
check_uncomputed
=
True
):
if
check_uncomputed
:
for
input
in
self
.
env
.
inputs
:
if
input
.
data
is
core
.
UNCOMPUTED
:
raise
Exception
(
"You must provide a value for input
%
s!"
%
input
)
for
orphan
in
self
.
env
.
orphans
():
if
orphan
.
data
is
core
.
UNCOMPUTED
:
raise
Exception
(
"Orphan
%
s is uncomputed but needed to calculate the function. "
%
input
+
\
"Try calling prog.compute_orphans() or set it manually."
)
return
gof
.
Prog
.
__call__
(
self
)
def
compute_orphans
(
self
):
raise
NotImplementedError
def
single
(
*
outputs
):
return
prog
(
gof
.
graph
.
inputs
(
outputs
),
outputs
)
core.py
浏览文件 @
b8839686
差异被折叠。
点击展开。
opt.py
浏览文件 @
b8839686
...
...
@@ -3,24 +3,28 @@ from core import *
import
gof
def
pattern_opt
(
in_pattern
,
out_pattern
):
def
parse
(
x
):
if
isinstance
(
x
,
(
list
,
tuple
)):
return
[
parse
(
y
)
for
y
in
x
]
elif
isinstance
(
x
,
wrapper
):
return
x
.
opclass
elif
isinstance
(
x
,
str
)
or
(
hasattr
(
x
,
'__bases__'
)
and
issubclass
(
x
,
gof
.
op
.
Op
)):
return
x
else
:
raise
TypeError
(
"Bad input type for pattern_opt."
)
return
gof
.
opt
.
PatternOptimizer
(
parse
(
in_pattern
),
parse
(
out_pattern
))
def
op_sub
(
op1
,
op2
):
if
isinstance
(
op1
,
wrapper
):
op1
=
op1
.
opclass
if
isinstance
(
op2
,
wrapper
):
op2
=
op2
.
opclass
return
gof
.
opt
.
OpSubOptimizer
(
op1
,
op2
)
# def pattern_opt(in_pattern, out_pattern):
# def parse(x):
# if isinstance(x, (list, tuple)):
# return [parse(y) for y in x]
# elif isinstance(x, wrapper):
# return x.opclass
# elif isinstance(x, str) or (hasattr(x, '__bases__') and issubclass(x, gof.op.Op)):
# return x
# else:
# raise TypeError("Bad input type for pattern_opt.")
# return gof.opt.PatternOptimizer(parse(in_pattern), parse(out_pattern))
# def op_sub(op1, op2):
# if isinstance(op1, wrapper):
# op1 = op1.opclass
# if isinstance(op2, wrapper):
# op2 = op2.opclass
# return gof.opt.OpSubOptimizer(op1, op2)
pattern_opt
=
gof
.
opt
.
PatternOptimizer
op_sub
=
gof
.
opt
.
OpSubOptimizer
#def make_patterns(patterns):
...
...
@@ -67,4 +71,15 @@ opts = [
export_opts
(
opts
)
# publish the optimizations performed under individual names
optimizer
=
gof
.
opt
.
MergeOptMerge
(
gof
.
opt
.
SeqOptimizer
([
opt
for
name
,
opt
in
opts
]))
# class AAA(gof.opt.Optimizer):
# def __init__(self, opt):
# self.opt = opt
# def optimize(self, env):
# build_mode()
# self.opt.optimize(env)
# pop_mode()
optimizer
=
gof
.
lib
.
PythonOpt
(
gof
.
opt
.
MergeOptMerge
(
gof
.
opt
.
SeqOptimizer
([
opt
for
name
,
opt
in
opts
])))
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论