Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
896fdba3
提交
896fdba3
authored
9月 05, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
connection pattern and grad method for several ops
上级
f90b7022
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
82 行增加
和
12 行删除
+82
-12
basic.py
theano/tensor/basic.py
+82
-12
没有找到文件。
theano/tensor/basic.py
浏览文件 @
896fdba3
...
...
@@ -3980,6 +3980,15 @@ class Subtensor(Op):
return
([
IncSubtensor
(
self
.
idx_list
)(
zeros_like
(
x
),
gz
,
*
rest
)]
+
[
DisconnectedType
()()]
*
len
(
rest
))
def
connection_pattern
(
self
,
node
):
rval
=
[
[
True
]
]
for
ipt
in
node
.
inputs
[
1
:]:
rval
.
append
([
False
])
return
rval
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
self
.
idx_list
==
other
.
idx_list
...
...
@@ -4636,7 +4645,7 @@ class IncSubtensor(Op):
rval
=
[
[
True
]
]
for
ipt
in
node
.
inputs
[
1
:]:
for
ipt
in
node
.
inputs
[
2
:]:
rval
.
append
([
False
])
return
rval
...
...
@@ -4654,7 +4663,7 @@ class IncSubtensor(Op):
gx
=
g_output
gy
=
Subtensor
(
idx_list
=
self
.
idx_list
)(
g_output
,
*
idx_list
)
return
[
gx
,
gy
]
+
[
None
]
*
len
(
idx_list
)
return
[
gx
,
gy
]
+
[
DisconnectedType
()()
]
*
len
(
idx_list
)
def
split
(
x
,
splits_size
,
n_splits
,
axis
=
0
):
...
...
@@ -4772,8 +4781,10 @@ class Split(Op):
def
grad
(
self
,
inputs
,
g_outputs
):
"""Join the gradients along the axis that was used to split x."""
_
,
axis
,
_
=
inputs
return
[
join
(
axis
,
*
g_outputs
),
None
,
None
]
_
,
axis
,
n
=
inputs
return
[
join
(
axis
,
*
g_outputs
),
grad_undefined
(
self
,
1
,
axis
),
grad_undefined
(
self
,
2
,
n
)]
def
R_op
(
self
,
inputs
,
eval_points
):
if
eval_points
[
0
]
is
None
:
...
...
@@ -5041,6 +5052,9 @@ class Join(Op):
"""
gz
,
=
grads
axis
,
tensors
=
axis_and_tensors
[
0
],
axis_and_tensors
[
1
:]
rval
=
[
grad_undefined
(
self
,
0
,
axis
)
]
if
'float'
in
tensors
[
0
]
.
dtype
or
'complex'
in
tensors
[
0
]
.
dtype
:
# assume that this is differentiable
split
=
Split
(
len
(
tensors
))
...
...
@@ -5049,10 +5063,14 @@ class Join(Op):
# If there is only one split, it might not be in a list.
if
not
isinstance
(
split_gz
,
list
):
split_gz
=
[
split_gz
]
return
[
None
]
+
split_gz
rval
=
rval
+
split_gz
else
:
# assume that this isn't differentiable
return
[
None
]
*
(
1
+
len
(
tensors
))
# the output has integer type, so the gradient through it
# is 0
rval
=
rval
+
[
tensor
.
zeros_like
()
for
tensor
in
tensors
]
return
rval
def
_native_grad
(
self
,
axis_and_tensors
,
grads
):
"""WRITEME"""
...
...
@@ -5781,9 +5799,21 @@ class ARange(Op):
step
=
step
.
item
()
out
[
0
]
=
numpy
.
arange
(
start
,
stop
,
step
,
dtype
=
self
.
dtype
)
def
connection_pattern
(
self
,
node
):
return
[
[
True
],
[
False
],
[
True
]
]
def
grad
(
self
,
inputs
,
grads
):
start
,
stop
,
step
=
inputs
gz
,
=
grads
return
[
None
]
*
len
(
inputs
)
# start and step affect the output values
# but the outputs are integers so there's
# no gradient through them
# stop does not affect the output values,
# just the output shape, so it is disconnected
return
[
start
.
zeros_like
(),
DisconnectedType
()(),
step
.
zeros_like
()
]
def
R_op
(
self
,
inputs
,
eval_points
):
return
[
None
]
...
...
@@ -6082,11 +6112,21 @@ class AdvancedSubtensor1(Op):
out
[
0
]
=
x
.
take
(
i
,
axis
=
0
,
out
=
o
)
def
connection_pattern
(
self
,
node
):
rval
=
[
[
True
]
]
for
ipt
in
node
.
inputs
[
1
:]:
rval
.
append
([
False
])
return
rval
def
grad
(
self
,
inputs
,
grads
):
gz
,
=
grads
assert
len
(
inputs
)
==
2
rval1
=
[
advanced_inc_subtensor1
(
zeros_like
(
inputs
[
0
]),
gz
,
inputs
[
1
])]
return
rval1
+
[
None
]
*
(
len
(
inputs
)
-
1
)
return
rval1
+
[
DisconnectedType
()()
]
*
(
len
(
inputs
)
-
1
)
def
R_op
(
self
,
inputs
,
eval_points
):
if
eval_points
[
0
]
is
None
:
...
...
@@ -6185,6 +6225,16 @@ class AdvancedIncSubtensor1(Op):
return
self
.
make_node
(
eval_points
[
0
],
eval_points
[
1
],
*
inputs
[
2
:])
.
outputs
def
connection_pattern
(
self
,
node
):
rval
=
[
[
True
]
]
for
ipt
in
node
.
inputs
[
2
:]:
rval
.
append
([
False
])
return
rval
def
grad
(
self
,
inputs
,
grads
):
g_output
,
=
grads
x
,
y
=
inputs
[:
2
]
...
...
@@ -6193,7 +6243,7 @@ class AdvancedIncSubtensor1(Op):
gx
=
g_output
gy
=
advanced_subtensor1
(
g_output
,
*
idx_list
)
return
[
gx
,
gy
]
+
[
None
]
*
len
(
idx_list
)
return
[
gx
,
gy
]
+
[
DisconnectedType
()()
]
*
len
(
idx_list
)
advanced_inc_subtensor1
=
AdvancedIncSubtensor1
()
...
...
@@ -6282,12 +6332,22 @@ class AdvancedSubtensor(Op):
# return
#raise NotImplementedError()
def
connection_pattern
(
self
,
node
):
rval
=
[
[
True
]
]
for
ipt
in
node
.
inputs
[
1
:]:
rval
.
append
([
False
])
return
rval
def
grad
(
self
,
inputs
,
grads
):
gz
,
=
grads
x
=
inputs
[
0
]
rest
=
inputs
[
1
:]
return
[
advanced_inc_subtensor
(
zeros_like
(
x
),
gz
,
*
rest
)]
+
[
None
]
*
len
(
rest
)
*
rest
)]
+
\
[
DisconnectedType
()()]
*
len
(
rest
)
class
AdvancedIncSubtensor
(
Op
):
...
...
@@ -6372,13 +6432,23 @@ class AdvancedIncSubtensor(Op):
def
infer_shape
(
self
,
node
,
ishapes
):
return
[
ishapes
[
0
]]
def
connection_pattern
(
self
,
node
):
rval
=
[
[
True
]
]
for
ipt
in
node
.
inputs
[
2
:]:
rval
.
append
([
False
])
return
rval
def
grad
(
self
,
inpt
,
output_gradients
):
x
,
y
=
inpt
[:
2
]
idxs
=
inpt
[
2
:]
outgrad
,
=
output_gradients
d_x_wrt_C
=
outgrad
d_y_wrt_C
=
AdvancedSubtensor
()(
outgrad
,
*
idxs
)
return
[
d_x_wrt_C
,
d_y_wrt_C
]
+
[
None
for
_
in
idxs
]
return
[
d_x_wrt_C
,
d_y_wrt_C
]
+
\
[
DisconnectedType
()()
for
_
in
idxs
]
def
R_op
(
self
,
inputs
,
eval_points
):
if
None
in
eval_points
[:
2
]:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论