Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b079a36c
提交
b079a36c
authored
12月 16, 2020
作者:
Michael Osthege
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move the base Linker class
上级
9f7cf7d0
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
89 行增加
和
84 行删除
+89
-84
link.py
theano/gof/link.py
+1
-84
basic.py
theano/link/basic.py
+88
-0
没有找到文件。
theano/gof/link.py
浏览文件 @
b079a36c
...
@@ -10,6 +10,7 @@ import numpy as np
...
@@ -10,6 +10,7 @@ import numpy as np
import
theano
import
theano
from
theano.gof
import
graph
,
utils
from
theano.gof
import
graph
,
utils
from
theano.gof.type
import
Type
from
theano.gof.type
import
Type
from
theano.link.basic
import
Linker
from
.utils
import
undef
from
.utils
import
undef
...
@@ -341,90 +342,6 @@ def raise_with_op(fgraph, node, thunk=None, exc_info=None, storage_map=None):
...
@@ -341,90 +342,6 @@ def raise_with_op(fgraph, node, thunk=None, exc_info=None, storage_map=None):
raise
exc_value
.
with_traceback
(
exc_trace
)
raise
exc_value
.
with_traceback
(
exc_trace
)
class
Linker
:
"""
WRITEME
"""
def
clone
(
self
,
allow_gc
=
undef
):
new
=
copy
(
self
)
if
allow_gc
is
not
undef
:
new
.
allow_gc
=
allow_gc
return
new
def
make_thunk
(
self
):
"""
This function must return a triplet (function, input_variables,
output_variables) where function is a thunk that operates on the
returned variables. If inplace is True, the input_variables and
output_variables lists will be the same as the inputs and outputs
of the graph provided to the L{Linker}. Else, independent
variables will be returned.
Examples
--------
x, y = Variable(Double), Variable(Double)
e = x + y
fgraph = FunctionGraph([x, y], [e])
fn, (new_x, new_y), (new_e, ) = MyLinker(fgraph).make_thunk(inplace)
new_x.data = 1.0
new_y.data = 2.0
fn()
print new_e.data # 3.0
print e.data # 3.0 iff inplace == True (else unknown)
"""
raise
utils
.
MethodNotDefined
(
"make_thunk"
,
type
(
self
),
self
.
__class__
.
__name__
)
# DELETEME #
def
make_function
(
self
,
unpack_single
=
True
,
**
kwargs
):
"""
Returns a function that takes values corresponding to the inputs of the
fgraph used by this L{Linker} and returns values corresponding the the
outputs of that fgraph. If inplace is True, the calculations will
operate in the same storage the fgraph uses, else independent storage
will be allocated for the function.
Examples
--------
e = x + y
fgraph = FunctionGraph([x, y], [e])
fn = MyLinker(fgraph).make_function(inplace)
print fn(1.0, 2.0) # 3.0
print e.data # 3.0 iff inplace == True (else unknown)
If unpack_single is True (default) and that the function has only one
output, then that output will be returned. Else, a list or tuple of
length 1 will be returned.
"""
thunk
,
inputs
,
outputs
=
self
.
make_thunk
(
**
kwargs
)
def
execute
(
*
args
):
def
e_arity
(
takes
,
got
):
return
f
"Function call takes exactly {takes} {['argument', 'arguments'][takes > 1]} ({got} given)"
if
len
(
args
)
!=
len
(
inputs
):
raise
TypeError
(
e_arity
(
len
(
inputs
),
len
(
args
)))
for
arg
,
variable
in
zip
(
args
,
inputs
):
variable
.
data
=
arg
thunk
()
if
unpack_single
:
return
utils
.
to_return_values
([
variable
.
data
for
variable
in
outputs
])
else
:
return
[
variable
.
data
for
variable
in
outputs
]
execute
.
thunk
=
thunk
execute
.
inputs
=
inputs
execute
.
outputs
=
outputs
return
execute
def
schedule
(
self
,
fgraph
):
return
fgraph
.
toposort
()
# TODO: Move this class to the compile module, where it is used (and for which it exists).
# TODO: Move this class to the compile module, where it is used (and for which it exists).
class
Container
:
class
Container
:
"""
"""
...
...
theano/link/basic.py
0 → 100644
浏览文件 @
b079a36c
from
copy
import
copy
from
theano.gof
import
utils
from
theano.gof.utils
import
undef
class
Linker
:
"""
WRITEME
"""
def
clone
(
self
,
allow_gc
=
undef
):
new
=
copy
(
self
)
if
allow_gc
is
not
undef
:
new
.
allow_gc
=
allow_gc
return
new
def
make_thunk
(
self
):
"""
This function must return a triplet (function, input_variables,
output_variables) where function is a thunk that operates on the
returned variables. If inplace is True, the input_variables and
output_variables lists will be the same as the inputs and outputs
of the graph provided to the L{Linker}. Else, independent
variables will be returned.
Examples
--------
x, y = Variable(Double), Variable(Double)
e = x + y
fgraph = FunctionGraph([x, y], [e])
fn, (new_x, new_y), (new_e, ) = MyLinker(fgraph).make_thunk(inplace)
new_x.data = 1.0
new_y.data = 2.0
fn()
print new_e.data # 3.0
print e.data # 3.0 iff inplace == True (else unknown)
"""
raise
utils
.
MethodNotDefined
(
"make_thunk"
,
type
(
self
),
self
.
__class__
.
__name__
)
# DELETEME #
def
make_function
(
self
,
unpack_single
=
True
,
**
kwargs
):
"""
Returns a function that takes values corresponding to the inputs of the
fgraph used by this L{Linker} and returns values corresponding the the
outputs of that fgraph. If inplace is True, the calculations will
operate in the same storage the fgraph uses, else independent storage
will be allocated for the function.
Examples
--------
e = x + y
fgraph = FunctionGraph([x, y], [e])
fn = MyLinker(fgraph).make_function(inplace)
print fn(1.0, 2.0) # 3.0
print e.data # 3.0 iff inplace == True (else unknown)
If unpack_single is True (default) and that the function has only one
output, then that output will be returned. Else, a list or tuple of
length 1 will be returned.
"""
thunk
,
inputs
,
outputs
=
self
.
make_thunk
(
**
kwargs
)
def
execute
(
*
args
):
def
e_arity
(
takes
,
got
):
return
f
"Function call takes exactly {takes} {['argument', 'arguments'][takes > 1]} ({got} given)"
if
len
(
args
)
!=
len
(
inputs
):
raise
TypeError
(
e_arity
(
len
(
inputs
),
len
(
args
)))
for
arg
,
variable
in
zip
(
args
,
inputs
):
variable
.
data
=
arg
thunk
()
if
unpack_single
:
return
utils
.
to_return_values
([
variable
.
data
for
variable
in
outputs
])
else
:
return
[
variable
.
data
for
variable
in
outputs
]
execute
.
thunk
=
thunk
execute
.
inputs
=
inputs
execute
.
outputs
=
outputs
return
execute
def
schedule
(
self
,
fgraph
):
return
fgraph
.
toposort
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论