Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ad628f1f
提交
ad628f1f
authored
9月 28, 2017
作者:
Pascal Lamblin
提交者:
GitHub
9月 28, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6452 from Faruk-Ahmed/ARange-gradient
ARange gradient (contd)
上级
deea1af5
a8e4f8dc
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
18 行增加
和
16 行删除
+18
-16
basic.py
theano/tensor/basic.py
+13
-12
test_basic.py
theano/tensor/tests/test_basic.py
+5
-4
没有找到文件。
theano/tensor/basic.py
浏览文件 @
ad628f1f
...
...
@@ -5530,22 +5530,23 @@ class ARange(Op):
def
L_op
(
self
,
inputs
,
outputs
,
grads
):
start
,
stop
,
step
=
inputs
gz
,
=
grads
#
start and step
affect the output values
#
`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
if
(
self
.
dtype
in
discrete_dtypes
)
and
(
step
>
0
):
return
[
start
.
zeros_like
(),
# no gradient through them.
# When they are not integers, the gradients are
# as expressed below.
# `stop` does not affect the output values,
# just the output shape, so it is disconnected.
if
self
.
dtype
in
discrete_dtypes
:
return
[
start
.
zeros_like
(
dtype
=
config
.
floatX
),
DisconnectedType
()(),
step
.
zeros_like
()]
step
.
zeros_like
(
dtype
=
config
.
floatX
)]
else
:
num_steps_taken
=
outputs
[
0
]
.
shape
[
0
]
# (stop-start)/step
return
[
gz
.
sum
(
dtype
=
config
.
floatX
),
num_steps_taken
=
outputs
[
0
]
.
shape
[
0
]
return
[
gz
.
sum
(),
DisconnectedType
()(),
(
gz
*
arange
(
num_steps_taken
,
dtype
=
self
.
dtype
))
.
sum
(
dtype
=
config
.
floatX
)]
(
gz
*
arange
(
num_steps_taken
,
dtype
=
self
.
dtype
))
.
sum
()]
def
R_op
(
self
,
inputs
,
eval_points
):
return
[
None
]
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
ad628f1f
...
...
@@ -5917,12 +5917,13 @@ class TestARange(unittest.TestCase):
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
# Due to the random projection, we should not use the exact
# point that
sha
ge the shape of the output.
# point that
chan
ge the shape of the output.
for
start
,
stop
,
step
in
[(
0
,
4.9
,
1
),
(
5.1
,
0
,
-
0.5
),
(
1
,
5.1
,
0.5
)]:
utt
.
verify_grad
(
f
,
[
np
.
float32
(
start
),
np
.
float32
(
stop
),
np
.
float32
(
step
)],
utt
.
verify_grad
(
f
,
[
np
.
asarray
(
start
)
.
astype
(
config
.
floatX
),
np
.
asarray
(
stop
)
.
astype
(
config
.
floatX
),
np
.
asarray
(
step
)
.
astype
(
config
.
floatX
)],
rng
=
rng
)
def
test_integers
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论