Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0a9707ea
提交
0a9707ea
authored
2月 16, 2012
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #447 from delallea/clearer_borrow
Simplified code for In.borrow and Param.borrow
上级
0a56bdff
e63f3e1b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
37 行增加
和
39 行删除
+37
-39
io.py
theano/compile/io.py
+16
-20
pfunc.py
theano/compile/pfunc.py
+21
-19
没有找到文件。
theano/compile/io.py
浏览文件 @
0a9707ea
...
@@ -161,11 +161,10 @@ class In(SymbolicInput):
...
@@ -161,11 +161,10 @@ class In(SymbolicInput):
True: permit the compiled function to modify the python object being passed as the input
True: permit the compiled function to modify the python object being passed as the input
False: do not permit the compiled function to modify the python object being passed as the input.
False: do not permit the compiled function to modify the python object being passed as the input.
borrow: Bool (default:
False if mutable evaluate to False, True otherwis
e)
borrow: Bool (default:
take the same value as mutabl
e)
True: permit the output of the compiled function to be aliased to the input
True: permit the output of the compiled function to be aliased to the input
False: do not permit any output to be aliased to the input
False: do not permit any output to be aliased to the input
strict: Bool (default: False)
strict: Bool (default: False)
True: means that the value you pass for this input must have exactly the right type
True: means that the value you pass for this input must have exactly the right type
False: the value you pass for this input may be cast automatically to the proper type
False: the value you pass for this input may be cast automatically to the proper type
...
@@ -201,24 +200,22 @@ class In(SymbolicInput):
...
@@ -201,24 +200,22 @@ class In(SymbolicInput):
#in the function or from the caller
#in the function or from the caller
self
.
shared
=
shared
self
.
shared
=
shared
# 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
:
_logger
.
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
:
if
borrow
is
None
:
borrow
=
False
self
.
borrow
=
mutable
else
:
self
.
borrow
=
borrow
# 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.
if
mutable
and
not
self
.
borrow
:
raise
AssertionError
(
"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 "
"overwritten."
,
variable
,
name
)
if
implicit
is
None
:
if
implicit
is
None
:
implicit
=
(
isinstance
(
value
,
gof
.
Container
)
or
implicit
=
(
isinstance
(
value
,
gof
.
Container
)
or
...
@@ -233,7 +230,6 @@ class In(SymbolicInput):
...
@@ -233,7 +230,6 @@ class In(SymbolicInput):
autoname
=
autoname
,
autoname
=
autoname
,
implicit
=
implicit
)
implicit
=
implicit
)
self
.
value
=
value
self
.
value
=
value
self
.
borrow
=
borrow
if
self
.
implicit
and
value
is
None
:
if
self
.
implicit
and
value
is
None
:
raise
TypeError
(
'An implicit input must be given a default value'
)
raise
TypeError
(
'An implicit input must be given a default value'
)
...
...
theano/compile/pfunc.py
浏览文件 @
0a9707ea
...
@@ -268,9 +268,9 @@ class Param(object):
...
@@ -268,9 +268,9 @@ class Param(object):
:param mutable: True -> function is allowed to modify this argument.
:param mutable: True -> function is allowed to modify this argument.
:param borrow:
True ->
function is allowed to alias some output to
:param borrow:
Whether the
function is allowed to alias some output to
this input
this input. Using None (default) means we re-use the same value as the
`mutable` flag.
False: do not permit any output to be aliased to the input
False: do not permit any output to be aliased to the input
:param strict: False -> function arguments may be copied or cast to match the
:param strict: False -> function arguments may be copied or cast to match the
...
@@ -289,25 +289,27 @@ class Param(object):
...
@@ -289,25 +289,27 @@ class Param(object):
self
.
default
=
default
self
.
default
=
default
self
.
name
=
name
self
.
name
=
name
self
.
mutable
=
mutable
self
.
mutable
=
mutable
# 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
if
borrow
is
None
:
# mutable=True should require borrow=True. Raise warning when borrow is explicitely set
self
.
borrow
=
self
.
mutable
# to False with mutable=True.
else
:
if
mutable
:
self
.
borrow
=
borrow
# Do not compare with "if not borrow", because borrow can be None,
# and "not None" would be True.
# mutable implies the output can be both aliased to the input and that
if
borrow
is
False
:
# the input can be destroyed. borrow simply implies the output can be
_logger
.
warning
(
"Symbolic input for variable
%
s (name=
%
s) has "
# aliased to the input. Thus mutable=True should require borrow=True.
"flags mutable=True, borrow=False. This combination is "
if
self
.
mutable
and
not
self
.
borrow
:
"incompatible since mutable=True implies that the "
raise
AssertionError
(
"input variable may be both aliased (borrow=True) and "
"Symbolic input for variable
%
s (name=
%
s) has "
"over-written. We set borrow=True and continue."
,
"flags mutable=True, borrow=False. This combination is "
variable
,
name
)
"incompatible since mutable=True implies that the "
borrow
=
True
"input variable may be both aliased (borrow=True) and "
"overwritten."
,
variable
,
name
)
self
.
strict
=
strict
self
.
strict
=
strict
self
.
allow_downcast
=
allow_downcast
self
.
allow_downcast
=
allow_downcast
self
.
implicit
=
implicit
self
.
implicit
=
implicit
self
.
borrow
=
borrow
def
pfunc
(
params
,
outputs
=
None
,
mode
=
None
,
updates
=
[],
givens
=
[],
def
pfunc
(
params
,
outputs
=
None
,
mode
=
None
,
updates
=
[],
givens
=
[],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论