Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
da45efb4
提交
da45efb4
authored
10月 12, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added config variable shared.value_borrows to control the copying behaviour of…
added config variable shared.value_borrows to control the copying behaviour of the shared.value property
上级
f9b46251
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
19 行增加
和
8 行删除
+19
-8
sharedvalue.py
theano/compile/sharedvalue.py
+18
-7
test_pfunc.py
theano/compile/tests/test_pfunc.py
+1
-1
没有找到文件。
theano/compile/sharedvalue.py
浏览文件 @
da45efb4
"""Provide a simple user friendly API """
"""Provide a simple user friendly API
to Theano-managed memory
"""
__docformat__
=
'restructuredtext en'
__docformat__
=
'restructuredtext en'
import
traceback
import
traceback
...
@@ -14,6 +14,15 @@ def warn(*msg): _logger.warn(' '.join(str(m) for m in msg))
...
@@ -14,6 +14,15 @@ def warn(*msg): _logger.warn(' '.join(str(m) for m in msg))
def
warning
(
*
msg
):
_logger
.
warning
(
' '
.
join
(
str
(
m
)
for
m
in
msg
))
def
warning
(
*
msg
):
_logger
.
warning
(
' '
.
join
(
str
(
m
)
for
m
in
msg
))
def
error
(
*
msg
):
_logger
.
error
(
' '
.
join
(
str
(
m
)
for
m
in
msg
))
def
error
(
*
msg
):
_logger
.
error
(
' '
.
join
(
str
(
m
)
for
m
in
msg
))
from
theano.configparser
import
TheanoConfigParser
,
AddConfigVar
,
EnumStr
,
StrParam
,
IntParam
,
FloatParam
,
BoolParam
from
theano
import
config
AddConfigVar
(
'shared.value_borrows'
,
(
"False: shared variables 'value' property is guaranteed to not"
" alias theano-managed memory. True: no guarantee, but faster."
" For more control consider using shared.get_value() instead."
),
BoolParam
(
True
))
class
SharedVariable
(
Variable
):
class
SharedVariable
(
Variable
):
"""
"""
Variable that is (defaults to being) shared between functions that it appears in.
Variable that is (defaults to being) shared between functions that it appears in.
...
@@ -106,17 +115,19 @@ class SharedVariable(Variable):
...
@@ -106,17 +115,19 @@ class SharedVariable(Variable):
cp
.
tag
=
copy
.
copy
(
self
.
tag
)
cp
.
tag
=
copy
.
copy
(
self
.
tag
)
return
cp
return
cp
def
get_borrowed_value
(
self
):
def
_value_get
(
self
):
return
self
.
get_value
(
borrow
=
True
)
return
self
.
get_value
(
borrow
=
config
.
shared
.
value_borrows
)
def
set_borrowed_value
(
self
,
new_value
):
def
_value_set
(
self
,
new_value
):
return
self
.
set_value
(
new_value
,
borrow
=
True
)
return
self
.
set_value
(
new_value
,
borrow
=
config
.
shared
.
value_borrows
)
#TODO: USE A CONFIG VARIABLE TO set these get/set methods to the non-borrowing versions
#TODO: USE A CONFIG VARIABLE TO set these get/set methods to the non-borrowing versions
# Semantically things are clearer when using non-borrow versions. That should be the
# Semantically things are clearer when using non-borrow versions. That should be the
# default. The default support transparently (if slowly) when the 'raw' value is in a
# default. The default support transparently (if slowly) when the 'raw' value is in a
# different memory space (e.g. GPU or other machine).
# different memory space (e.g. GPU or other machine).
value
=
property
(
get_borrowed_value
,
set_borrowed_value
,
value
=
property
(
_value_get
,
_value_set
,
doc
=
"shortcut for self.get_borrowed_value() and self.set_borrowed_value() which COPIES data"
)
doc
=
(
"shortcut for self.get_value() and self.set_value()."
"The `borrow` argument to these methods is read from "
"`theano.config.shared.value_borrows`"
))
def
filter_update
(
self
,
update
):
def
filter_update
(
self
,
update
):
...
...
theano/compile/tests/test_pfunc.py
浏览文件 @
da45efb4
...
@@ -511,7 +511,7 @@ class Test_aliasing_rules(unittest.TestCase):
...
@@ -511,7 +511,7 @@ class Test_aliasing_rules(unittest.TestCase):
assert
not
numpy
.
may_share_memory
(
orig_a
,
data_of
(
A
))
assert
not
numpy
.
may_share_memory
(
orig_a
,
data_of
(
A
))
# rule #2 reading back from theano-managed memory
# rule #2 reading back from theano-managed memory
assert
not
numpy
.
may_share_memory
(
A
.
value
,
data_of
(
A
))
assert
not
numpy
.
may_share_memory
(
A
.
get_value
(
borrow
=
False
)
,
data_of
(
A
))
def
test_potential_output_aliasing_induced_by_updates
(
self
):
def
test_potential_output_aliasing_induced_by_updates
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论