Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
823cffaa
提交
823cffaa
authored
11月 19, 2010
作者:
gdesjardins
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Re: ticket #573
Implemented unittests which test that the contract for In is respected: we test that aliasing the input is impossible with borrow=False.
上级
260f7392
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
50 行增加
和
3 行删除
+50
-3
io.py
theano/compile/io.py
+27
-1
pfunc.py
theano/compile/pfunc.py
+3
-2
test_function_module.py
theano/compile/tests/test_function_module.py
+20
-0
没有找到文件。
theano/compile/io.py
浏览文件 @
823cffaa
...
...
@@ -4,6 +4,13 @@ __docformat__ = 'restructuredtext en'
from
theano
import
gof
from
sharedvalue
import
SharedVariable
import
logging
_logger
=
logging
.
getLogger
(
"theano.compile.io"
)
_logger
.
setLevel
(
logging
.
WARNING
)
def
warning
(
*
args
):
_logger
.
warning
(
"WARNING: "
+
' '
.
join
(
str
(
a
)
for
a
in
args
))
class
SymbolicInput
(
object
):
"""
Represents a symbolic input for use with function or FunctionMaker.
...
...
@@ -184,7 +191,26 @@ class In(SymbolicInput):
# try to keep it synchronized.
def
__init__
(
self
,
variable
,
name
=
None
,
value
=
None
,
update
=
None
,
mutable
=
None
,
strict
=
False
,
allow_downcast
=
False
,
autoname
=
True
,
implicit
=
None
,
borrow
=
False
):
implicit
=
None
,
borrow
=
None
):
# mutable implies the output can be both aliased to the input and that the input can be
# destroyed. borrow simply implies the output can be aliased to the input. Thus
# mutable=True should require borrow=True. Raise warning when borrow is explicitely set
# to False with mutable=True.
if
mutable
:
if
borrow
==
False
:
warning
(
"Symbolic input for variable
%
s (name=
%
s) has flags "
\
"mutable=True, borrow=False. This combination is "
\
"incompatible since mutable=True implies that the input "
\
"variable may be both aliased (borrow=True) and over-"
\
"written. We set borrow=True and continue."
%
(
variable
,
name
))
borrow
=
True
# borrow=None basically means False. We can't set default value to False because of the
# above business with mutable.
if
borrow
is
None
:
borrow
=
False
if
implicit
is
None
:
implicit
=
(
isinstance
(
value
,
gof
.
Container
)
or
isinstance
(
value
,
SharedVariable
))
...
...
theano/compile/pfunc.py
浏览文件 @
823cffaa
...
...
@@ -257,9 +257,10 @@ def pfunc(params, outputs=None, mode=None, updates=[], givens=[],
for
sv
in
shared_inputs
:
if
sv
in
update_d
:
si
=
In
(
variable
=
sv
,
value
=
sv
.
container
,
mutable
=
True
,
update
=
update_d
[
sv
])
borrow
=
True
,
update
=
update_d
[
sv
])
else
:
si
=
In
(
variable
=
sv
,
value
=
sv
.
container
,
mutable
=
False
)
si
=
In
(
variable
=
sv
,
value
=
sv
.
container
,
mutable
=
False
,
borrow
=
True
)
inputs
.
append
(
si
)
return
orig_function
(
inputs
,
cloned_outputs
,
mode
,
...
...
theano/compile/tests/test_function_module.py
浏览文件 @
823cffaa
...
...
@@ -281,6 +281,26 @@ class T_function(unittest.TestCase):
self
.
failUnless
(
dec
[
s
]
==
-
1
)
def
test_borrow_input
(
self
):
"""
Tests that the contract for io.In is respected. When borrow=False, it should be
impossible for outputs to be aliased to the input variables provided by the user,
either through a view-map or a destroy map. New tests should be added in the future
when borrow=True is implemented.
"""
a
=
T
.
dmatrix
()
aval
=
numpy
.
random
.
rand
(
3
,
3
)
# when borrow=False, test that a destroy map cannot alias output to input
f
=
theano
.
function
([
In
(
a
,
borrow
=
False
)],
Out
(
a
+
1
,
borrow
=
True
))
assert
numpy
.
all
(
f
(
aval
)
==
aval
+
1
)
assert
not
numpy
.
may_share_memory
(
aval
,
f
(
aval
))
# when borrow=False, test that a viewmap cannot alias output to input
f
=
theano
.
function
([
In
(
a
,
borrow
=
False
)],
Out
(
a
[
0
,:],
borrow
=
True
))
assert
numpy
.
all
(
f
(
aval
)
==
aval
[
0
,:])
assert
not
numpy
.
may_share_memory
(
aval
,
f
(
aval
))
def
test_borrow_output
(
self
):
a
=
T
.
dmatrix
()
f
=
function
([
a
],
Out
(
a
,
borrow
=
False
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论