Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bed6f019
提交
bed6f019
authored
8月 14, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
numpydoc for theano/compile/sharedvalue.py
上级
33a899b2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
75 行增加
和
52 行删除
+75
-52
sharedvalue.py
theano/compile/sharedvalue.py
+75
-52
没有找到文件。
theano/compile/sharedvalue.py
浏览文件 @
bed6f019
"""Provide a simple user friendly API to Theano-managed memory"""
"""
Provide a simple user friendly API to Theano-managed memory.
"""
# Standard imports
# Standard imports
import
copy
import
copy
import
logging
import
logging
...
@@ -18,6 +21,32 @@ class SharedVariable(Variable):
...
@@ -18,6 +21,32 @@ class SharedVariable(Variable):
Variable that is (defaults to being) shared between functions that
Variable that is (defaults to being) shared between functions that
it appears in.
it appears in.
Parameters
----------
name : str
The name for this variable (see `Variable`).
type : str
The type for this variable (see `Variable`).
value
A value to associate with this variable (a new container will be
created).
strict
True : assignments to .value will not be cast or copied, so they must
have the correct type.
allow_downcast
Only applies if `strict` is False.
True : allow assigned value to lose precision when cast during
assignment.
False : never allow precision loss.
None : only allow downcasting of a Python float to a scalar floatX.
container
The container to use for this variable. Illegal to pass this as well as
a value.
Notes
-----
For more user-friendly constructor, see `shared`.
"""
"""
# Container object
# Container object
...
@@ -36,29 +65,6 @@ class SharedVariable(Variable):
...
@@ -36,29 +65,6 @@ class SharedVariable(Variable):
def
__init__
(
self
,
name
,
type
,
value
,
strict
,
def
__init__
(
self
,
name
,
type
,
value
,
strict
,
allow_downcast
=
None
,
container
=
None
):
allow_downcast
=
None
,
container
=
None
):
"""
:param name: The name for this variable (see `Variable`).
:param type: The type for this variable (see `Variable`).
:param value: A value to associate with this variable (a new
container will be created).
:param strict: True -> assignments to .value will not be cast
or copied, so they must have the correct type.
:param allow_downcast: Only applies if `strict` is False.
True -> allow assigned value to lose precision when cast
during assignment.
False -> never allow precision loss.
None -> only allow downcasting of a Python float to a scalar floatX.
:param container: The container to use for this
variable. Illegal to pass this as well as a value.
:note: For more user-friendly constructor, see `shared`
"""
super
(
SharedVariable
,
self
)
.
__init__
(
type
=
type
,
name
=
name
,
super
(
SharedVariable
,
self
)
.
__init__
(
type
=
type
,
name
=
name
,
owner
=
None
,
index
=
None
)
owner
=
None
,
index
=
None
)
...
@@ -79,18 +85,21 @@ class SharedVariable(Variable):
...
@@ -79,18 +85,21 @@ class SharedVariable(Variable):
allow_downcast
=
allow_downcast
)
allow_downcast
=
allow_downcast
)
def
get_value
(
self
,
borrow
=
False
,
return_internal_type
=
False
):
def
get_value
(
self
,
borrow
=
False
,
return_internal_type
=
False
):
"""Get the non-symbolic value associated with this SharedVariable.
"""
Get the non-symbolic value associated with this SharedVariable.
:param borrow: True to permit returning of an object aliased
Parameters
to internal memory.
----------
:param return_internal_type: True to permit the returning of
borrow : bool
an arbitrary type object used internally to store the
True to permit returning of an object aliased to internal memory.
shared variable.
return_internal_type : bool
True to permit the returning of an arbitrary type object used
internally to store the shared variable.
Only with borrow=False and return_internal_type=True does this
Only with borrow=False and return_internal_type=True does this
function
function
guarantee that you actually get the internal object.
guarantee that you actually get the internal object.
But in that case, you may get different return types when
But in that case, you may get different return types when
using
using
different compute devices.
different compute devices.
"""
"""
if
borrow
:
if
borrow
:
...
@@ -99,14 +108,18 @@ class SharedVariable(Variable):
...
@@ -99,14 +108,18 @@ class SharedVariable(Variable):
return
copy
.
deepcopy
(
self
.
container
.
value
)
return
copy
.
deepcopy
(
self
.
container
.
value
)
def
set_value
(
self
,
new_value
,
borrow
=
False
):
def
set_value
(
self
,
new_value
,
borrow
=
False
):
"""Set the non-symbolic value associated with this SharedVariable.
"""
Set the non-symbolic value associated with this SharedVariable.
:param borrow:
Parameters
----------
borrow : bool
True to use the new_value directly, potentially creating problems
True to use the new_value directly, potentially creating problems
related to aliased memory.
related to aliased memory.
Changes to this value will be visible to all functions using
Changes to this value will be visible to all functions using
this SharedVariable.
this SharedVariable.
"""
"""
if
borrow
:
if
borrow
:
self
.
container
.
value
=
new_value
self
.
container
.
value
=
new_value
...
@@ -114,15 +127,19 @@ class SharedVariable(Variable):
...
@@ -114,15 +127,19 @@ class SharedVariable(Variable):
self
.
container
.
value
=
copy
.
deepcopy
(
new_value
)
self
.
container
.
value
=
copy
.
deepcopy
(
new_value
)
def
zero
(
self
,
borrow
=
False
):
def
zero
(
self
,
borrow
=
False
):
"""Set the values of a shared variable to 0.
"""
Set the values of a shared variable to 0.
:param borrow:
Parameters
----------
borrow : bbol
True to modify the value of a shared variable directly by using
True to modify the value of a shared variable directly by using
its previous value. Potentially this can cause problems
its previous value. Potentially this can cause problems
regarding to the aliased memory.
regarding to the aliased memory.
Changes done with this function will be visible to all functions using
Changes done with this function will be visible to all functions using
this SharedVariable.
this SharedVariable.
"""
"""
if
borrow
:
if
borrow
:
self
.
container
.
value
[
...
]
=
0
self
.
container
.
value
[
...
]
=
0
...
@@ -183,7 +200,8 @@ def shared_constructor(ctor, remove=False):
...
@@ -183,7 +200,8 @@ def shared_constructor(ctor, remove=False):
def
shared
(
value
,
name
=
None
,
strict
=
False
,
allow_downcast
=
None
,
**
kwargs
):
def
shared
(
value
,
name
=
None
,
strict
=
False
,
allow_downcast
=
None
,
**
kwargs
):
"""Return a SharedVariable Variable, initialized with a copy or
"""
Return a SharedVariable Variable, initialized with a copy or
reference of `value`.
reference of `value`.
This function iterates over
This function iterates over
...
@@ -196,23 +214,25 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
...
@@ -196,23 +214,25 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
``theano.shared`` is a shortcut to this function.
``theano.shared`` is a shortcut to this function.
:note: By passing kwargs, you effectively limit the set of
Notes
potential constructors to those that can accept those kwargs.
-----
By passing kwargs, you effectively limit the set of potential constructors
to those that can accept those kwargs.
:note:
Some shared variable have ``borrow`` as extra kwargs.
Some shared variable have ``borrow`` as extra kwargs.
`See <http://deeplearning.net/software/theano/tutorial/aliasing.
\
`See <http://deeplearning.net/software/theano/tutorial/aliasing.
\
html#borrowing-when-creating-shared-variables>`_ for detail
.
html#borrowing-when-creating-shared-variables>`_ for details
.
:note: Some shared variable have ``broadcastable`` as extra kwargs.
Some shared variable have ``broadcastable`` as extra kwargs. As shared
As shared variable shapes can change, all dimensions default
variable shapes can change, all dimensions default to not being
to not being broadcastable, even if ``value`` has a shape of 1
broadcastable, even if ``value`` has a shape of 1 along some dimension.
along some dimension. This parameter allows you to create
This parameter allows you to create for example a `row` or `column` 2d
for example a `row` or `column` 2d
tensor.
tensor.
.. attribute:: constructors
.. attribute:: constructors
A list of shared variable constructors that will be tried in reverse
A list of shared variable constructors that will be tried in reverse
order.
order.
"""
"""
...
@@ -251,6 +271,9 @@ shared.constructors = []
...
@@ -251,6 +271,9 @@ shared.constructors = []
@shared_constructor
@shared_constructor
def
generic_constructor
(
value
,
name
=
None
,
strict
=
False
,
allow_downcast
=
None
):
def
generic_constructor
(
value
,
name
=
None
,
strict
=
False
,
allow_downcast
=
None
):
"""SharedVariable Constructor"""
"""
SharedVariable Constructor.
"""
return
SharedVariable
(
type
=
generic
,
value
=
value
,
name
=
name
,
strict
=
strict
,
return
SharedVariable
(
type
=
generic
,
value
=
value
,
name
=
name
,
strict
=
strict
,
allow_downcast
=
allow_downcast
)
allow_downcast
=
allow_downcast
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论