Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bb09fd5c
提交
bb09fd5c
authored
1月 07, 2010
作者:
Pierre-Antoine Manzagol
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modified IncSubtensor so that it can now perform setting in addition
to incrementing.
上级
38d38f11
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
23 行增加
和
3 行删除
+23
-3
basic.py
theano/tensor/basic.py
+23
-3
没有找到文件。
theano/tensor/basic.py
浏览文件 @
bb09fd5c
...
@@ -2006,6 +2006,9 @@ class SubtensorPrinter:
...
@@ -2006,6 +2006,9 @@ class SubtensorPrinter:
pprint
.
assign
(
lambda
pstate
,
r
:
r
.
owner
and
isinstance
(
r
.
owner
.
op
,
Subtensor
),
SubtensorPrinter
())
pprint
.
assign
(
lambda
pstate
,
r
:
r
.
owner
and
isinstance
(
r
.
owner
.
op
,
Subtensor
),
SubtensorPrinter
())
def
incsubtensor
(
x
,
y
,
idx_list
,
inplace
=
False
,
set_instead_of_inc
=
False
):
the_op
=
IncSubtensor
(
idx_list
,
inplace
,
set_instead_of_inc
)
return
the_op
(
x
,
y
)
class
IncSubtensor
(
Op
):
class
IncSubtensor
(
Op
):
"""Increment a subtensor.
"""Increment a subtensor.
...
@@ -2015,18 +2018,23 @@ class IncSubtensor(Op):
...
@@ -2015,18 +2018,23 @@ class IncSubtensor(Op):
z[i,j,k] += <something>
z[i,j,k] += <something>
It is used internally to implement the gradient on SubTensor.
It is used internally to implement the gradient on SubTensor.
:param set_instead_of_inc: if True set the subtensor to the value instead
of incrementing it by that value.
"""
"""
def
__init__
(
self
,
idx_list
,
inplace
=
False
):
def
__init__
(
self
,
idx_list
,
inplace
=
False
,
set_instead_of_inc
=
False
):
self
.
idx_list
=
map
(
Subtensor
.
convert
,
idx_list
)
self
.
idx_list
=
map
(
Subtensor
.
convert
,
idx_list
)
self
.
inplace
=
inplace
self
.
inplace
=
inplace
if
inplace
:
if
inplace
:
self
.
destroy_map
=
{
0
:
[
0
]}
self
.
destroy_map
=
{
0
:
[
0
]}
self
.
set_instead_of_inc
=
set_instead_of_inc
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
\
return
type
(
self
)
==
type
(
other
)
\
and
self
.
idx_list
==
other
.
idx_list
\
and
self
.
idx_list
==
other
.
idx_list
\
and
self
.
inplace
==
other
.
inplace
and
self
.
inplace
==
other
.
inplace
\
and
self
.
set_instead_of_inc
==
other
.
set_instead_of_inc
def
__hash__
(
self
):
def
__hash__
(
self
):
msg
=
[]
msg
=
[]
...
@@ -2042,7 +2050,8 @@ class IncSubtensor(Op):
...
@@ -2042,7 +2050,8 @@ class IncSubtensor(Op):
# if isinstance(entry, slice)
# if isinstance(entry, slice)
# else entry
# else entry
# for entry in self.idx_list)
# for entry in self.idx_list)
return
hashtype
(
self
)
^
hash
(
idx_list
)
^
hash
(
self
.
inplace
)
return
hashtype
(
self
)
^
hash
(
idx_list
)
^
hash
(
self
.
inplace
)
\
^
hash
(
self
.
set_instead_of_inc
)
def
__str__
(
self
):
def
__str__
(
self
):
indices
=
[]
indices
=
[]
...
@@ -2055,6 +2064,10 @@ class IncSubtensor(Op):
...
@@ -2055,6 +2064,10 @@ class IncSubtensor(Op):
msg
=
'Inplace'
msg
=
'Inplace'
else
:
else
:
msg
=
''
msg
=
''
if
not
self
.
set_instead_of_inc
:
msg
+=
'Inc'
else
:
msg
+=
'Set'
return
"
%
s
%
s{
%
s}"
%
(
msg
,
return
"
%
s
%
s{
%
s}"
%
(
msg
,
self
.
__class__
.
__name__
,
", "
.
join
(
indices
))
self
.
__class__
.
__name__
,
", "
.
join
(
indices
))
...
@@ -2107,10 +2120,17 @@ class IncSubtensor(Op):
...
@@ -2107,10 +2120,17 @@ class IncSubtensor(Op):
sub_x
=
x
.
__getitem__
(
cdata
)
sub_x
=
x
.
__getitem__
(
cdata
)
if
sub_x
.
shape
:
if
sub_x
.
shape
:
# we've sliced out an N-D tensor with N > 0
# we've sliced out an N-D tensor with N > 0
if
not
self
.
set_instead_of_inc
:
sub_x
+=
y
sub_x
+=
y
else
:
#sub_x += -sub_x + y
x
.
__setitem__
(
cdata
,
y
)
else
:
else
:
# scalar case
# scalar case
if
not
self
.
set_instead_of_inc
:
x
.
__setitem__
(
cdata
,
sub_x
+
y
)
x
.
__setitem__
(
cdata
,
sub_x
+
y
)
else
:
x
.
__setitem__
(
cdata
,
y
)
out
[
0
]
=
x
out
[
0
]
=
x
def
split
(
x
,
splits_size
,
n_splits
,
axis
=
0
):
def
split
(
x
,
splits_size
,
n_splits
,
axis
=
0
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论