Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2c813862
提交
2c813862
authored
5月 17, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modified compile to use the new linker interface
上级
61d10d72
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
25 行增加
和
22 行删除
+25
-22
compile.py
compile.py
+25
-22
没有找到文件。
compile.py
浏览文件 @
2c813862
...
@@ -3,17 +3,18 @@
...
@@ -3,17 +3,18 @@
import
numpy
import
numpy
import
gof
import
gof
import
sys
import
sys
from
copy
import
copy
#TODO: put together some default optimizations (TRAC #67)
#TODO: put together some default optimizations (TRAC #67)
def
exec_py_opt
(
inputs
,
outputs
,
features
=
[]):
def
exec_py_opt
(
inputs
,
outputs
,
features
=
[]):
"""Return an optimized graph running purely python implementations"""
"""Return an optimized graph running purely python implementations"""
return
Function
(
intputs
,
outputs
,
features
,
exec_py_opt
.
optimizer
,
gof
.
link
.
PerformLinker
,
False
)
return
Function
(
intputs
,
outputs
,
features
,
exec_py_opt
.
optimizer
,
gof
.
link
.
PerformLinker
()
,
False
)
exec_py_opt
.
optimizer
=
None
exec_py_opt
.
optimizer
=
None
def
exec_opt
(
inputs
,
outputs
,
features
=
[]):
def
exec_opt
(
inputs
,
outputs
,
features
=
[]):
"""Return a fast implementation"""
"""Return a fast implementation"""
return
Function
(
intputs
,
outputs
,
features
,
exec_opt
.
optimizer
,
gof
.
link
.
PerformLinker
,
False
)
return
Function
(
intputs
,
outputs
,
features
,
exec_opt
.
optimizer
,
gof
.
link
.
PerformLinker
()
,
False
)
exec_opt
.
optimizer
=
None
exec_opt
.
optimizer
=
None
class
_DefaultOptimizer
(
object
):
class
_DefaultOptimizer
(
object
):
...
@@ -28,18 +29,20 @@ def _mark_indestructible(results):
...
@@ -28,18 +29,20 @@ def _mark_indestructible(results):
for
r
in
results
:
for
r
in
results
:
r
.
tag
.
indestructible
=
True
r
.
tag
.
indestructible
=
True
def
linker_cls_python_and_c
(
env
,
**
kwargs
):
# def linker_cls_python_and_c(env, **kwargs):
"""Use this as the linker_cls argument to Function.__init__ to compare
# """Use this as the linker_cls argument to Function.__init__ to compare
python and C implementations"""
# python and C implementations"""
def
checker
(
x
,
y
):
x
,
y
=
x
[
0
],
y
[
0
]
def
check_equal
(
x
,
y
):
if
isinstance
(
x
,
numpy
.
ndarray
)
or
isinstance
(
y
,
numpy
.
ndarray
):
x
,
y
=
x
[
0
],
y
[
0
]
if
x
.
dtype
!=
y
.
dtype
or
x
.
shape
!=
y
.
shape
or
numpy
.
any
(
abs
(
x
-
y
)
>
1e-10
):
if
isinstance
(
x
,
numpy
.
ndarray
)
or
isinstance
(
y
,
numpy
.
ndarray
):
raise
Exception
(
"Output mismatch."
,
{
'performlinker'
:
x
,
'clinker'
:
y
})
if
x
.
dtype
!=
y
.
dtype
or
x
.
shape
!=
y
.
shape
or
numpy
.
any
(
abs
(
x
-
y
)
>
1e-10
):
else
:
raise
Exception
(
"Output mismatch."
,
{
'performlinker'
:
x
,
'clinker'
:
y
})
if
x
!=
y
:
else
:
if
x
!=
y
:
raise
Exception
(
"Output mismatch."
,
{
'performlinker'
:
x
,
'clinker'
:
y
})
raise
Exception
(
"Output mismatch."
,
{
'performlinker'
:
x
,
'clinker'
:
y
})
return
gof
.
DualLinker
(
env
,
checker
,
**
kwargs
)
# return gof.DualLinker(checker, **kwargs).accept(env)
def
infer_reuse_pattern
(
env
,
outputs_to_disown
):
def
infer_reuse_pattern
(
env
,
outputs_to_disown
):
...
@@ -86,10 +89,10 @@ def std_opt(env):
...
@@ -86,10 +89,10 @@ def std_opt(env):
predefined_linkers
=
{
predefined_linkers
=
{
'py'
:
gof
.
link
.
PerformLinker
,
'py'
:
gof
.
PerformLinker
()
,
'c'
:
gof
.
cc
.
CLinker
,
'c'
:
gof
.
CLinker
()
,
'c|py'
:
gof
.
cc
.
OpWiseCLinker
,
'c|py'
:
gof
.
OpWiseCLinker
()
,
'c&py'
:
linker_cls_python_and_c
'c&py'
:
gof
.
DualLinker
(
checker
=
check_equal
)
}
}
class
FunctionFactory
:
class
FunctionFactory
:
...
@@ -105,14 +108,14 @@ class FunctionFactory:
...
@@ -105,14 +108,14 @@ class FunctionFactory:
optimizer
(
env
)
optimizer
(
env
)
env
.
validate
()
env
.
validate
()
self
.
env
=
env
self
.
env
=
env
linker
=
predefined_linkers
.
get
(
linker
,
linker
)
linker
=
copy
(
predefined_linkers
.
get
(
linker
,
linker
)
)
if
not
callable
(
linker
):
if
not
hasattr
(
linker
,
'accept'
):
raise
ValueError
(
"'linker' parameter of FunctionFactory should be a
callable that takes an env as argument
"
\
raise
ValueError
(
"'linker' parameter of FunctionFactory should be a
Linker with an accept method
"
\
"or one of ['py', 'c', 'c|py', 'c&py']"
)
"or one of ['py', 'c', 'c|py', 'c&py']"
)
if
borrow_outputs
:
if
borrow_outputs
:
self
.
linker
=
linker
(
env
)
self
.
linker
=
linker
.
accept
(
env
)
else
:
else
:
self
.
linker
=
linker
(
env
,
no_recycling
=
infer_reuse_pattern
(
env
,
env
.
outputs
))
self
.
linker
=
linker
.
accept
(
env
,
no_recycling
=
infer_reuse_pattern
(
env
,
env
.
outputs
))
def
create
(
self
,
profiler
=
None
,
unpack_single
=
True
,
strict
=
'if_destroyed'
):
def
create
(
self
,
profiler
=
None
,
unpack_single
=
True
,
strict
=
'if_destroyed'
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论